From b1bbac815389c32c30121fa70b3ac42bd3c9e819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C4=81ris=20Pop=C4=93ns?= Date: Tue, 10 Nov 2026 12:38:55 +0200 Subject: [PATCH] build: multi-arch (amd64, arm64) image via native cross-compile --- .github/workflows/ci.yml | 3 +++ .github/workflows/publish.yml | 4 ++-- Dockerfile | 9 ++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de6a36a..14c45f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,9 @@ jobs: context: . file: Dockerfile push: false + platforms: linux/amd64,linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max zizmor: uses: drumandbytes/reusable-actions/.github/workflows/zizmor.yml@v1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 26505bb..5d934a5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,8 +21,8 @@ jobs: artifact-metadata: write # storage record for the pushed image uses: drumandbytes/reusable-actions/.github/workflows/docker-publish.yml@v1 with: - # The cluster runs amd64 only. - platforms: linux/amd64 + # Go cross-compiles on the native runner (Dockerfile uses $BUILDPLATFORM), so no QEMU. + platforms: linux/amd64,linux/arm64 tags: | type=semver,pattern={{version}} type=raw,value=latest diff --git a/Dockerfile b/Dockerfile index 7ac9366..3681b7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ -FROM golang:1.26-alpine AS builder +FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder +ARG TARGETOS +ARG TARGETARCH RUN apk add --no-cache ca-certificates WORKDIR /build COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o paddock-api . +RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags="-s -w" -o paddock-api . RUN mkdir /data # scratch has no CA bundle or zoneinfo: CAs copied below, tzdata embedded (main.go).