support multi platform build
iwanhae committed
Nov 16, 2025 at 22:00 UTC
6c002798b5409b08f5155a28963ad100638fd8b2
2 files changed
+21
-21
.github/workflows/cd.yml
+2
-5
@@ -51,9 +51,6 @@ jobs:
51
type=semver,pattern={{major}}
52
type=sha,enable=true,prefix=sha-,suffix=,format=short
53
54
- - name: Pre-build WASM artifacts
55
- run: make build-wasm compress-wasm
56
-
54
- name: Build and push Docker image
55
uses: docker/build-push-action@v6
56
with:
@@ -62,6 +59,8 @@ jobs:
59
push: true
60
tags: ${{ steps.meta.outputs.tags }}
61
labels: ${{ steps.meta.outputs.labels }}
62
+ cache-from: type=gha,mode=max
63
+ cache-to: type=gha,mode=max
64
deploy:
65
name: Deploy
66
runs-on: ubuntu-latest
@@ -72,8 +71,6 @@ jobs:
71
uses: actions/checkout@v5
72
73
- uses: azure/setup-kubectl@v4
75
- with:
76
- version: "1.33"
74
75
- name: Prepare Kubernetes context
76
run: |
Dockerfile
+19
-16
@@ -1,30 +1,33 @@
1
-FROM golang:1 AS builder
1
+# syntax=docker/dockerfile:1.7
2
+
3
+FROM --platform=$BUILDPLATFORM golang:1 AS builder
4
+
5
+ARG TARGETPLATFORM
6
+ARG TARGETOS
7
+ARG TARGETARCH
8
9
WORKDIR /src
10
11
# Install make, binaryen (wasm-opt), and brotli CLI for WASM build/compression
12
RUN apt-get update && apt-get install -y --no-install-recommends \
7
- binaryen \
8
- brotli \
9
- make \
13
+ binaryen \
14
+ brotli \
15
+ make \
16
&& rm -rf /var/lib/apt/lists/*
17
12
-COPY go.mod go.sum ./
13
-
14
-# Download dependencies
15
-RUN go mod download
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
20
-# Build WASM (if needed), precompress, and server
21
-RUN if ls dist/[0-9a-f]*.wasm.br >/dev/null 2>&1; then \
22
- echo "[docker] Using prebuilt WASM artifacts in dist/"; \
23
- else \
24
- echo "[docker] No prebuilt WASM found; running make build-wasm compress-wasm"; \
25
- make build-wasm compress-wasm; \
26
- fi && \
27
- make build-server
24
+RUN --mount=type=cache,target=/go/pkg/mod \
25
+ --mount=type=cache,target=/root/.cache/go-build \
26
+ make build-wasm compress-wasm
27
+
28
+RUN --mount=type=cache,target=/go/pkg/mod \
29
+ --mount=type=cache,target=/root/.cache/go-build \
30
+ GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build-server
31
32
FROM gcr.io/distroless/static-debian12:nonroot
33