Enhance Dockerfile for platform-specific builds and improve comments
Docker / Docker Build & Push (push) Successful in 2m18s
Docker / Docker Build & Push (push) Successful in 2m18s
This commit is contained in:
1 parent
78f2b76ea8
commit
2919f28656
1 file changed
+9
-3
+9
-3
@@ -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
|
WORKDIR /frontend
|
||||||
COPY frontend/package*.json ./
|
COPY frontend/package*.json ./
|
||||||
COPY shared/package.json shared/package-lock.json /shared/
|
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
|
ln -s /shared/packages/web-ui /frontend/node_modules/@gabriel20xx/web-ui
|
||||||
RUN npm run build
|
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
|
WORKDIR /app
|
||||||
|
ARG TARGETOS TARGETARCH
|
||||||
COPY backend/go.mod backend/go.sum ./
|
COPY backend/go.mod backend/go.sum ./
|
||||||
COPY shared/backend/ /shared/backend/
|
COPY shared/backend/ /shared/backend/
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY backend/*.go ./
|
COPY backend/*.go ./
|
||||||
COPY --from=frontend-builder /frontend/build ./web
|
COPY --from=frontend-builder /frontend/build ./web
|
||||||
RUN apk add --no-cache ca-certificates && \
|
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
|
FROM scratch
|
||||||
COPY --from=builder /app/server /server
|
COPY --from=builder /app/server /server
|
||||||
|
|||||||
Reference in new issue
Block a user