Enhance Dockerfile for platform-specific builds and improve comments
Docker / Docker Build & Push (push) Successful in 2m18s

This commit is contained in:
Gabriel20xx committed 2026-08-10 13:48:56 +02:00
1 parent 78f2b76ea8
commit 2919f28656
1 file changed
+9 -3
+9 -3
View File
@@ -1,4 +1,7 @@
FROM node:22-alpine AS frontend-builder
# Pinned to the build machine's native platform: esbuild/rollup's worker
# threads can hang for hours under QEMU user-mode emulation (arm64 on amd64
# CI runners), and the compiled JS/CSS output is architecture-independent.
FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend-builder
WORKDIR /frontend
COPY frontend/package*.json ./
COPY shared/package.json shared/package-lock.json /shared/
@@ -22,15 +25,18 @@ RUN rm -rf /frontend/node_modules/@gabriel20xx/web-ui && \
ln -s /shared/packages/web-ui /frontend/node_modules/@gabriel20xx/web-ui
RUN npm run build
FROM golang:1.26-alpine AS builder
# Pinned to native too: Go cross-compiles trivially via GOOS/GOARCH, avoiding
# QEMU emulation for the compiler itself.
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
WORKDIR /app
ARG TARGETOS TARGETARCH
COPY backend/go.mod backend/go.sum ./
COPY shared/backend/ /shared/backend/
RUN go mod download
COPY backend/*.go ./
COPY --from=frontend-builder /frontend/build ./web
RUN apk add --no-cache ca-certificates && \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o server .
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-s -w" -o server .
FROM scratch
COPY --from=builder /app/server /server