Skip to content

Commit

Permalink
Use cross-compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasferrandiz committed May 13, 2024
1 parent f9bfcec commit 9218ca4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
42 changes: 30 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,69 @@ ARG BCI_IMAGE=registry.suse.com/bci/bci-base
ARG HARDENED_IMAGE=rancher/hardened-build-base:${GOBORING_VERSION}
ARG ARCH

FROM ${HARDENED_IMAGE} as base
# Image that provides cross compilation tooling.
FROM --platform=$BUILDPLATFORM rancher/mirrored-tonistiigi-xx:1.3.0 as xx


FROM --platform=$BUILDPLATFORM ${HARDENED_IMAGE} as base
ARG TAG
ARG BUILD
ENV VERSION_OVERRIDE=${TAG}${BUILD}
RUN git clone https://github.com/k8snetworkplumbingwg/sriov-network-operator && \
cd sriov-network-operator && \
git checkout ${COMMIT} && \
make clean
# copy xx scripts to your build stage
COPY --from=xx / /
RUN apk add file make git clang lld
ARG TARGETPLATFORM
# setup required packages
RUN set -x && \
xx-apk --no-cache add musl-dev gcc lld

FROM base as builder
ENV CGO_ENABLED=0
ARG TAG
ARG BUILD
ENV VERSION_OVERRIDE=${TAG}${BUILD}
ENV GOFLAGS=-trimpath
RUN cd sriov-network-operator && \
RUN git clone https://github.com/k8snetworkplumbingwg/sriov-network-operator && \
cd sriov-network-operator && \
git checkout ${COMMIT} && \
make clean && \
go mod download

# cross-compilation setup
ARG TARGETPLATFORM
RUN export GOOS=$(xx-info os) &&\
export GOARCH=$(xx-info arch) &&\
export ARCH=$(xx-info arch) &&\
cd sriov-network-operator && \
make _build-manager && \
make _build-webhook && \
make _build-sriov-network-config-daemon
RUN mv /go/sriov-network-operator/build/_output/linux/$(xx-info arch)/sriov-network-config-daemon /usr/bin/ && \
mv /go/sriov-network-operator/build/_output/linux/$(xx-info arch)/webhook /usr/bin/webhook && \
mv /go/sriov-network-operator/build/_output/linux/$(xx-info arch)/manager /usr/bin/sriov-network-operator

# Create the config daemon image
FROM ${BCI_IMAGE} as config-daemon
ARG ARCH
WORKDIR /
COPY centos.repo /etc/yum.repos.d/centos.repo
RUN zypper update -y && \
ARCH_DEP_PKGS=$(if [ "$(uname -m)" != "s390x" ]; then echo -n mstflint ; fi) && \
zypper install -y hwdata $ARCH_DEP_PKGS
COPY --from=builder /go/sriov-network-operator/build/_output/linux/${ARCH}/sriov-network-config-daemon /usr/bin/
COPY --from=builder /usr/bin/sriov-network-config-daemon /usr/bin/
COPY --from=builder /go/sriov-network-operator/bindata /bindata
ENTRYPOINT ["/usr/bin/sriov-network-config-daemon"]

# Create the webhook image
FROM ${BCI_IMAGE} as webhook
ARG ARCH
WORKDIR /
LABEL io.k8s.display-name="sriov-network-webhook" \
io.k8s.description="This is an admission controller webhook that mutates and validates customer resources of sriov network operator."
COPY --from=builder /go/sriov-network-operator/build/_output/linux/${ARCH}/webhook /usr/bin/webhook
COPY --from=builder /usr/bin/webhook /usr/bin/webhook
CMD ["/usr/bin/webhook"]

# Create the operator image
FROM ${BCI_IMAGE} as operator
ARG ARCH
WORKDIR /
COPY --from=builder /go/sriov-network-operator/build/_output/linux/${ARCH}/manager /usr/bin/sriov-network-operator
COPY --from=builder /usr/bin/sriov-network-operator /usr/bin/sriov-network-operator
COPY --from=builder /go/sriov-network-operator/bindata /bindata
ENTRYPOINT ["/usr/bin/sriov-network-operator"]
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ image-build-operator:
--load \
--platform=$(ARCH) \
--pull \
--build-arg ARCH=$(ARCH) \
--build-arg TAG=$(TAG:$(BUILD_META)=) \
--build-arg BUILD=$(BUILD_META) \
--target operator \
Expand All @@ -50,7 +49,6 @@ image-build-network-config-daemon:
docker buildx build \
--pull \
--platform=$(ARCH) \
--build-arg ARCH=$(ARCH) \
--build-arg TAG=$(TAG:$(BUILD_META)=) \
--build-arg BUILD=$(BUILD_META) \
--target config-daemon \
Expand All @@ -71,7 +69,6 @@ image-build-sriov-network-webhook:
docker buildx build \
--pull \
--platform=$(ARCH) \
--build-arg ARCH=$(ARCH) \
--build-arg TAG=$(TAG:$(BUILD_META)=) \
--build-arg BUILD=$(BUILD_META) \
--target webhook \
Expand Down

0 comments on commit 9218ca4

Please sign in to comment.