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.
This commit is contained in:
Oliver Gugger 2021-10-08 11:35:06 +02:00
parent 20f76dc5ab
commit 8e422d058e
No known key found for this signature in database
GPG key ID: 8E4256593F177720
4 changed files with 33 additions and 6 deletions

View file

@ -33,7 +33,7 @@ jobs:
- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build and push
- name: Build and push default image
id: docker_build
uses: lightninglabs/gh-actions/build-push-action@2021.01.25.00
with:
@ -42,5 +42,14 @@ jobs:
tags: "${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}"
build-args: checkout=${{ env.RELEASE_VERSION }}
- name: Build and push image with /lit path
id: docker_build2
uses: lightninglabs/gh-actions/build-push-action@2021.01.25.00
with:
push: true
platforms: linux/amd64,linux/arm64
tags: "${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}-path-prefix"
build-args: checkout=${{ env.RELEASE_VERSION }} public_url=/lit
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
run: echo ${{ steps.docker_build.outputs.digest }} ${{ steps.docker_build2.outputs.digest }}

View file

@ -6,6 +6,10 @@ FROM node:12.17.0-alpine as nodejsbuilder
# master by default.
ARG checkout="master"
# The public URL the static files should be served under. This must be empty to
# work for the root path (/).
ARG public_url=""
# There seem to be multiple problems when using yarn for a build inside of a
# docker image:
# 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 \
&& npm config set registry "http://registry.npmjs.org" \
&& yarn config set registry "http://registry.npmjs.org" \
&& yarn install --frozen-lockfile --network-timeout 1000000 \
&& yarn build
&& PUBLIC_URL=$public_url yarn build
# The first stage is already done and all static assets should now be generated
# in the app/build sub directory.
@ -46,7 +50,7 @@ ENV GO111MODULE on
RUN apk add --no-cache --update alpine-sdk \
make \
&& cd /go/src/github.com/lightninglabs/lightning-terminal \
&& make go-install \
&& make go-install PUBLIC_URL=$public_url \
&& make go-install-cli
# Start a new, final image to reduce size.

View file

@ -15,6 +15,7 @@ GOACC_BIN := $(GO_BIN)/go-acc
COMMIT := $(shell git describe --abbrev=40 --dirty --tags)
COMMIT_HASH := $(shell git rev-parse HEAD)
PUBLIC_URL :=
LOOP_COMMIT := $(shell cat go.mod | \
grep $(LOOP_PKG) | \
@ -57,6 +58,7 @@ make_ldflags = $(2) -X $(LND_PKG)/build.Commit=lightning-terminal-$(COMMIT) \
-X $(LND_PKG)/build.CommitHash=$(COMMIT_HASH) \
-X $(LND_PKG)/build.GoVersion=$(GOVERSION) \
-X $(LND_PKG)/build.RawTags=$(shell echo $(1) | sed -e 's/ /,/g') \
-X $(PKG).appFilesPrefix=$(PUBLIC_URL) \
-X $(LOOP_PKG).Commit=$(LOOP_COMMIT) \
-X $(POOL_PKG).Commit=$(POOL_COMMIT)

View file

@ -74,6 +74,11 @@ var (
// we pass to the HTTP server.
appFilesDir = "app/build"
// appFilesPrefix is the path prefix the static assets of the UI are
// exposed under. This variable can be overwritten during build time if
// a different deployment path should be used.
appFilesPrefix = ""
// patternRESTRequest is the regular expression that matches all REST
// URIs that are currently used by lnd, faraday, loop and pool.
patternRESTRequest = regexp.MustCompile(`^/v\d/.*`)
@ -971,8 +976,15 @@ type ClientRouteWrapper struct {
// is no file extension, then assume this is a client side route and return the
// contents of index.html
func (i *ClientRouteWrapper) Open(name string) (http.File, error) {
ret, err := i.assets.Open(name)
if !os.IsNotExist(err) || filepath.Ext(name) != "" {
localName := name
// The file prefix can be overwritten during build time.
if appFilesPrefix != "" {
localName = strings.Replace(name, appFilesPrefix, "/", 1)
}
localName = strings.ReplaceAll(localName, "//", "/")
ret, err := i.assets.Open(localName)
if !os.IsNotExist(err) || filepath.Ext(localName) != "" {
return ret, err
}