diff --git a/Jenkinsfile.public b/Jenkinsfile.public index a30d0bce4..4452811ab 100644 --- a/Jenkinsfile.public +++ b/Jenkinsfile.public @@ -46,6 +46,44 @@ pipeline { sh 'touch web/satellite/node_modules/go.mod web/storagenode/node_modules/go.mod web/multinode/node_modules/go.mod' } } + stage('Build Web') { + // The build code depends on the following assets being loaded. + parallel { + stage('web/satellite') { + steps { + dir('web/satellite') { + sh 'npm ci --prefer-offline --no-audit' + sh './scripts/build-wasm.sh' + sh 'npm run build' + } + } + } + stage('web/storagenode') { + steps { + dir('web/storagenode') { + sh 'npm ci --prefer-offline --no-audit' + sh 'npm run build' + } + } + } + stage('web/multinode') { + steps { + dir('web/multinode') { + sh 'npm ci --prefer-offline --no-audit' + sh 'npm run build' + } + } + } + stage('satellite/admin/ui') { + steps { + dir('satellite/admin/ui') { + sh 'npm ci --prefer-offline --no-audit' + sh 'npm run build' + } + } + } + } + } stage('Build') { parallel { stage('go') { @@ -89,41 +127,6 @@ pipeline { } } } - - stage('web/satellite') { - steps { - dir('web/satellite') { - sh 'npm ci --prefer-offline --no-audit' - sh './scripts/build-wasm.sh' - sh 'npm run build' - } - } - } - stage('web/storagenode') { - steps { - dir('web/storagenode') { - sh 'npm ci --prefer-offline --no-audit' - sh 'npm run build' - } - } - } - stage('web/multinode') { - steps { - dir('web/multinode') { - sh 'npm ci --prefer-offline --no-audit' - sh 'npm run build' - } - } - } - stage('satellite/admin/ui') { - steps { - dir('satellite/admin/ui') { - sh 'npm ci --prefer-offline --no-audit' - sh 'npm run build' - sh 'rm -rf build .svelte-kit' // Remove these directories for avoiding linting their files. - } - } - } } } diff --git a/Makefile b/Makefile index fe68900a1..9475aa0c3 100644 --- a/Makefile +++ b/Makefile @@ -179,7 +179,7 @@ satellite-admin-ui: -e HOME=/tmp \ -u $(shell id -u):$(shell id -g) \ node:${NODE_VERSION} \ - /bin/bash -c "npm ci && npm run build && cp -r build/* assets" + /bin/bash -c "npm ci && npm run build" .PHONY: satellite-wasm satellite-wasm: diff --git a/satellite/admin/server.go b/satellite/admin/server.go index 1750f1485..74c93d9a8 100644 --- a/satellite/admin/server.go +++ b/satellite/admin/server.go @@ -7,9 +7,7 @@ package admin import ( "context" "crypto/subtle" - "embed" "errors" - "io/fs" "net" "net/http" "time" @@ -20,6 +18,7 @@ import ( "storj.io/common/errs2" "storj.io/storj/satellite/accounting" + adminui "storj.io/storj/satellite/admin/ui" "storj.io/storj/satellite/buckets" "storj.io/storj/satellite/console" "storj.io/storj/satellite/oidc" @@ -27,9 +26,6 @@ import ( "storj.io/storj/satellite/payments/stripecoinpayments" ) -//go:embed ui/assets/* -var ui embed.FS - // Config defines configuration for debug server. type Config struct { Address string `help:"admin peer http listening address" releaseDefault:"" devDefault:""` @@ -115,12 +111,7 @@ func NewServer(log *zap.Logger, listener net.Listener, db DB, buckets *buckets.S // This handler must be the last one because it uses the root as prefix, // otherwise will try to serve all the handlers set after this one. if config.StaticDir == "" { - uiAssets, err := fs.Sub(ui, "ui/assets") - if err != nil { - log.Error("invalid embbeded static assets directory, the Admin UI is not enabled") - } else { - root.PathPrefix("/").Handler(http.FileServer(http.FS(uiAssets))).Methods("GET") - } + root.PathPrefix("/").Handler(http.FileServer(http.FS(adminui.Assets))).Methods("GET") } else { root.PathPrefix("/").Handler(http.FileServer(http.Dir(config.StaticDir))).Methods("GET") } diff --git a/satellite/admin/server_test.go b/satellite/admin/server_test.go index 518a933e9..9170e91a2 100644 --- a/satellite/admin/server_test.go +++ b/satellite/admin/server_test.go @@ -32,7 +32,7 @@ func TestBasic(t *testing.T) { baseURL := "http://" + address.String() t.Run("UI", func(t *testing.T) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"/.gitignore", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"/.keep", nil) require.NoError(t, err) response, err := http.DefaultClient.Do(req) @@ -42,7 +42,7 @@ func TestBasic(t *testing.T) { content, err := ioutil.ReadAll(response.Body) require.NoError(t, response.Body.Close()) - require.NotEmpty(t, content) + require.Empty(t, content) require.NoError(t, err) }) diff --git a/satellite/admin/ui/.gitignore b/satellite/admin/ui/.gitignore index 21cf94a8a..483f84307 100644 --- a/satellite/admin/ui/.gitignore +++ b/satellite/admin/ui/.gitignore @@ -1,8 +1,7 @@ .DS_Store node_modules -/build -/assets/* -!/assets/.keep +/build/* +!/build/.keep /.svelte-kit /package .env diff --git a/satellite/admin/ui/README.md b/satellite/admin/ui/README.md index a879aad0a..695af7495 100644 --- a/satellite/admin/ui/README.md +++ b/satellite/admin/ui/README.md @@ -39,9 +39,3 @@ To create an optimized version of the app: ```bash npm run build ``` - -And then, place the files of the build in the assets directory for allowing Go to embed them into the satellite binary. - -```bash -cp -r build/* assets/ -``` diff --git a/satellite/admin/ui/assets.go b/satellite/admin/ui/assets.go new file mode 100644 index 000000000..5e35f43b5 --- /dev/null +++ b/satellite/admin/ui/assets.go @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Storj Labs, Inc. +// See LICENSE for copying information. + +package adminui + +import ( + "embed" + "fmt" + "io/fs" +) + +//go:embed build/* +var assets embed.FS + +// Assets contains either the built admin/ui or it is empty. +var Assets = func() fs.FS { + build, err := fs.Sub(assets, "build") + if err != nil { + panic(fmt.Errorf("invalid embedding: %w", err)) + } + return build +}() diff --git a/satellite/admin/ui/assets/.gitignore b/satellite/admin/ui/assets/.gitignore deleted file mode 100644 index d6b7ef32c..000000000 --- a/satellite/admin/ui/assets/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/satellite/admin/ui/build/.keep b/satellite/admin/ui/build/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/satellite/admin/ui/static/.keep b/satellite/admin/ui/static/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/scripts/build-wasm.sh b/scripts/build-wasm.sh index a71b82274..c238c50e1 100755 --- a/scripts/build-wasm.sh +++ b/scripts/build-wasm.sh @@ -13,7 +13,7 @@ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" release/$TAG/wasm/ brotli -k release/$TAG/wasm/wasm_exec.js # Build wasm code -go build -o release/$TAG/wasm/access.wasm storj.io/storj/satellite/console/wasm +GOOS=js GOARCH=wasm go build -o release/$TAG/wasm/access.wasm storj.io/storj/satellite/console/wasm # Compress wasm code using brotli brotli -k release/$TAG/wasm/access.wasm