Skip to content

Commit 91c8198

Browse files
authored
Merge pull request #275 from lightninglabs/prefix-build
docker: create and push secondary image with path prefix
2 parents 20f76dc + b82f403 commit 91c8198

File tree

6 files changed

+134
-6
lines changed

6 files changed

+134
-6
lines changed

.github/workflows/docker.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set env
3434
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
3535

36-
- name: Build and push
36+
- name: Build and push default image
3737
id: docker_build
3838
uses: lightninglabs/gh-actions/[email protected]
3939
with:
@@ -42,5 +42,14 @@ jobs:
4242
tags: "${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}"
4343
build-args: checkout=${{ env.RELEASE_VERSION }}
4444

45+
- name: Build and push image with /lit path
46+
id: docker_build2
47+
uses: lightninglabs/gh-actions/[email protected]
48+
with:
49+
push: true
50+
platforms: linux/amd64,linux/arm64
51+
tags: "${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}-path-prefix"
52+
build-args: checkout=${{ env.RELEASE_VERSION }} public_url=/lit
53+
4554
- name: Image digest
46-
run: echo ${{ steps.docker_build.outputs.digest }}
55+
run: echo ${{ steps.docker_build.outputs.digest }} ${{ steps.docker_build2.outputs.digest }}

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ FROM node:12.17.0-alpine as nodejsbuilder
66
# master by default.
77
ARG checkout="master"
88

9+
# The public URL the static files should be served under. This must be empty to
10+
# work for the root path (/).
11+
ARG public_url=""
12+
913
# There seem to be multiple problems when using yarn for a build inside of a
1014
# docker image:
1115
# 1. For building and installing node-gyp, python is required. This seems to
@@ -25,7 +29,7 @@ RUN apk add --no-cache --update alpine-sdk \
2529
&& npm config set registry "http://registry.npmjs.org" \
2630
&& yarn config set registry "http://registry.npmjs.org" \
2731
&& yarn install --frozen-lockfile --network-timeout 1000000 \
28-
&& yarn build
32+
&& PUBLIC_URL=$public_url yarn build
2933

3034
# The first stage is already done and all static assets should now be generated
3135
# in the app/build sub directory.
@@ -46,7 +50,7 @@ ENV GO111MODULE on
4650
RUN apk add --no-cache --update alpine-sdk \
4751
make \
4852
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
49-
&& make go-install \
53+
&& make go-install PUBLIC_URL=$public_url \
5054
&& make go-install-cli
5155

5256
# Start a new, final image to reduce size.

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ GOACC_BIN := $(GO_BIN)/go-acc
1515

1616
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
1717
COMMIT_HASH := $(shell git rev-parse HEAD)
18+
PUBLIC_URL :=
1819

