From 52c826cbdfffb1737e53ba3c898bfe41831850fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Gustav=20Str=C3=A5b=C3=B8?= <65334626+nilsgstrabo@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:01:55 +0100 Subject: [PATCH] build go tagret on buildplatform --- Dockerfile | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index efedfd4..22d209b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,22 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM docker.io/golang:1.22-alpine3.20 AS builder +FROM --platform=$BUILDPLATFORM docker.io/golang:1.22-alpine3.20 AS builder + +ARG TARGETARCH ENV CGO_ENABLED=0 \ - GOOS=linux + GOOS=linux \ + GOARCH=${TARGETARCH} + WORKDIR /src + +# Install project dependencies COPY go.mod go.sum ./ RUN go mod download + +# Copy and build project code COPY . . RUN go build -ldflags="-s -w" -o /build/radix-velero-plugin ./radix-velero-plugin +# Final stage FROM docker.io/alpine:3 - -RUN mkdir /plugins - COPY --from=builder /build/radix-velero-plugin /plugins/ - USER 65534 - ENTRYPOINT ["/bin/sh", "-c", "cp /plugins/* /target/."]