Skip to content

Commit f6821d9

Browse files
committed
Optimize multi-arch docker image build
1 parent 0012443 commit f6821d9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.25.8-trixie AS builder
2+
FROM --platform=$BUILDPLATFORM golang:1.25.8-trixie as builder
33

44
WORKDIR /workspace/api
55
COPY api/ .
@@ -20,11 +20,13 @@ COPY controllers/ controllers/
2020
COPY utils/ utils/
2121

2222
# Build
23-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
23+
ARG TARGETOS
24+
ARG TARGETARCH
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on go build -a -o manager main.go
2426

2527
# Use distroless as minimal base image to package the manager binary
2628
# Refer to https://github.com/GoogleContainerTools/distroless for more details
27-
FROM gcr.io/distroless/static:nonroot
29+
FROM --platform=$TARGETPLATFORM gcr.io/distroless/static:nonroot
2830
WORKDIR /
2931
COPY --from=builder /workspace/manager .
3032
USER 65532:65532

operator.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.21
1+
FROM --platform=$TARGETPLATFORM alpine:3.21
22

33
ENV GID=10001
44
ENV UID=10000

redhat.Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.25.8-trixie as builder
2+
FROM --platform=$BUILDPLATFORM golang:1.25.8-trixie AS builder
33

44
WORKDIR /workspace/api
55
COPY api/ .
@@ -20,12 +20,14 @@ COPY controllers/ controllers/
2020
COPY utils/ utils/
2121

2222
# Build
23-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
23+
ARG TARGETOS
24+
ARG TARGETARCH
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} GO111MODULE=on go build -a -o manager main.go
2426

2527
# Use ubi image as the base image which is required by the red hat certification.
2628
# Base on the image size, the order is ubi > ubi-minimal > ubi-micro.
2729
# https://access.redhat.com/documentation/en-us/red_hat_software_certification/8.45/html/red_hat_openshift_software_certification_policy_guide/assembly-requirements-for-container-images_openshift-sw-cert-policy-introduction#con-image-metadata-requirements_openshift-sw-cert-policy-container-images
28-
FROM registry.access.redhat.com/ubi8/ubi-micro:latest
30+
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi8/ubi-micro:latest
2931

3032
ARG VERSION
3133

0 commit comments

Comments
 (0)