Skip to content

Commit 3f0c727

Browse files
authored
feat: static websites (#849)
Adds support for deploying and developing static sites with Nitric
1 parent 702978c commit 3f0c727

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2494
-79
lines changed

.github/workflows/dashboard-run-test.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
- uses: actions/setup-node@v4
2929
with:
30-
node-version: 21
30+
node-version: 22
3131

3232
- name: Setup Go
3333
uses: actions/setup-go@v3
@@ -44,8 +44,9 @@ jobs:
4444
run: |
4545
cd ${{ github.workspace }}/cli/pkg/dashboard/frontend/test-app
4646
yarn install
47+
yarn install:websites
4748
nitric run --ci &
48-
sleep 15
49+
sleep 25
4950
5051
- name: Run Tests
5152
uses: cypress-io/github-action@v5

.github/workflows/dashboard-start-test.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
- uses: actions/setup-node@v4
2929
with:
30-
node-version: 21
30+
node-version: 22
3131

3232
- name: Lint Dashboard
3333
working-directory: cli/pkg/dashboard/frontend
@@ -51,7 +51,9 @@ jobs:
5151
run: |
5252
cd ${{ github.workspace }}/cli/pkg/dashboard/frontend/test-app
5353
yarn install
54+
yarn install:websites
5455
nitric start --ci &
56+
sleep 10
5557
5658
- name: Run Tests
5759
uses: cypress-io/github-action@v5

cmd/debug.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ var specCmd = &cobra.Command{
100100
batchRequirements, err := proj.CollectBatchRequirements()
101101
tui.CheckErr(err)
102102

103+
websiteRequirements, err := proj.CollectWebsiteRequirements()
104+
tui.CheckErr(err)
105+
103106
additionalEnvFiles := []string{}
104107

105108
if debugEnvFile != "" {
@@ -115,7 +118,7 @@ var specCmd = &cobra.Command{
115118
envVariables = map[string]string{}
116119
}
117120

118-
spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements)
121+
spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements, websiteRequirements)
119122
tui.CheckErr(err)
120123

121124
migrationImageContexts, err := collector.GetMigrationImageBuildContexts(serviceRequirements, batchRequirements, fs)

cmd/run.go

+27-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ var runCmd = &cobra.Command{
106106
LogWriter: logWriter,
107107
LocalConfig: proj.LocalConfig,
108108
MigrationRunner: project.BuildAndRunMigrations,
109-
LocalCloudMode: cloud.LocalCloudModeRun,
109+
LocalCloudMode: cloud.RunMode,
110110
})
111111
tui.CheckErr(err)
112112
runView.Send(local.LocalCloudStartStatusMsg{Status: local.Done})
@@ -149,6 +149,23 @@ var runCmd = &cobra.Command{
149149
tui.CheckErr(err)
150150
}
151151

152+
websiteBuildUpdates, err := proj.BuildWebsites(loadEnv)
153+
tui.CheckErr(err)
154+
155+
if isNonInteractive() {
156+
fmt.Println("building project websites")
157+
for update := range websiteBuildUpdates {
158+
for _, line := range strings.Split(strings.TrimSuffix(update.Message, "\n"), "\n") {
159+
fmt.Printf("%s [%s]: %s\n", update.ServiceName, update.Status, line)
160+
}
161+
}
162+
} else {
163+
prog := teax.NewProgram(build.NewModel(websiteBuildUpdates, "Building Websites"))
164+
// blocks but quits once the above updates channel is closed by the build process
165+
_, err = prog.Run()
166+
tui.CheckErr(err)
167+
}
168+
152169
// Run the app code (project services)
153170
stopChan := make(chan bool)
154171
updatesChan := make(chan project.ServiceRunUpdate)
@@ -179,6 +196,15 @@ var runCmd = &cobra.Command{
179196
}
180197
}()
181198

199+
go func() {
200+
err := proj.RunWebsites(localCloud)
201+
if err != nil {
202+
localCloud.Stop()
203+
204+
tui.CheckErr(err)
205+
}
206+
}()
207+
182208
tui.CheckErr(err)
183209
// FIXME: This is a hack to get labelled logs into the TUI
184210
// We should refactor the system logs to be more generic

