Skip to content

Commit 77018a9

Browse files
committed
feat: improve build stage
1 parent 714f122 commit 77018a9

File tree

7 files changed

+2985
-5
lines changed

7 files changed

+2985
-5
lines changed

Dockerfile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
FROM node:22-alpine AS spa-builder
1+
# syntax=docker/dockerfile:1.7
2+
3+
# Build the SPA with the build platform to avoid slow QEMU emulation on arm64
4+
FROM --platform=$BUILDPLATFORM node:22-bookworm-slim AS spa-builder
25

36
WORKDIR /app/webapp
47
COPY webapp/package*.json ./
5-
RUN npm ci
8+
# Speed up and stabilize npm installs in CI
9+
# - no-audit/no-fund: skip network calls
10+
# - no-progress: cleaner logs
11+
# - cache mount: reuse npm cache between builds
12+
RUN --mount=type=cache,target=/root/.npm \
13+
npm ci --no-audit --no-fund --no-progress
614
COPY webapp/ ./
715
RUN npm run build
816

@@ -14,22 +22,32 @@ RUN adduser -D -g '' ackuser
1422
WORKDIR /app
1523
COPY go.mod go.sum ./
1624
ENV GOTOOLCHAIN=auto
17-
RUN go mod download && go mod verify
25+
# Cache Go modules and build cache between builds
26+
RUN --mount=type=cache,target=/go/pkg/mod \
27+
--mount=type=cache,target=/root/.cache/go-build \
28+
go mod download && go mod verify
1829
COPY backend/ ./backend/
1930

2031
RUN mkdir -p backend/cmd/community/web/dist
2132
COPY --from=spa-builder /app/webapp/dist ./backend/cmd/community/web/dist
2233

34+
# Cross-compile per target platform
35+
ARG TARGETOS
36+
ARG TARGETARCH
2337
ARG VERSION="dev"
2438
ARG COMMIT="unknown"
2539
ARG BUILD_DATE="unknown"
2640

27-
RUN CGO_ENABLED=0 GOOS=linux go build \
41+
RUN --mount=type=cache,target=/go/pkg/mod \
42+
--mount=type=cache,target=/root/.cache/go-build \
43+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
2844
-a -installsuffix cgo \
2945
-ldflags="-w -s -X main.Version=${VERSION} -X main.Commit=${COMMIT} -X main.BuildDate=${BUILD_DATE}" \
3046
-o ackify ./backend/cmd/community
3147

32-
RUN CGO_ENABLED=0 GOOS=linux go build \
48+
RUN --mount=type=cache,target=/go/pkg/mod \
49+
--mount=type=cache,target=/root/.cache/go-build \
50+
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build \
3351
-a -installsuffix cgo \
3452
-ldflags="-w -s" \
3553
-o migrate ./backend/cmd/migrate

0 commit comments

Comments
 (0)