alby-hub/Dockerfile
Roland 51ce7c64a0
Feat: allow hosting alby hub on subpath (#1439)
* feat: add base path to front end

- add docker build arg to set base path frontend is served under
- set vite.config.ts base value based on docker build arg
- update http variant request function to inject base path during calls to /api and /images
- update how static assets are loaded from public folder to inject base path during vite build

To use a base path build the docker image with --build-arg BASE_PATH=/hub/.
All assets and api calls from the frontend will use that base path as prefix.

The backend service is not using the base path, when using a proxy the base path has to be stripped.

* chore: simplify base path usage and add extra documentation

* chore: add extra documentation

---------

Co-authored-by: 8de2fdb0 <89734465+8de2fdb0@users.noreply.github.com>
2025-06-26 16:23:40 +05:30

65 lines
1.8 KiB
Docker

FROM node:20-alpine as frontend
# Set the base path for the frontend build
# This can be overridden at build time with --build-arg BASE_PATH=<url> e.g. --build-arg BASE_PATH=/hub
# Allows to build a frontend that can be served from a subpath, e.g. /hub
ARG BASE_PATH
WORKDIR /build
COPY frontend ./frontend
RUN echo "Building frontend with base path $BASE_PATH"
RUN cd frontend && yarn install --network-timeout 3000000 && yarn build:http
FROM golang:1.24 as builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TAG
RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM, release tag $TAG"
RUN apt-get update && \
apt-get install -y gcc
ENV CGO_ENABLED=1
ENV GOOS=linux
#ENV GOARCH=$GOARCH
#RUN echo "AAA $GOARCH"
# Move to working directory /build
WORKDIR /build
# Copy and download dependency using go mod
COPY go.mod .
COPY go.sum .
RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go mod download
# Copy the code into the container
COPY . .
# Copy frontend dist files into the container
COPY --from=frontend /build/frontend/dist ./frontend/dist
RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build \
-ldflags="-X 'github.com/getAlby/hub/version.Tag=$TAG'" \
-o main cmd/http/main.go
RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build \
-o db_migrate cmd/db_migrate/main.go
COPY ./build/docker/copy_dylibs.sh .
RUN chmod +x copy_dylibs.sh
RUN ./copy_dylibs.sh $(echo "$TARGETPLATFORM" | cut -d'/' -f2)
# Start a new, final image to reduce size.
FROM debian:12-slim as final
ENV LD_LIBRARY_PATH=/usr/lib/nwc
#
# # Copy the binaries and entrypoint from the builder image.
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/libldk_node.so /usr/lib/nwc/
COPY --from=builder /build/main /bin/
COPY --from=builder /build/db_migrate /bin/
ENTRYPOINT [ "/bin/main" ]