From 8e4f335bd5f6446329269a57996e7e710f155333 Mon Sep 17 00:00:00 2001 From: Robert Moucha Date: Sat, 4 Jan 2025 18:59:52 +0100 Subject: [PATCH] Platform-agnostic Dockerfile As this project doesn't provide container images for other platforms than linux/amd64, we can make docker image build easier for those using arm64 or other platforms. Building for other platforms will be as simple as: docker build -t myimage https://github.com/ns1/cert-manager-webhook-ns1.git --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 55fb636..45dc5f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.4-alpine AS build_deps +FROM --platform=$BUILDPLATFORM golang:1.20.4-alpine AS build_deps RUN apk add --no-cache git @@ -10,10 +10,12 @@ COPY go.sum . RUN go mod download FROM build_deps AS build +ARG TARGETOS +ARG TARGETARCH COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o webhook -ldflags '-w -extldflags "-static"' . +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook -ldflags '-w -extldflags "-static"' . FROM alpine:3.18