|
1 |
| -ARG ARCH="amd64" |
2 | 1 | ARG GO_IMAGE=rancher/hardened-build-base:v1.21.10b1
|
3 | 2 |
|
4 |
| -# Build the multus project |
5 |
| -FROM ${GO_IMAGE} as builder |
| 3 | +# Image that provides cross compilation tooling. |
| 4 | +FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.3.0 AS xx |
| 5 | + |
| 6 | +FROM --platform=$BUILDPLATFORM ${GO_IMAGE} as base-builder |
| 7 | +# copy xx scripts to your build stage |
| 8 | +COPY --from=xx / / |
| 9 | +RUN apk add file make git clang lld patch |
| 10 | +ARG TARGETPLATFORM |
6 | 11 | RUN set -x && \
|
7 |
| - apk --no-cache add patch |
8 |
| -ARG ARCH |
| 12 | + xx-apk --no-cache add musl-dev gcc lld |
| 13 | + |
| 14 | +# Build the multus project |
| 15 | +FROM base-builder as multus-builder |
9 | 16 | ARG TAG=v4.0.2
|
10 |
| -ENV GOARCH ${ARCH} |
11 |
| -ENV GOOS "linux" |
| 17 | +ARG SRC=github.com/k8snetworkplumbingwg/multus-cni |
| 18 | +ARG PKG=github.com/k8snetworkplumbingwg/multus-cni |
| 19 | +RUN git clone --depth=1 https://${SRC}.git $GOPATH/src/${PKG} |
| 20 | +WORKDIR $GOPATH/src/${PKG} |
12 | 21 | # patch to solve https://github.com/rancher/rke2/issues/4568
|
13 | 22 | # to be removed once upstream merges the fix
|
14 | 23 | # https://github.com/k8snetworkplumbingwg/multus-cni/pull/1137
|
15 | 24 | COPY self_delegation_bug.patch /tmp
|
16 |
| -RUN git clone --depth=1 https://github.com/k8snetworkplumbingwg/multus-cni && \ |
17 |
| - cd multus-cni && \ |
18 |
| - git fetch --all --tags --prune && \ |
| 25 | + |
| 26 | +RUN git fetch --all --tags --prune && \ |
19 | 27 | git checkout tags/${TAG} -b ${TAG} && \
|
20 |
| - git apply /tmp/self_delegation_bug.patch && \ |
| 28 | + git apply /tmp/self_delegation_bug.patch |
| 29 | +RUN go mod download |
| 30 | +# cross-compilation setup |
| 31 | +ARG TARGETARCH |
| 32 | + |
| 33 | +RUN xx-go --wrap && \ |
21 | 34 | ./hack/build-go.sh
|
| 35 | +RUN xx-verify --static bin/thin_entrypoint bin/multus |
| 36 | + |
| 37 | +FROM ${GO_IMAGE} as strip_binary |
| 38 | +#strip needs to run on TARGETPLATFORM, not BUILDPLATFORM |
| 39 | +COPY --from=multus-builder /go/src/github.com/k8snetworkplumbingwg/multus-cni/bin/thin_entrypoint /thin_entrypoint |
| 40 | +COPY --from=multus-builder /go/src/github.com/k8snetworkplumbingwg/multus-cni/bin/multus /multus |
| 41 | +RUN strip /thin_entrypoint /multus |
22 | 42 |
|
23 | 43 | # Create the multus image
|
24 | 44 | FROM scratch as multus-cni
|
25 |
| -COPY --from=builder /go/multus-cni/bin/multus /usr/src/multus-cni/bin/multus |
26 |
| -COPY --from=builder /go/multus-cni/LICENSE /usr/src/multus-cni/LICENSE |
27 |
| -COPY --from=builder /go/multus-cni/bin/thin_entrypoint / |
| 45 | +COPY --from=strip_binary /multus /usr/src/multus-cni/bin/multus |
| 46 | +COPY --from=multus-builder /go/src/github.com/k8snetworkplumbingwg/multus-cni/LICENSE /usr/src/multus-cni/LICENSE |
| 47 | +COPY --from=strip_binary /thin_entrypoint / |
28 | 48 | ENTRYPOINT ["/thin_entrypoint"]
|
0 commit comments