-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: multiarch build by using crosscompilation #336
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
FROM quay.io/centos/centos:stream9 as builder | ||
FROM --platform=$BUILDPLATFORM quay.io/centos/centos:stream9 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} | ||
|
||
ARG BUILDOS | ||
ARG BUILDARCH | ||
ENV BUILDOS=${BUILDOS:-linux} | ||
ENV BUILDARCH=${BUILDARCH:-amd64} | ||
|
||
ENV GOOS=${TARGETOS} | ||
ENV GOARCH=${goarch:-$TARGETARCH} | ||
ENV CGO_ENABLED=0 | ||
ENV GOFLAGS=-mod=vendor | ||
|
||
WORKDIR /workdir | ||
|
||
RUN dnf install -y wget | ||
|
||
COPY go.mod . | ||
COPY go.sum . | ||
|
||
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 | ||
wget https://dl.google.com/go/go${GO_VERSION}.${BUILDOS}-${BUILDARCH}.tar.gz && \ | ||
tar -C /usr/local -xzf go${GO_VERSION}.${BUILDOS}-${BUILDARCH}.tar.gz && \ | ||
rm go${GO_VERSION}.${BUILDOS}-${BUILDARCH}.tar.gz | ||
|
||
ENV PATH /usr/local/go/bin:$PATH | ||
ENV PATH=/usr/local/go/bin:$PATH | ||
|
||
COPY . . | ||
RUN go mod download | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious, why we need this suddenly ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. First, we 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 | ||
COPY . . | ||
|
||
RUN mkdir /workdir/bin | ||
RUN go build -tags no_openssl -o /workdir/bin/ovs ./cmd/plugin | ||
|
@@ -30,6 +45,8 @@ RUN go build -tags no_openssl -o /workdir/bin/ovs-mirror-producer ./cmd/mirror-p | |
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/* / |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to set this anymore. Default for the goarch= build-arg is empty string.