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 <will@tailscale.com>
This commit is contained in:
Will Norris
2023-01-09 20:32:47 -08:00
committed by Will Norris
parent ef7f8b26d8
commit 3af59c51b8
+7 -2
View File
@@ -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