cmd/stack.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ var stackUpdateCmd = &cobra.Command{
220220
batchRequirements, err := proj.CollectBatchRequirements()
221221
tui.CheckErr(err)
222222

223+
websiteRequirements, err := proj.CollectWebsiteRequirements()
224+
tui.CheckErr(err)
225+
223226
additionalEnvFiles := []string{}
224227

225228
if envFile != "" {
@@ -240,13 +243,13 @@ var stackUpdateCmd = &cobra.Command{
240243
envVariables["NITRIC_BETA_PROVIDERS"] = "true"
241244
}
242245

243-
spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements)
246+
spec, err := collector.ServiceRequirementsToSpec(proj.Name, envVariables, serviceRequirements, batchRequirements, websiteRequirements)
244247
tui.CheckErr(err)
245248

246249
migrationImageContexts, err := collector.GetMigrationImageBuildContexts(serviceRequirements, batchRequirements, fs)
247250
tui.CheckErr(err)
248-
// Build images from contexts and provide updates on the builds
249251

252+
// Build images from contexts and provide updates on the builds
250253
if len(migrationImageContexts) > 0 {
251254
migrationBuildUpdates, err := project.BuildMigrationImages(fs, migrationImageContexts, !noBuilder)
252255
tui.CheckErr(err)
@@ -274,6 +277,23 @@ var stackUpdateCmd = &cobra.Command{
274277
}
275278
}
276279

280+
websiteBuildUpdates, err := proj.BuildWebsites(envVariables)
281+
tui.CheckErr(err)
282+
283+
if isNonInteractive() {
284+
fmt.Println("building project websites")
285+
for update := range websiteBuildUpdates {
286+
for _, line := range strings.Split(strings.TrimSuffix(update.Message, "\n"), "\n") {
287+
fmt.Printf("%s [%s]: %s\n", update.ServiceName, update.Status, line)
288+
}
289+
}
290+
} else {
291+
prog := teax.NewProgram(build.NewModel(websiteBuildUpdates, "Building Websites"))
292+
// blocks but quits once the above updates channel is closed by the build process
293+
_, err = prog.Run()
294+
tui.CheckErr(err)
295+
}
296+
277297
providerStdout := make(chan string)
278298

279299
// Step 4. Start the deployment provider server

cmd/start.go

+23-10
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ func createTlsCredentialsIfNotPresent(fs afero.Fs, projectDir string) {
122122
}
123123
}
124124

125+
func runInGoroutine(
126+
fn func(*cloud.LocalCloud, <-chan bool, chan<- project.ServiceRunUpdate, map[string]string) error,
127+
localCloud *cloud.LocalCloud,
128+
stopChan chan bool,
129+
updatesChan chan project.ServiceRunUpdate,
130+
localEnv map[string]string,
131+
) {
132+
go func() {
133+
if err := fn(localCloud, stopChan, updatesChan, localEnv); err != nil {
134+
localCloud.Stop()
135+
tui.CheckErr(err)
136+
}
137+
}()
138+
}
139+
125140
var startCmd = &cobra.Command{
126141
Use: "start",
127142
Short: "Run nitric services locally for development and testing",
@@ -186,7 +201,7 @@ var startCmd = &cobra.Command{
186201
LogWriter: logWriter,
187202
LocalConfig: proj.LocalConfig,
188203
MigrationRunner: project.BuildAndRunMigrations,
189-
LocalCloudMode: cloud.LocalCloudModeStart,
204+
LocalCloudMode: cloud.StartMode,
190205
})
191206
tui.CheckErr(err)
192207
runView.Send(local.LocalCloudStartStatusMsg{Status: local.Done})
@@ -221,16 +236,14 @@ var startCmd = &cobra.Command{
221236
}
222237
}()
223238

