Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accelerate ARM64 build #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 add musl-dev gcc lld
ARG TARGETPLATFORM

FROM base as builder
FROM --platform=$BUILDPLATFORM base-builder as addon-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 --wrap && \
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=addon-builder /usr/local/bin/pod_nanny /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"]
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ endif
image-build:
docker build \
--pull \
--platform=$(ARCH) \
--build-arg ARCH=$(ARCH) \
--build-arg PKG=$(PKG) \
--build-arg SRC=$(SRC) \
Expand Down
Loading