1920
LOOP_COMMIT := $(shell cat go.mod | \
2021
grep $(LOOP_PKG) | \
@@ -57,6 +58,7 @@ make_ldflags = $(2) -X $(LND_PKG)/build.Commit=lightning-terminal-$(COMMIT) \
5758
-X $(LND_PKG)/build.CommitHash=$(COMMIT_HASH) \
5859
-X $(LND_PKG)/build.GoVersion=$(GOVERSION) \
5960
-X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g') \
61+
-X $(PKG).appFilesPrefix=$(PUBLIC_URL) \
6062
-X $(LOOP_PKG).Commit=$(LOOP_COMMIT) \
6163
-X $(POOL_PKG).Commit=$(POOL_COMMIT)
6264

doc/custom-path.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Using a custom path for LiT
2+
3+
If required LiT can be built to be accessed through a custom path (e.g. `/lit/`)
4+
in the browser instead of the default root path (`/`).
5+
6+
To build LiT with a custom path, run the following command:
7+
8+
```shell
9+
⛰ make PUBLIC_URL=/my-custom-path
10+
```
11+
12+
**Make sure to not include a `/` at the end of the path.** To revert to the
13+
original, root path, set the variable to empty (`make PUBLIC_URL=`) or leave
14+
it out completely.
15+
16+
## Docker image built with a path prefix
17+
18+
There is a docker image that's automatically built with the prefix `/lit`
19+
available on Docker Hub. Just append `-path-prefix` to any version tag (after
20+
`v0.5.2-alpha`). For example:
21+
22+
```shell
23+
# Default image.
24+
⛰ docker pull lightninglabs/lightning-terminal:v0.5.3-alpha
25+
26+
# Image with /lit path prefix.
27+
⛰ docker pull lightninglabs/lightning-terminal:v0.5.3-alpha-path-prefix
28+
```
29+
30+
## Use with nginx reverse proxy
31+
32+
There is [an example nginx](example-nginx.conf) config file that demonstrates
33+
how rewrite rules can be set up to run LiT under the `/lit` path prefix (and
34+
internally forward all `grpc-web` requests to the LiT proxy while still
35+
forwarding "native" gRPC requests to the `lnd` instance that's also running
36+
behind the nginx reverse proxy).
37+
38+
The example reverse proxy can be run with:
39+
40+
```shell
41+
cd docs
42+
⛰ docker run --name lit-nginx \
43+
-v $(pwd)/example-nginx.conf:/etc/nginx/nginx.conf:ro -p 8081:80 -d nginx
44+
```

doc/example-nginx.conf

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
# Redirect all incoming grpc-web requests to the LiT proxy. Everything else
7+
# goes directly to the internal lnd container. We use a temporary variable
8+
# here so we can rewrite it to the actual host again in the next map
9+
# directive.
10+
map $content_type $tmp_backend {
11+
"application/grpc-web+proto" "172.17.0.1:8443"; # LiT proxy.
12+
default "localhost:10009"; # main LND
13+
}
14+
15+
# Streaming grpc-web requests can be identified by the
16+
# "Sec-WebSocket-Protocol: grpc-websockets" header field. So those requests
17+
# also need to go to the LiT proxy.
18+
map $http_sec_websocket_protocol $lnd_backend {
19+
"grpc-websockets" "172.17.0.1:8443"; # LiT proxy.
20+
default $tmp_backend; # Fall back to the value from the above map result.
21+
}
22+
23+
# Make sure WebSockets are properly upgraded.
24+
map $http_sec_websocket_protocol $lnd_connection {
25+
"grpc-websockets" "upgrade";
26+
default $http_connection;
27+
}
28+
29+
server {
30+
listen 80;
31+
server_name localhost;
32+
33+
proxy_set_header Upgrade $http_upgrade;
34+
proxy_set_header Origin https://$lnd_backend;
35+
proxy_set_header Connection $lnd_connection;
36+
37+
location /lit {
38+
# This needs a slash at the end!
39+
proxy_pass https://172.17.0.1:8443/;
40+
}
41+
42+
location ~* ^/lnrpc.Lightning/ {
43+
# This cannot have a slash at the end!
44+
proxy_pass https://$lnd_backend;
45+
}
46+
47+
location ~* ^/looprpc.SwapClient/ {
48+
# This cannot have a slash at the end!
49+
proxy_pass https://$lnd_backend;
50+
}
51+
52+
location ~* ^/poolrpc.Trader/ {
53+
# This cannot have a slash at the end!
54+
proxy_pass https://$lnd_backend;
55+
}
56+
}
57+
}

terminal.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ var (
7474
// we pass to the HTTP server.
7575
appFilesDir = "app/build"
7676

77+
// appFilesPrefix is the path prefix the static assets of the UI are
78+
// exposed under. This variable can be overwritten during build time if
79+
// a different deployment path should be used.
80+
appFilesPrefix = ""
81+
7782
// patternRESTRequest is the regular expression that matches all REST
7883
// URIs that are currently used by lnd, faraday, loop and pool.
7984
patternRESTRequest = regexp.MustCompile(`^/v\d/.*`)
@@ -971,8 +976,15 @@ type ClientRouteWrapper struct {
971976
// is no file extension, then assume this is a client side route and return the
972977
// contents of index.html
973978
func (i *ClientRouteWrapper) Open(name string) (http.File, error) {
974-
ret, err := i.assets.Open(name)
975-
if !os.IsNotExist(err) || filepath.Ext(name) != "" {
979+
localName := name
980+
981+
// The file prefix can be overwritten during build time.
982+
if appFilesPrefix != "" {
983+
localName = strings.Replace(name, appFilesPrefix, "/", 1)
984+
}
985+
localName = strings.ReplaceAll(localName, "//", "/")
986+
ret, err := i.assets.Open(localName)
987+
if !os.IsNotExist(err) || filepath.Ext(localName) != "" {
976988
return ret, err
977989
}
978990

0 commit comments

Comments
 (0)