Skip to content

Commit cb24a1b

Browse files
authored
Merge pull request #180 from lightninglabs/go-1.16-embed
Use go 1.16 embed instead of statik
2 parents aad7fc5 + 52f2480 commit cb24a1b

File tree

10 files changed

+33
-56
lines changed

10 files changed

+33
-56
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373

7474
strategy:
7575
matrix:
76-
go_version: [1.14.x]
76+
go_version: [1.16.x]
7777
os: [ubuntu-latest, windows-latest, macOS-latest]
7878

7979
steps:
@@ -117,6 +117,9 @@ jobs:
117117

118118
- name: build backend binary
119119
run: make build
120+
121+
- name: build CLI binaries
122+
run: make go-install-cli
120123

121124
proto-compile-check:
122125
name: RPC proto compilation check

.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

doc/compile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ installed on your machine.
55

66
| Dependency | Description |
77
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
8-
| [golang](https://golang.org/doc/install) | LiT's backend web server is written in Go. The minimum version supported is Go v1.13. |
8+
| [golang](https://golang.org/doc/install) | LiT's backend web server is written in Go. The minimum version supported is Go v1.16. |
99
| [nodejs](https://nodejs.org/en/download/) | LiT's frontend is written in TypeScript and built on top of the React JS web framework. To bundle the assets into Javascript & CSS compatible with web browsers, NodeJS is required. |
1010
| [yarn](https://classic.yarnpkg.com/en/docs/install) | A popular package manager for NodeJS application dependencies. |
1111

go.mod

Lines changed: 1 addition & 2 deletions
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
@@ -28,4 +27,4 @@ require (
2827
gopkg.in/macaroon.v2 v2.1.0
2928
)
3029

31-
go 1.13
30+
go 1.16

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHqu
120120
github.com/frankban/quicktest v1.0.0/go.mod h1:R98jIehRai+d1/3Hv2//jOVCTJhW1VBavT6B6CuGq2k=
121121
github.com/frankban/quicktest v1.2.2 h1:xfmOhhoH5fGPgbEAlhLpJH9p0z/0Qizio9osmvn9IUY=
122122
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
123-
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
124123
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
125124
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
126125
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
@@ -171,7 +170,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.14.3/go.mod h1:6CwZWGDSPRJidgKAtJVvND6
171170
github.com/grpc-ecosystem/grpc-gateway v1.14.6 h1:8ERzHx8aj1Sc47mu9n/AksaKCSWrMchFtkdrS4BIj5o=
172171
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
173172
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
174-
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
175173
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
176174
github.com/improbable-eng/grpc-web v0.12.0 h1:GlCS+lMZzIkfouf7CNqY+qqpowdKuJLSLLcKVfM1oLc=
177175
github.com/improbable-eng/grpc-web v0.12.0/go.mod h1:6hRR09jOEG81ADP5wCQju1z71g6OL4eEvELdran/3cs=
@@ -287,10 +285,8 @@ github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76 h1:0xuRacu/Zr+j
287285
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76/go.mod h1:x5OoJHDHqxHS801UIuhqGl6QdSAEJvtausosHSdazIo=
288286
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
289287
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
290-
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
291288
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
292289
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
293-
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
294290
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
295291
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
296292
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
@@ -318,8 +314,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
318314
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
319315
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
320316
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
321-
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
322-
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
323317
github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s=
324318
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
325319
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -479,7 +473,6 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
479473
gopkg.in/errgo.v1 v1.0.1 h1:oQFRXzZ7CkBGdm1XZm/EbQYaYNNEElNBOd09M6cqNso=
480474
gopkg.in/errgo.v1 v1.0.1/go.mod h1:3NjfXwocQRYAPTq4/fzX+CwUhPRcR/azYRhj8G+LqMo=
481475
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
482-
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
483476
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
484477
gopkg.in/macaroon-bakery.v2 v2.0.1/go.mod h1:B4/T17l+ZWGwxFSZQmlBwp25x+og7OkhETfr3S9MbIA=
485478
gopkg.in/macaroon-bakery.v2 v2.1.0 h1:9Jw/+9XHBSutkaeVpWhDx38IcSNLJwWUICkOK98DHls=
@@ -489,7 +482,6 @@ gopkg.in/macaroon.v2 v2.1.0 h1:HZcsjBCzq9t0eBPMKqTN/uSN6JOm78ZJ2INbqcBQOUI=
489482
gopkg.in/macaroon.v2 v2.1.0/go.mod h1:OUb+TQP/OP0WOerC2Jp/3CwhIKyIa9kQjuc7H24e6/o=
490483
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
491484
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
492-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
493485
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
494486
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
495487
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

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)