Skip to content

Commit

Permalink
Merge pull request #40 from thomasferrandiz/remove-arch
Browse files Browse the repository at this point in the history
Use cross-compilation and remove all references to ARCH
  • Loading branch information
thomasferrandiz authored Jun 13, 2024
2 parents 54df5ae + 0cc5002 commit 472adf6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
34 changes: 27 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,51 @@ ARG BCI_IMAGE=registry.suse.com/bci/bci-busybox
ARG GO_IMAGE=rancher/hardened-build-base:v1.21.11b2
FROM ${BCI_IMAGE} as bci

FROM ${GO_IMAGE} as builder
ARG ARCH="amd64"
# Image that provides cross compilation tooling.
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.3.0 AS xx

FROM --platform=$BUILDPLATFORM ${GO_IMAGE} as base-builder
# copy xx scripts to your build stage
COPY --from=xx / /
RUN apk add file make git clang lld
ARG TARGETPLATFORM
RUN set -x && \
xx-apk --no-cache add musl-dev gcc

FROM base-builder as whereabouts-builder
ARG TAG=v0.7.0
ARG PKG="github.com/k8snetworkplumbingwg/whereabouts"
ARG SRC="github.com/k8snetworkplumbingwg/whereabouts"
RUN git clone --depth=1 https://${SRC}.git $GOPATH/src/${PKG}
WORKDIR $GOPATH/src/${PKG}
RUN git fetch --all --tags --prune
RUN git checkout tags/${TAG} -b ${TAG}
RUN go mod download
# cross-compilation setup
ARG TARGETARCH

ENV GO111MODULE=on
RUN GIT_SHA=$(git rev-parse --short HEAD) \
GIT_TREE_STATE=$(test -n "`git status --porcelain --untracked-files=no`" && echo "dirty" || echo "clean") && \
export GO_LDFLAGS="-X ${PKG}/pkg/version.Version=${TAG} \
-X ${PKG}/pkg/version.GitSHA=${GIT_SHA} \
-X ${PKG}/pkg/version.GitTreeState=${GIT_TREE_STATE}" && \
xx-go --wrap && \
go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -mod vendor -o bin/whereabouts cmd/whereabouts.go && \
go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -mod vendor -o bin/ip-control-loop cmd/controlloop/*.go
RUN go-assert-boring.sh bin/*
RUN install -s bin/* /usr/local/bin
RUN whereabouts --version
RUN xx-verify --static bin/*
RUN install bin/* /usr/local/bin

FROM ${GO_IMAGE} as strip_binary
#strip needs to run on TARGETPLATFORM, not BUILDPLATFORM
COPY --from=whereabouts-builder /usr/local/bin/whereabouts .
COPY --from=whereabouts-builder /usr/local/bin/ip-control-loop .
RUN strip ./whereabouts ./ip-control-loop

FROM bci
COPY --from=builder /usr/local/bin/whereabouts .
COPY --from=builder /usr/local/bin/ip-control-loop .
COPY --from=strip_binary /go/whereabouts .
COPY --from=strip_binary /go/ip-control-loop .
ARG PKG="github.com/k8snetworkplumbingwg/whereabouts"
COPY --from=builder /go/src/${PKG}/script/install-cni.sh .
COPY --from=whereabouts-builder /go/src/${PKG}/script/install-cni.sh .
CMD ["/install-cni.sh"]
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ image-build:
docker buildx build \
--platform=$(ARCH) \
--pull \
--build-arg ARCH=$(ARCH) \
--build-arg PKG=$(PKG) \
--build-arg SRC=$(SRC) \
--build-arg TAG=$(TAG:$(BUILD_META)=) \
Expand Down

0 comments on commit 472adf6

Please sign in to comment.