Skip to content

Commit 3af59c5

Browse files
committed
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 <[email protected]>
1 parent ef7f8b2 commit 3af59c5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
FROM cgr.dev/chainguard/go:1.19-musl as build
1+
FROM --platform=$BUILDPLATFORM cgr.dev/chainguard/go:1.19 as build
22

33
WORKDIR /work
44

55
COPY go.mod go.sum ./
66
RUN go mod download
77

88
COPY . .
9-
RUN CGO_ENABLED=0 GOOS=linux go build -v ./cmd/golink
9+
ARG TARGETOS TARGETARCH TARGETVARIANT
10+
RUN \
11+
if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \
12+
export GOARM="${TARGETVARIANT#v}"; \
13+
fi; \
14+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -v ./cmd/golink
1015

1116

1217
FROM cgr.dev/chainguard/static:latest

0 commit comments

Comments
 (0)