From 4e55d14eb91aceda6c515a33d80dbf693bcd8e03 Mon Sep 17 00:00:00 2001 From: Thiago Almeida Date: Wed, 7 May 2025 17:14:22 +0200 Subject: [PATCH] fix: enhance Dockerfile for multi-platform builds This commit improves the support building for multiple platforms Dockerfile. - Removed explicit platform from base image, using `${BUILDPLATFORM}` instead. - Added `TARGETPLATFORM`, `BUILDPLATFORM`, `TARGETOS`, and `TARGETARCH` arguments for clarity and flexibility. - Ensures consistent platform handling throughout the build process. Fixes: https://github.com/angelnu/gateway-admision-controller/issues/299 --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b3b743..081a8ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,9 @@ -FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.24@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e AS build +FROM --platform=${BUILDPLATFORM} golang:1.24@sha256:30baaea08c5d1e858329c50f29fe381e9b7d7bced11a0f5f1f69a1504cdfbf5e AS build + +ARG TARGETPLATFORM +ARG BUILDPLATFORM +ARG TARGETOS +ARG TARGETARCH WORKDIR /workspace ENV GO111MODULE=on @@ -20,7 +25,7 @@ RUN CCGO_ENABLED=0 go test -v ./... # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details # debug tag adds a shell (not recommended for prod) -FROM gcr.io/distroless/static:nonroot@sha256:c0f429e16b13e583da7e5a6ec20dd656d325d88e6819cafe0adb0828976529dc +FROM --platform=${BUILDPLATFORM} gcr.io/distroless/static:nonroot@sha256:c0f429e16b13e583da7e5a6ec20dd656d325d88e6819cafe0adb0828976529dc WORKDIR / COPY --from=build /workspace/app /app/app USER nonroot:nonroot