-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: multiarch build by moving the binaries build stage to the golang…
… image Use golang:1.23 as the builder image in the Dockerfile. With the –platform=$BUILDPLATFORM flag, the image is pulled for the builder host's current architecture. Cross-compilation occurs in the builder image using TARGETOS and TARGETARCH build arguments to determine the target OS/arch. These args are set automatically by the multiarch-build process (with docker buildx). The final container image (registry.access.redhat.com/ubi9/ubi-minimal) is pulled for the correct target architecture, such as amd64 or arm64. This update fixes support for multiarch builds and speeds up image building, as cross-compilation is faster than compiling on a non-native platform.
- Loading branch information
1 parent
546b351
commit bb3536d
Showing
4 changed files
with
20 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
FROM quay.io/centos/centos:stream9 as builder | ||
FROM --platform=$BUILDPLATFORM docker.io/golang:1.23 AS builder | ||
|
||
RUN mkdir /workdir | ||
WORKDIR /workdir | ||
# Support overriding target GOARCH during `make docker-build` | ||
ARG goarch= | ||
|
||
COPY go.mod . | ||
# these variable are automatically set during the multiarch build by docker buildx | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ENV TARGETOS=${TARGETOS:-linux} | ||
ENV TARGETARCH=${TARGETARCH:-amd64} | ||
|
||
RUN dnf install -y wget | ||
ENV GOOS=${TARGETOS} | ||
ENV GOARCH=${goarch:-$TARGETARCH} | ||
ENV CGO_ENABLED=0 | ||
ENV GOFLAGS=-mod=vendor | ||
|
||
WORKDIR /workdir | ||
RUN mkdir /workdir/bin | ||
|
||
RUN GO_VERSION=$(sed -En 's/^go +(.*)$/\1/p' go.mod) && \ | ||
wget https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \ | ||
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \ | ||
rm go${GO_VERSION}.linux-amd64.tar.gz | ||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
ENV PATH /usr/local/go/bin:$PATH | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
ENV GOOS linux | ||
# Support overriding target GOARCH during `make docker-build` | ||
ARG goarch=amd64 | ||
ENV GOARCH=$goarch | ||
ENV CGO_ENABLED 0 | ||
ENV GOFLAGS -mod=vendor | ||
|
||
RUN mkdir /workdir/bin | ||
RUN go build -tags no_openssl -o /workdir/bin/ovs ./cmd/plugin | ||
RUN go build -tags no_openssl -o /workdir/bin/marker ./cmd/marker | ||
RUN go build -tags no_openssl -o /workdir/bin/ovs-mirror-producer ./cmd/mirror-producer | ||
RUN go build -tags no_openssl -o /workdir/bin/ovs-mirror-consumer ./cmd/mirror-consumer | ||
|
||
FROM registry.access.redhat.com/ubi9/ubi-minimal | ||
|
||
RUN microdnf install -y findutils | ||
|
||
COPY --from=builder /workdir/.version /.version | ||
COPY --from=builder /workdir/bin/* / |