storagenode: embed the console into the binary and makefile (#3164)
* web/storagenode: add package-lock.json * storagenode: compile console into binary
This commit is contained in:
parent
1d2808eeb0
commit
37491d0d32
19
Makefile
19
Makefile
@ -45,6 +45,7 @@ build-dev-deps: ## Install dependencies for builds
|
|||||||
go get github.com/mattn/goveralls
|
go get github.com/mattn/goveralls
|
||||||
go get golang.org/x/tools/cover
|
go get golang.org/x/tools/cover
|
||||||
go get github.com/modocache/gover
|
go get github.com/modocache/gover
|
||||||
|
go get github.com/go-bindata/go-bindata/go-bindata
|
||||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.19.1
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b ${GOPATH}/bin v1.19.1
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
@ -133,6 +134,22 @@ test-sim-backwards-compatible: ## Test uploading a file with lastest release (je
|
|||||||
|
|
||||||
##@ Build
|
##@ Build
|
||||||
|
|
||||||
|
.PHONY: storagenode-console
|
||||||
|
storagenode-console:
|
||||||
|
# build web assets
|
||||||
|
rm -rf web/storagenode/dist
|
||||||
|
# install npm dependencies and build the binaries
|
||||||
|
docker run --rm -i \
|
||||||
|
--mount type=bind,src="${PWD}",dst=/go/src/storj.io/storj \
|
||||||
|
-w /go/src/storj.io/storj/web/storagenode \
|
||||||
|
node:10.15.1 \
|
||||||
|
/bin/bash -c "npm ci && npm run build"
|
||||||
|
# embed web assets into go
|
||||||
|
go-bindata -prefix web/storagenode/ -fs -o storagenode/console/consoleassets/bindata.resource.go -pkg consoleassets web/storagenode/dist/... web/storagenode/static/...
|
||||||
|
# configure existing go code to know about the new assets
|
||||||
|
/bin/echo -e '\nfunc init() { FileSystem = AssetFile() }' >> storagenode/console/consoleassets/bindata.resource.go
|
||||||
|
gofmt -w -s storagenode/console/consoleassets/bindata.resource.go
|
||||||
|
|
||||||
.PHONY: images
|
.PHONY: images
|
||||||
images: gateway-image satellite-image storagenode-image uplink-image versioncontrol-image ## Build gateway, satellite, storagenode, uplink, and versioncontrol Docker images
|
images: gateway-image satellite-image storagenode-image uplink-image versioncontrol-image ## Build gateway, satellite, storagenode, uplink, and versioncontrol Docker images
|
||||||
echo Built version: ${TAG}
|
echo Built version: ${TAG}
|
||||||
@ -222,7 +239,7 @@ satellite_%:
|
|||||||
GOOS=$(word 2, $(subst _, ,$@)) GOARCH=$(word 3, $(subst _, ,$@)) COMPONENT=satellite $(MAKE) binary
|
GOOS=$(word 2, $(subst _, ,$@)) GOARCH=$(word 3, $(subst _, ,$@)) COMPONENT=satellite $(MAKE) binary
|
||||||
$(MAKE) binary-check COMPONENT=satellite GOARCH=$(word 3, $(subst _, ,$@)) GOOS=$(word 2, $(subst _, ,$@))
|
$(MAKE) binary-check COMPONENT=satellite GOARCH=$(word 3, $(subst _, ,$@)) GOOS=$(word 2, $(subst _, ,$@))
|
||||||
.PHONY: storagenode_%
|
.PHONY: storagenode_%
|
||||||
storagenode_%:
|
storagenode_%: storagenode-console
|
||||||
$(MAKE) binary-check COMPONENT=storagenode GOARCH=$(word 3, $(subst _, ,$@)) GOOS=$(word 2, $(subst _, ,$@))
|
$(MAKE) binary-check COMPONENT=storagenode GOARCH=$(word 3, $(subst _, ,$@)) GOOS=$(word 2, $(subst _, ,$@))
|
||||||
.PHONY: binary-check
|
.PHONY: binary-check
|
||||||
binary-check:
|
binary-check:
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
ARG DOCKER_ARCH
|
ARG DOCKER_ARCH
|
||||||
# Storagenode UI static asset generation
|
|
||||||
FROM node:10.15.1 as ui
|
|
||||||
WORKDIR /app
|
|
||||||
COPY web/storagenode/ /app
|
|
||||||
# Need to clean up (or ignore) local folders like node_modules, etc...
|
|
||||||
RUN npm install
|
|
||||||
RUN npm run build
|
|
||||||
FROM ${DOCKER_ARCH:-amd64}/alpine
|
FROM ${DOCKER_ARCH:-amd64}/alpine
|
||||||
ARG TAG
|
ARG TAG
|
||||||
ARG GOARCH
|
ARG GOARCH
|
||||||
@ -13,8 +6,6 @@ ENV GOARCH ${GOARCH}
|
|||||||
EXPOSE 28967
|
EXPOSE 28967
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
VOLUME /root/.local/share/storj/storagenode
|
VOLUME /root/.local/share/storj/storagenode
|
||||||
COPY --from=ui /app/static /app/static
|
|
||||||
COPY --from=ui /app/dist /app/dist
|
|
||||||
COPY resources/certs.pem /etc/ssl/certs/ca-certificates.crt
|
COPY resources/certs.pem /etc/ssl/certs/ca-certificates.crt
|
||||||
COPY release/${TAG}/storagenode_linux_${GOARCH:-amd64} /app/storagenode
|
COPY release/${TAG}/storagenode_linux_${GOARCH:-amd64} /app/storagenode
|
||||||
COPY cmd/storagenode/entrypoint /entrypoint
|
COPY cmd/storagenode/entrypoint /entrypoint
|
||||||
|
@ -14,7 +14,6 @@ RUN_PARAMS="${RUN_PARAMS:-} --contact.external-address=${ADDRESS}"
|
|||||||
RUN_PARAMS="${RUN_PARAMS:-} --operator.email=${EMAIL}"
|
RUN_PARAMS="${RUN_PARAMS:-} --operator.email=${EMAIL}"
|
||||||
RUN_PARAMS="${RUN_PARAMS:-} --operator.wallet=${WALLET}"
|
RUN_PARAMS="${RUN_PARAMS:-} --operator.wallet=${WALLET}"
|
||||||
RUN_PARAMS="${RUN_PARAMS:-} --console.address=:14002"
|
RUN_PARAMS="${RUN_PARAMS:-} --console.address=:14002"
|
||||||
RUN_PARAMS="${RUN_PARAMS:-} --console.static-dir=/app"
|
|
||||||
RUN_PARAMS="${RUN_PARAMS:-} --storage.allocated-bandwidth=${BANDWIDTH}"
|
RUN_PARAMS="${RUN_PARAMS:-} --storage.allocated-bandwidth=${BANDWIDTH}"
|
||||||
RUN_PARAMS="${RUN_PARAMS:-} --storage.allocated-disk-space=${STORAGE}"
|
RUN_PARAMS="${RUN_PARAMS:-} --storage.allocated-disk-space=${STORAGE}"
|
||||||
|
|
||||||
|
13
storagenode/console/consoleassets/assets.go
Normal file
13
storagenode/console/consoleassets/assets.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (C) 2019 Storj Labs, Inc.
|
||||||
|
// See LICENSE for copying information.
|
||||||
|
|
||||||
|
package consoleassets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FileSystem is nil by default, but when our Makefile generates
|
||||||
|
// embedded resources via go-bindata, it will also drop an init method
|
||||||
|
// that sets this to not nil.
|
||||||
|
var FileSystem http.FileSystem
|
@ -8,7 +8,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/zeebo/errs"
|
"github.com/zeebo/errs"
|
||||||
@ -44,7 +43,6 @@ type Config struct {
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
|
|
||||||
config Config
|
|
||||||
service *console.Service
|
service *console.Service
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
|
|
||||||
@ -52,23 +50,23 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates new instance of storagenode console web server.
|
// NewServer creates new instance of storagenode console web server.
|
||||||
func NewServer(logger *zap.Logger, config Config, service *console.Service, listener net.Listener) *Server {
|
func NewServer(logger *zap.Logger, assets http.FileSystem, service *console.Service, listener net.Listener) *Server {
|
||||||
server := Server{
|
server := Server{
|
||||||
log: logger,
|
log: logger,
|
||||||
service: service,
|
service: service,
|
||||||
config: config,
|
|
||||||
listener: listener,
|
listener: listener,
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs http.Handler
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
// handle static pages
|
if assets != nil {
|
||||||
if config.StaticDir != "" {
|
fs := http.FileServer(assets)
|
||||||
fs = http.FileServer(http.Dir(server.config.StaticDir))
|
|
||||||
|
|
||||||
mux.Handle("/static/", http.StripPrefix("/static", fs))
|
mux.Handle("/static/", http.StripPrefix("/static", fs))
|
||||||
mux.Handle("/", http.HandlerFunc(server.appHandler))
|
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
req := r.Clone(r.Context())
|
||||||
|
req.URL.Path = "/dist/"
|
||||||
|
fs.ServeHTTP(w, req)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle api endpoints
|
// handle api endpoints
|
||||||
@ -106,11 +104,6 @@ func (server *Server) Close() error {
|
|||||||
return server.server.Close()
|
return server.server.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// appHandler is web app http handler function.
|
|
||||||
func (server *Server) appHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
http.ServeFile(w, r, filepath.Join(server.config.StaticDir, "dist", "index.html"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// dashboardHandler handles dashboard API requests.
|
// dashboardHandler handles dashboard API requests.
|
||||||
func (server *Server) dashboardHandler(w http.ResponseWriter, r *http.Request) {
|
func (server *Server) dashboardHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
@ -6,6 +6,7 @@ package storagenode
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/zeebo/errs"
|
"github.com/zeebo/errs"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
@ -27,6 +28,7 @@ import (
|
|||||||
"storj.io/storj/storagenode/bandwidth"
|
"storj.io/storj/storagenode/bandwidth"
|
||||||
"storj.io/storj/storagenode/collector"
|
"storj.io/storj/storagenode/collector"
|
||||||
"storj.io/storj/storagenode/console"
|
"storj.io/storj/storagenode/console"
|
||||||
|
"storj.io/storj/storagenode/console/consoleassets"
|
||||||
"storj.io/storj/storagenode/console/consoleserver"
|
"storj.io/storj/storagenode/console/consoleserver"
|
||||||
"storj.io/storj/storagenode/contact"
|
"storj.io/storj/storagenode/contact"
|
||||||
"storj.io/storj/storagenode/inspector"
|
"storj.io/storj/storagenode/inspector"
|
||||||
@ -349,9 +351,15 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, revocationDB exten
|
|||||||
return nil, errs.Combine(err, peer.Close())
|
return nil, errs.Combine(err, peer.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assets := consoleassets.FileSystem
|
||||||
|
if config.Console.StaticDir != "" {
|
||||||
|
// a specific directory has been configured. use it
|
||||||
|
assets = http.Dir(config.Console.StaticDir)
|
||||||
|
}
|
||||||
|
|
||||||
peer.Console.Endpoint = consoleserver.NewServer(
|
peer.Console.Endpoint = consoleserver.NewServer(
|
||||||
peer.Log.Named("console:endpoint"),
|
peer.Log.Named("console:endpoint"),
|
||||||
config.Console,
|
assets,
|
||||||
peer.Console.Service,
|
peer.Console.Service,
|
||||||
peer.Console.Listener,
|
peer.Console.Listener,
|
||||||
)
|
)
|
||||||
|
1
web/storagenode/.gitignore
vendored
1
web/storagenode/.gitignore
vendored
@ -1,7 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
package-lock.json
|
|
||||||
coverage
|
coverage
|
||||||
temp
|
temp
|
||||||
|
|
||||||
|
15006
web/storagenode/package-lock.json
generated
Normal file
15006
web/storagenode/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user