Skip to content

Commit 8e422d0

Browse files
committed
multi: create second image with path prefix
We want to allow users to use LiT under a custom path to make it easier to integrate LiT in bundled software such as BTCPayServer. Because the custom path prefix must be known at build time, we create an additional docker image that uses the static /lit path as the prefix.
1 parent 20f76dc commit 8e422d0

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-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

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)