1 FROM node:22-alpine AS frontend
2 3 # Set the base path for the frontend build
4 # This can be overridden at build time with --build-arg BASE_PATH=<url> e.g. --build-arg BASE_PATH=/hub
5 # Allows to build a frontend that can be served from a subpath, e.g. /hub
6 ARG BASE_PATH
7 WORKDIR /build
8 COPY frontend ./frontend
9 RUN echo "Building frontend with base path $BASE_PATH"
10 RUN cd frontend && yarn install --network-timeout 3000000 && yarn build:http
11 12 FROM golang:1.26.2 AS builder
13 14 ARG TARGETPLATFORM
15 ARG BUILDPLATFORM
16 ARG TAG
17 18 RUN echo "I am running on $BUILDPLATFORM, building for $TARGETPLATFORM, release tag $TAG"
19 20 RUN apt-get update && \
21 apt-get install -y gcc
22 23 ENV CGO_ENABLED=1
24 ENV GOOS=linux
25 #ENV GOARCH=$GOARCH
26 27 #RUN echo "AAA $GOARCH"
28 29 # Move to working directory /build
30 WORKDIR /build
31 32 # Copy and download dependency using go mod
33 COPY go.mod .
34 COPY go.sum .
35 RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go mod download
36 37 # Copy the code into the container
38 COPY . .
39 40 # Copy frontend dist files into the container
41 COPY --from=frontend /build/frontend/dist ./frontend/dist
42 43 RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build \
44 -ldflags="-X 'github.com/getAlby/hub/version.Tag=$TAG'" \
45 -o main cmd/http/main.go
46 47 RUN GOARCH=$(echo "$TARGETPLATFORM" | cut -d'/' -f2) go build \
48 -o db_migrate cmd/db_migrate/main.go
49 50 COPY ./build/docker/copy_dylibs.sh .
51 RUN chmod +x copy_dylibs.sh
52 RUN ./copy_dylibs.sh $(echo "$TARGETPLATFORM" | cut -d'/' -f2)
53 54 # Start a new, final image to reduce size.
55 FROM debian:12-slim AS final
56 57 ENV LD_LIBRARY_PATH=/usr/lib/nwc
58 #
59 # # Copy the binaries and entrypoint from the builder image.
60 COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
61 COPY --from=builder /build/libldk_node.so /usr/lib/nwc/
62 COPY --from=builder /build/main /bin/
63 COPY --from=builder /build/db_migrate /bin/
64 65 ENTRYPOINT [ "/bin/main" ]
66