Cross compile Docker image targets
All checks were successful
Publish / Test, build, and push image (push) Successful in 4m10s

This commit is contained in:
V 2026-05-16 22:37:08 +01:00
parent fc736aa06e
commit d4441cda67

View File

@ -1,14 +1,28 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
FROM golang:1.24-bookworm AS build ARG BUILDPLATFORM
FROM --platform=$BUILDPLATFORM golang:1.24-bookworm AS build
WORKDIR /src WORKDIR /src
ARG TARGETARCH
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
&& rm -rf /var/lib/apt/lists/*
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . . COPY . .
RUN CGO_ENABLED=1 GOOS=linux go build -o /out/archi-folio ./cmd/server RUN targetarch="${TARGETARCH:-amd64}" \
&& echo "building for TARGETARCH=${targetarch}" \
&& case "$targetarch" in \
amd64) export CC=gcc ;; \
arm64) export CC=aarch64-linux-gnu-gcc ;; \
*) echo "unsupported TARGETARCH=${targetarch}" >&2; exit 1 ;; \
esac \
&& CGO_ENABLED=1 GOOS=linux GOARCH="$targetarch" go build -o /out/archi-folio ./cmd/server
FROM gcr.io/distroless/cc-debian12:nonroot FROM gcr.io/distroless/cc-debian12:nonroot