From 3af59c51b849a19a01a47fe8bbad33dc16374201 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 9 Jan 2023 17:01:46 -0800 Subject: [PATCH] Dockerfile: cross compile images using native builder Use a build image built for the native architecture so that it doesn't run in emulation mode. Switch to Chainguard's wolfi/glibc build image. This limits our build architectures to just amd64 and arm64, but that is sufficient for our needs. Updates #42 Updates #43 Signed-off-by: Will Norris --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 71a7fd9..2b1a059 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM cgr.dev/chainguard/go:1.19-musl as build +FROM --platform=$BUILDPLATFORM cgr.dev/chainguard/go:1.19 as build WORKDIR /work @@ -6,7 +6,12 @@ COPY go.mod go.sum ./ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -v ./cmd/golink +ARG TARGETOS TARGETARCH TARGETVARIANT +RUN \ + if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \ + export GOARM="${TARGETVARIANT#v}"; \ + fi; \ + GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -v ./cmd/golink FROM cgr.dev/chainguard/static:latest