From 6b2b10964648a4193df49d200ddcf0ea6c2df2d7 Mon Sep 17 00:00:00 2001 From: Andras Katona <41361962+akatona84@users.noreply.github.com> Date: Tue, 10 Oct 2023 18:16:13 +0200 Subject: [PATCH] add: multiarch docker image build (#1059) --- .github/workflows/docker.yml | 2 +- Dockerfile | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4c2b9d2d0..395566a1d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,7 +9,7 @@ on: - "v?[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" # pull_request: env: - PLATFORMS: linux/amd64 + PLATFORMS: linux/amd64,linux/arm64 jobs: docker: name: Docker diff --git a/Dockerfile b/Dockerfile index c74d9e1b0..63523f4f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,11 @@ # Build the manager binary -FROM golang:1.19 as builder +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.19 as builder + +ARG BUILDPLATFORM +ARG TARGETPLATFORM +ARG TARGETOS +ARG TARGETARCH +RUN echo "BUILDPLATFORM: ${BUILDPLATFORM}, TARGETPLATFORM: ${TARGETPLATFORM}, TARGETOS: ${TARGETOS}, TARGETARCH: ${TARGETARCH}" WORKDIR /workspace # Copy the Go Modules manifests @@ -18,11 +24,11 @@ COPY internal/ internal/ COPY pkg/ pkg/ # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on go build -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static-debian11:nonroot +FROM --platform=${TARGETPLATFORM:-linux/amd64} gcr.io/distroless/static-debian11:nonroot WORKDIR / COPY --from=builder /workspace/manager . ENTRYPOINT ["/manager"]