Skip to content

Commit 90f08a6

Browse files
committed
multi: replace statik with go1.16 embed directive
We can now simply use the //go:embed directive to compile everything in the app/build directory into our root package.
1 parent b1d820c commit 90f08a6

File tree

8 files changed

+27
-47
lines changed

8 files changed

+27
-47
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44
litd-debug
55
/lightning-terminal-*
66

7-
# go code generated by statik
8-
/statik/statik.go
9-
107
# MacOS junk
118
.DS_Store

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ ENV GO111MODULE on
4646
RUN apk add --no-cache --update alpine-sdk \
4747
make \
4848
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
49-
&& make statik-only \
5049
&& make go-install \
5150
&& make go-install-cli
5251

Makefile

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ POOL_PKG := github.com/lightninglabs/pool
77
LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
88
GOVERALLS_PKG := github.com/mattn/goveralls
99
GOACC_PKG := github.com/ory/go-acc
10-
STATIK_PKG := github.com/rakyll/statik
1110

1211
GO_BIN := ${GOPATH}/bin
1312
GOVERALLS_BIN := $(GO_BIN)/goveralls
1413
LINT_BIN := $(GO_BIN)/golangci-lint
1514
GOACC_BIN := $(GO_BIN)/go-acc
16-
STATIK_BIN := $(GO_BIN)/statik
1715

1816
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
1917
COMMIT_HASH := $(shell git rev-parse HEAD)
@@ -94,25 +92,16 @@ $(GOACC_BIN):
9492
@$(call print, "Fetching go-acc")
9593
$(DEPGET) $(GOACC_PKG)@$(GOACC_COMMIT)
9694

97-
$(STATIK_BIN):
98-
@$(call print, "Fetching statik")
99-
$(DEPGET) $(STATIK_PKG)
100-
10195
yarn-install:
10296
@$(call print, "Installing app dependencies with yarn")
10397
cd app; yarn
10498

10599
# ============
106100
# INSTALLATION
107101
# ============
108-
statik-only: $(STATIK_BIN)
109-
@$(call print, "Building statik package.")
110-
statik -src=app/build
111-
112-
statik-build: app-build statik-only
113102

114-
build: statik-build go-build
115-
install: statik-build go-install
103+
build: app-build go-build
104+
install: app-build go-install
116105

117106
go-build:
118107
@$(call print, "Building lightning-terminal.")
@@ -133,7 +122,7 @@ app-build: yarn-install
133122
@$(call print, "Building production app.")
134123
cd app; yarn build
135124

136-
release: statik-build
125+
release: app-build
137126
@$(call print, "Creating release of lightning-terminal.")
138127
./release.sh build-release "$(VERSION_TAG)" "$(BUILD_SYSTEM)" "$(LND_RELEASE_TAGS)" "$(RELEASE_LDFLAGS)"
139128

@@ -214,4 +203,3 @@ clean:
214203
@$(call print, "Cleaning source.$(NC)")
215204
$(RM) ./lightning-terminal-debug
216205
$(RM) coverage.txt
217-
$(RM) -r statik

dev.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ ENV GO111MODULE on
2727
RUN apk add --no-cache --update alpine-sdk \
2828
make \
2929
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
30-
&& make statik-only \
3130
&& make go-install \
3231
&& make go-install-cli
3332

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ require (
1818
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
1919
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76
2020
github.com/prometheus/client_golang v1.5.1 // indirect
21-
github.com/rakyll/statik v0.1.7
2221
github.com/rs/cors v1.7.0 // indirect
2322
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
2423
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
314314
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
315315
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
316316
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
317-
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
318-
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
319317
github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s=
320318
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
321319
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

statik/doc.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

terminal.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package terminal
33
import (
44
"context"
55
"crypto/tls"
6+
"embed"
67
"errors"
78
"fmt"
9+
"io/fs"
810
"net"
911
"net/http"
1012
"os"
@@ -29,15 +31,10 @@ import (
2931
"github.com/lightningnetwork/lnd/lnrpc"
3032
"github.com/lightningnetwork/lnd/lntest/wait"
3133
"github.com/lightningnetwork/lnd/signal"
32-
"github.com/rakyll/statik/fs"
3334
"google.golang.org/grpc"
3435
"google.golang.org/grpc/codes"
3536
"google.golang.org/grpc/status"
3637
"gopkg.in/macaroon-bakery.v2/bakery"
37-
38-
// Import generated go package that contains all static files for the
39-
// UI in a compressed format.
40-
_ "github.com/lightninglabs/lightning-terminal/statik"
4138
)
4239

4340
const (
@@ -50,6 +47,19 @@ var (
5047
// maxMsgRecvSize is the largest message our REST proxy will receive. We
5148
// set this to 200MiB atm.
5249
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(1 * 1024 * 1024 * 200)
50+
51+
// appBuildFS is an in-memory file system that contains all the static
52+
// HTML/CSS/JS files of the UI. It is compiled into the binary with the
53+
// go 1.16 embed directive below. Because the path is relative to the
54+
// root package, all assets will have a path prefix of /app/build/ which
55+
// we'll strip by giving a sub directory to the HTTP server.
56+
//
57+
//go:embed app/build/*
58+
appBuildFS embed.FS
59+
60+
// appFilesDir is the sub directory of the above build directory which
61+
// we pass to the HTTP server.
62+
appFilesDir = "app/build"
5363
)
5464

5565
// LightningTerminal is the main grand unified binary instance. Its task is to
@@ -523,14 +533,14 @@ func (g *LightningTerminal) shutdown() error {
523533
}
524534

525535
// startMainWebServer creates the main web HTTP server that delegates requests
526-
// between the Statik HTTP server and the RPC proxy. An incoming request will
536+
// between the embedded HTTP server and the RPC proxy. An incoming request will
527537
// go through the following chain of components:
528538
//
529539
// Request on port 8443
530540
// |
531541
// v
532542
// +---+----------------------+ other +----------------+
533-
// | Main web HTTP server +------->+ Statik HTTP |
543+
// | Main web HTTP server +------->+ Embedded HTTP |
534544
// +---+----------------------+ +----------------+
535545
// |
536546
// v any RPC or REST call
@@ -566,12 +576,15 @@ func (g *LightningTerminal) shutdown() error {
566576
//
567577
func (g *LightningTerminal) startMainWebServer() error {
568578
// Initialize the in-memory file server from the content compiled by
569-
// the statik library.
570-
statikFS, err := fs.New()
579+
// the go:embed directive. Since everything's relative to the root dir,
580+
// we need to create an FS of the sub directory app/build.
581+
buildDir, err := fs.Sub(appBuildFS, appFilesDir)
571582
if err != nil {
572-
return fmt.Errorf("could not load statik file system: %v", err)
583+
return err
573584
}
574-
staticFileServer := http.FileServer(&ClientRouteWrapper{statikFS})
585+
staticFileServer := http.FileServer(&ClientRouteWrapper{
586+
assets: http.FS(buildDir),
587+
})
575588

576589
// Both gRPC (web) and static file requests will come into through the
577590
// main UI HTTP server. We use this simple switching handler to send the

0 commit comments

Comments
 (0)