seperate wasm, server build

iwanhae committed Nov 16, 2025 at 22:21 UTC 3758c200fd20447cf4d79584192f8ba0e9e313de
2 files changed +38 -19
.github/workflows/cd.yml
+14 -6
@@ -12,6 +12,7 @@ on:
12 env:
13 REGISTRY: ghcr.io
14 IMAGE_NAME: ${{ github.repository }}
15 + PLATFORMS: linux/amd64,linux/arm64,linux/arm64
16
17 jobs:
18 build-and-push:
@@ -51,12 +52,20 @@ jobs:
52 type=semver,pattern={{major}}
53 type=sha,enable=true,prefix=sha-,suffix=,format=short
54
54 - - name: Build builder image
55 + - name: Build wasm-builder image
56 uses: docker/build-push-action@v6
57 with:
57 - platforms: linux/amd64,linux/arm64,linux/arm/v7
58 - target: builder
59 - context: .
58 + platforms: ${{ env.PLATFORMS }}
59 + target: wasm-builder
60 + push: false
61 + cache-from: type=gha,mode=max
62 + cache-to: type=gha,mode=max
63 +
64 + - name: Build server-builder image
65 + uses: docker/build-push-action@v6
66 + with:
67 + platforms: ${{ env.PLATFORMS }}
68 + target: server-builder
69 push: false
70 cache-from: type=gha,mode=max
71 cache-to: type=gha,mode=max
@@ -64,8 +73,7 @@ jobs:
73 - name: Build and push Docker image
74 uses: docker/build-push-action@v6
75 with:
67 - platforms: linux/amd64,linux/arm64,linux/arm/v7
68 - context: .
76 + platforms: ${{ env.PLATFORMS }}
77 push: true
78 tags: ${{ steps.meta.outputs.tags }}
79 labels: ${{ steps.meta.outputs.labels }}
Dockerfile
+24 -13
@@ -1,13 +1,24 @@
1 -# syntax=docker/dockerfile:1.7
1 +# syntax=docker/dockerfile:1
2
3 FROM --platform=$BUILDPLATFORM golang:1 AS builder
4
5 -ARG TARGETPLATFORM
6 -ARG TARGETOS
7 -ARG TARGETARCH
8 -
5 WORKDIR /src
6
7 +# Set GOMODCACHE to cache Go modules in cache volume
8 +RUN go env -w GOMODCACHE=/root/.cache/go-build
9 +
10 +# Copy go.mod and go.sum
11 +COPY go.mod go.sum ./
12 +
13 +# Download dependencies
14 +RUN --mount=type=cache,target=/go/pkg/mod \
15 + go mod download
16 +
17 +# Copy the rest of the source code
18 +COPY . .
19 +
20 +FROM --platform=$BUILDPLATFORM builder AS wasm-builder
21 +
22 # Install make, binaryen (wasm-opt), and brotli CLI for WASM build/compression
23 RUN apt-get update && apt-get install -y --no-install-recommends \
24 binaryen \
@@ -15,16 +26,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
26 make \
27 && rm -rf /var/lib/apt/lists/*
28
18 -# Set GOMODCACHE to cache Go modules in cache volume
19 -RUN go env -w GOMODCACHE=/root/.cache/go-build
20 -
21 -# Copy the rest of the source code
22 -COPY . .
23 -
29 RUN --mount=type=cache,target=/go/pkg/mod \
30 --mount=type=cache,target=/root/.cache/go-build \
31 make build-wasm compress-wasm
32
33 +FROM --platform=$BUILDPLATFORM builder AS server-builder
34 +
35 +ARG TARGETPLATFORM
36 +ARG TARGETOS
37 +ARG TARGETARCH
38 +
39 RUN --mount=type=cache,target=/go/pkg/mod \
40 --mount=type=cache,target=/root/.cache/go-build \
41 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build-server
@@ -32,10 +43,10 @@ RUN --mount=type=cache,target=/go/pkg/mod \
43 FROM gcr.io/distroless/static-debian12:nonroot
44
45 # Copy server binary
35 -COPY --from=builder /src/bin/relay-server /usr/bin/relay-server
46 +COPY --from=server-builder /src/bin/relay-server /usr/bin/relay-server
47
48 # Copy static files for portal frontend
38 -COPY --from=builder /src/dist /app/dist
49 +COPY --from=wasm-builder /src/dist /app/dist
50
51 # Set default environment variables
52 ENV STATIC_DIR=/app/dist