Skip to content

Commit

Permalink
Accelerate ARM64 build
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Buil <[email protected]>
  • Loading branch information
manuelbuil committed Apr 9, 2024
1 parent f3b1e6b commit 1d49b06
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
ARG GO_IMAGE=rancher/hardened-build-base:v1.20.14b1

#FROM ${BCI_IMAGE} as bci
FROM ${GO_IMAGE} as base

# Image that provides cross compilation tooling.
FROM --platform=$BUILDPLATFORM rancher/mirrored-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 set -x && \
apk --no-cache add \
git \
make
apk --no-cache add file make git clang lld
RUN xx-apk --no-cache musl-dev gcc lld
ARG TARGETPLATFORM

FROM base as builder
FROM --platform=$BUILDPLATFORM base-builder
ARG ARCH
ARG SRC=github.com/kubernetes/autoscaler
ARG PKG=github.com/kubernetes/autoscaler
Expand All @@ -18,15 +21,25 @@ ARG TAG=1.8.20
WORKDIR $GOPATH/src/${PKG}/addon-resizer
RUN git branch -a
RUN git checkout addon-resizer-${TAG} -b ${TAG}
RUN ls
RUN GOARCH=${ARCH} GO_LDFLAGS="-linkmode=external -X ${PKG}/pkg/version.VERSION=${TAG}" \
RUN go mod download

# cross-compilation setup
ARG TARGETPLATFORM
RUN xx-go --wrapp && \
GOARCH=${ARCH} GO_LDFLAGS="-linkmode=external -X ${PKG}/pkg/version.VERSION=${TAG}" \
go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o pod_nanny nanny/main/pod_nanny.go
RUN go-assert-static.sh pod_nanny
RUN xx-verify --static pod_nanny
RUN if [ "${ARCH}" = "amd64" ]; then \
go-assert-boring.sh pod_nanny; \
fi
RUN install -s pod_nanny /usr/local/bin
RUN install pod_nanny /usr/local/bin

FROM ${GO_IMAGE} as strip_binary
#strip needs to run on TARGETPLATFORM, not BUILDPLATFORM
COPY --from=base-builder /usr/local/bin/pod_nanny
RUN strip /pod_nanny

FROM scratch
COPY --from=builder /usr/local/bin/pod_nanny /pod_nanny
COPY --from=strip_binary /pod_nanny /pod_nanny
ENTRYPOINT ["/pod_nanny"]

0 comments on commit 1d49b06

Please sign in to comment.