Skip to content

Commit 7ca50bc

Browse files
Stefan ErnstStefan Ernst
authored andcommitted
split frontend build from multiarch build workflow
1 parent 6e97200 commit 7ca50bc

1 file changed

Lines changed: 27 additions & 17 deletions

File tree

Dockerfile

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
# Multi-stage build for Windshift server
2-
# Stage 1: Build the application
2+
3+
# Stage 1: Build frontend on HOST platform (no QEMU emulation needed)
4+
# Using --platform=$BUILDPLATFORM ensures this runs natively on x86-64
5+
# which avoids QEMU issues with native Node.js binaries (esbuild, rollup, etc.)
6+
FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend-builder
7+
8+
WORKDIR /build
9+
10+
# Copy package files first for better layer caching
11+
COPY frontend/package*.json ./
12+
13+
# Install dependencies (npm ci is faster and more reliable for CI)
14+
RUN npm ci
15+
16+
# Copy frontend source and build
17+
COPY frontend/ ./
18+
RUN npm run build
19+
20+
# Stage 2: Build Go binary (target platform, uses QEMU for arm64)
321
FROM golang:1.24.6-alpine AS builder
422

5-
# Install build dependencies
6-
RUN apk add --no-cache gcc musl-dev nodejs npm git tzdata
23+
# Install build dependencies (nodejs/npm no longer needed)
24+
RUN apk add --no-cache gcc musl-dev git tzdata
725

826
# Set working directory
927
WORKDIR /build
@@ -14,24 +32,16 @@ COPY go.mod go.sum ./
1432
# Copy source code
1533
COPY . .
1634

17-
# Build frontend - clean install with explicit platform targeting
18-
WORKDIR /build/frontend
19-
ARG TARGETPLATFORM
20-
ARG TARGETARCH
21-
RUN rm -rf node_modules package-lock.json && \
22-
npm config set target_arch ${TARGETARCH:-x64} && \
23-
npm config set target_platform linux && \
24-
npm install --force --ignore-scripts && \
25-
npm rebuild && \
26-
npm run build
27-
28-
# Build backend with static linking (native architecture)
29-
WORKDIR /build
35+
# Copy pre-built frontend from frontend-builder stage
36+
# Static files (JS/CSS/HTML) are architecture-independent
37+
COPY --from=frontend-builder /build/dist ./frontend/dist
38+
39+
# Build backend with static linking
3040
RUN CGO_ENABLED=1 \
3141
go build -ldflags '-s -w -linkmode external -extldflags "-static"' \
3242
-o windshift main.go
3343

34-
# Stage 2: Scratch runtime (minimal image)
44+
# Stage 3: Scratch runtime (minimal image)
3545
FROM scratch
3646

3747
# Copy CA certificates for HTTPS requests

0 commit comments

Comments
 (0)