satellite/admin/ui: avoid needing an additional copy
This also fixes the build order. Unfortunately we need to ensure that the web frontends are built before installing Go binaries. Fixes https://github.com/storj/storj/issues/4654 Change-Id: I5d1c83125fd3d1a454d3400b2cbdd44bd3f2250c
This commit is contained in:
parent
c641f4c9ac
commit
4a6c2e2a9c
@ -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'
|
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') {
|
stage('Build') {
|
||||||
parallel {
|
parallel {
|
||||||
stage('go') {
|
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.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
Makefile
2
Makefile
@ -179,7 +179,7 @@ satellite-admin-ui:
|
|||||||
-e HOME=/tmp \
|
-e HOME=/tmp \
|
||||||
-u $(shell id -u):$(shell id -g) \
|
-u $(shell id -u):$(shell id -g) \
|
||||||
node:${NODE_VERSION} \
|
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
|
.PHONY: satellite-wasm
|
||||||
satellite-wasm:
|
satellite-wasm:
|
||||||
|
@ -7,9 +7,7 @@ package admin
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"embed"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io/fs"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -20,6 +18,7 @@ import (
|
|||||||
|
|
||||||
"storj.io/common/errs2"
|
"storj.io/common/errs2"
|
||||||
"storj.io/storj/satellite/accounting"
|
"storj.io/storj/satellite/accounting"
|
||||||
|
adminui "storj.io/storj/satellite/admin/ui"
|
||||||
"storj.io/storj/satellite/buckets"
|
"storj.io/storj/satellite/buckets"
|
||||||
"storj.io/storj/satellite/console"
|
"storj.io/storj/satellite/console"
|
||||||
"storj.io/storj/satellite/oidc"
|
"storj.io/storj/satellite/oidc"
|
||||||
@ -27,9 +26,6 @@ import (
|
|||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:embed ui/assets/*
|
|
||||||
var ui embed.FS
|
|
||||||
|
|
||||||
// Config defines configuration for debug server.
|
// Config defines configuration for debug server.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Address string `help:"admin peer http listening address" releaseDefault:"" devDefault:""`
|
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,
|
// 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.
|
// otherwise will try to serve all the handlers set after this one.
|
||||||
if config.StaticDir == "" {
|
if config.StaticDir == "" {
|
||||||
uiAssets, err := fs.Sub(ui, "ui/assets")
|
root.PathPrefix("/").Handler(http.FileServer(http.FS(adminui.Assets))).Methods("GET")
|
||||||
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")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
root.PathPrefix("/").Handler(http.FileServer(http.Dir(config.StaticDir))).Methods("GET")
|
root.PathPrefix("/").Handler(http.FileServer(http.Dir(config.StaticDir))).Methods("GET")
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ func TestBasic(t *testing.T) {
|
|||||||
baseURL := "http://" + address.String()
|
baseURL := "http://" + address.String()
|
||||||
|
|
||||||
t.Run("UI", func(t *testing.T) {
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
response, err := http.DefaultClient.Do(req)
|
response, err := http.DefaultClient.Do(req)
|
||||||
@ -42,7 +42,7 @@ func TestBasic(t *testing.T) {
|
|||||||
|
|
||||||
content, err := ioutil.ReadAll(response.Body)
|
content, err := ioutil.ReadAll(response.Body)
|
||||||
require.NoError(t, response.Body.Close())
|
require.NoError(t, response.Body.Close())
|
||||||
require.NotEmpty(t, content)
|
require.Empty(t, content)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
5
satellite/admin/ui/.gitignore
vendored
5
satellite/admin/ui/.gitignore
vendored
@ -1,8 +1,7 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
/build
|
/build/*
|
||||||
/assets/*
|
!/build/.keep
|
||||||
!/assets/.keep
|
|
||||||
/.svelte-kit
|
/.svelte-kit
|
||||||
/package
|
/package
|
||||||
.env
|
.env
|
||||||
|
@ -39,9 +39,3 @@ To create an optimized version of the app:
|
|||||||
```bash
|
```bash
|
||||||
npm run build
|
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/
|
|
||||||
```
|
|
||||||
|
22
satellite/admin/ui/assets.go
Normal file
22
satellite/admin/ui/assets.go
Normal file
@ -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
|
||||||
|
}()
|
2
satellite/admin/ui/assets/.gitignore
vendored
2
satellite/admin/ui/assets/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
*
|
|
||||||
!.gitignore
|
|
0
satellite/admin/ui/build/.keep
Normal file
0
satellite/admin/ui/build/.keep
Normal file
0
satellite/admin/ui/static/.keep
Normal file
0
satellite/admin/ui/static/.keep
Normal file
@ -13,7 +13,7 @@ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" release/$TAG/wasm/
|
|||||||
brotli -k release/$TAG/wasm/wasm_exec.js
|
brotli -k release/$TAG/wasm/wasm_exec.js
|
||||||
|
|
||||||
# Build wasm code
|
# 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
|
# Compress wasm code using brotli
|
||||||
brotli -k release/$TAG/wasm/access.wasm
|
brotli -k release/$TAG/wasm/access.wasm
|
||||||
|
Loading…
Reference in New Issue
Block a user