239+
runInGoroutine(proj.RunServicesWithCommand, localCloud, stopChan, updatesChan, localEnv)
240+
241+
runInGoroutine(proj.RunBatchesWithCommand, localCloud, stopChan, updatesChan, localEnv)
242+
243+
runInGoroutine(proj.RunWebsitesWithCommand, localCloud, stopChan, updatesChan, localEnv)
244+
224245
go func() {
225-
err := proj.RunServicesWithCommand(localCloud, stopChan, updatesChan, localEnv)
226-
if err != nil {
227-
localCloud.Stop()
228-
tui.CheckErr(err)
229-
}
230-
}()
231-
// FIXME: Duplicate code
232-
go func() {
233-
err := proj.RunBatchesWithCommand(localCloud, stopChan, updatesChan, localEnv)
246+
err := proj.RunWebsites(localCloud)
234247
if err != nil {
235248
localCloud.Stop()
236249

go.mod

+12-13
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ require (
2222
github.com/hashicorp/consul/sdk v0.13.0
2323
github.com/hashicorp/go-getter v1.6.2
2424
github.com/hashicorp/go-version v1.7.0
25-
github.com/nitrictech/nitric/core v0.0.0-20241003062412-76ea6275fb0b
25+
github.com/nitrictech/nitric/core v0.0.0-20250305021715-06f92b813ce3
2626
github.com/pkg/errors v0.9.1
2727
github.com/spf13/cobra v1.8.1
2828
github.com/valyala/fasthttp v1.55.0
2929
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
30-
golang.org/x/mod v0.21.0 // indirect
30+
golang.org/x/mod v0.22.0 // indirect
3131
golang.org/x/oauth2 v0.22.0 // indirect
3232
google.golang.org/grpc v1.66.0
3333
gopkg.in/yaml.v2 v2.4.0
3434
)
3535

3636
require (
37-
github.com/Masterminds/semver/v3 v3.3.0
37+
github.com/Masterminds/semver/v3 v3.3.1
3838
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
3939
github.com/charmbracelet/bubbles v0.16.1
4040
github.com/charmbracelet/bubbletea v0.24.2
@@ -53,7 +53,7 @@ require (
5353
github.com/samber/lo v1.38.1
5454
github.com/sirupsen/logrus v1.9.3
5555
github.com/spf13/afero v1.11.0
56-
github.com/stretchr/testify v1.9.0
56+
github.com/stretchr/testify v1.10.0
5757
github.com/wk8/go-ordered-map/v2 v2.1.8
5858
go.etcd.io/bbolt v1.3.6
5959
golang.org/x/sync v0.10.0
@@ -115,7 +115,7 @@ require (
115115
github.com/denis-tingaikin/go-header v0.5.0 // indirect
116116
github.com/distribution/reference v0.6.0 // indirect
117117
github.com/docker/go-units v0.5.0 // indirect
118-
github.com/fatih/color v1.17.0 // indirect
118+
github.com/fatih/color v1.18.0 // indirect
119119
github.com/fatih/structtag v1.2.0 // indirect
120120
github.com/felixge/httpsnoop v1.0.4 // indirect
121121
github.com/firefart/nonamedreturns v1.0.5 // indirect
@@ -275,18 +275,17 @@ require (
275275
go.opentelemetry.io/otel/metric v1.29.0 // indirect
276276
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
277277
go.opentelemetry.io/otel/trace v1.29.0 // indirect
278-
go.uber.org/atomic v1.10.0 // indirect
279278
go.uber.org/automaxprocs v1.5.3 // indirect
280-
go.uber.org/multierr v1.8.0 // indirect
281-
go.uber.org/zap v1.24.0 // indirect
282-
golang.org/x/crypto v0.31.0 // indirect
279+
go.uber.org/multierr v1.11.0 // indirect
280+
go.uber.org/zap v1.27.0 // indirect
281+
golang.org/x/crypto v0.32.0 // indirect
283282
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
284-
golang.org/x/net v0.28.0 // indirect
285-
golang.org/x/sys v0.28.0 // indirect
286-
golang.org/x/term v0.27.0 // indirect
283+
golang.org/x/net v0.34.0 // indirect
284+
golang.org/x/sys v0.29.0 // indirect
285+
golang.org/x/term v0.28.0 // indirect
287286
golang.org/x/text v0.21.0 // indirect
288287
golang.org/x/time v0.6.0 // indirect
289-
golang.org/x/tools v0.24.0 // indirect
288+
golang.org/x/tools v0.28.0 // indirect
290289
google.golang.org/api v0.196.0 // indirect
291290
google.golang.org/genproto v0.0.0-20240903143218-8af14fe29dc1 // indirect
292291
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect

0 commit comments

Comments
 (0)