-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify Dockerfile to support multi-platform builds.
These changes enable building kubemacpool container images for multiple platforms (amd64, s390x, arm64) from a single Dockerfile. Signed-off-by: Ashok Pariya ashok.pariya@ibm.com
- Loading branch information
1 parent
38a92a2
commit cacc9f7
Showing
1 changed file
with
29 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
ARG BUILD_ARCH=amd64 | ||
FROM --platform=linux/${BUILD_ARCH} quay.io/centos/centos:stream9 AS builder | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ENV TARGETOS=${TARGETOS:-linux} | ||
ENV TARGETARCH=${TARGETARCH:-amd64} | ||
|
||
ARG BUILDOS | ||
ARG BUILDARCH | ||
ENV BUILDOS=${BUILDOS:-linux} | ||
ENV BUILDARCH=${BUILDARCH:-amd64} | ||
|
||
WORKDIR /go/src/kubemacpool | ||
RUN dnf install -y wget && dnf clean all | ||
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}.${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=$PATH:/usr/local/go/bin | ||
RUN go mod download | ||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o build/_output/bin/manager github.com/k8snetworkplumbingwg/kubemacpool/cmd/manager | ||
|
||
# Copy the controller-manager into a thin image | ||
FROM registry.access.redhat.com/ubi9/ubi-minimal | ||
COPY _output/bin/manager / | ||
FROM --platform=linux/${TARGETARCH} registry.access.redhat.com/ubi9/ubi-minimal | ||
COPY --from=builder /go/src/kubemacpool/build/_output/bin/manager / | ||
ENTRYPOINT ["/manager"] |