From 4e9b372d2c130ca292cb53bd4eab5fcf3b3ea539 Mon Sep 17 00:00:00 2001 From: Roberto Bonafiglia Date: Tue, 23 Apr 2024 16:37:31 +0200 Subject: [PATCH] Updated Dockerfile for arm64 build Signed-off-by: Roberto Bonafiglia --- Dockerfile | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 536e39f..f0bd1c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ ARG BCI_IMAGE=registry.suse.com/bci/bci-base ARG GO_IMAGE=rancher/hardened-build-base:v1.21.9b1 -FROM ${BCI_IMAGE} as bci -FROM ${GO_IMAGE} as builder +FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx +FROM --platform=$TARGETPLATFORM ${BCI_IMAGE} as bci +FROM --platform=$TARGETPLATFORM ${GO_IMAGE} as builder # setup required packages +COPY --from=xx / / +ARG TARGETPLATFORM +ARG BUILDPLATFORM RUN set -x && \ apk --no-cache add \ file \ @@ -11,9 +15,11 @@ RUN set -x && \ linux-headers \ make # setup the build -ARG ARCH="amd64" ARG K3S_ROOT_VERSION=v0.13.0 -ADD https://github.com/rancher/k3s-root/releases/download/${K3S_ROOT_VERSION}/k3s-root-xtables-${ARCH}.tar /opt/xtables/k3s-root-xtables.tar +RUN xx-info env +RUN mkdir -p /opt/xtables/ +RUN export ARCH=$(xx-info arch) &&\ + wget https://github.com/rancher/k3s-root/releases/download/${K3S_ROOT_VERSION}/k3s-root-xtables-${ARCH}.tar -O /opt/xtables/k3s-root-xtables.tar RUN tar xvf /opt/xtables/k3s-root-xtables.tar -C /opt/xtables ARG TAG=v0.25.1 ARG PKG="github.com/flannel-io/flannel" @@ -24,9 +30,15 @@ RUN git fetch --all --tags --prune RUN git checkout tags/${TAG} -b ${TAG} # build and assert statically linked executable(s) ENV GO_LDFLAGS="-X ${PKG}/version.Version=${TAG}" -RUN go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/flanneld . -RUN go-assert-static.sh bin/* -RUN if [ "${ARCH}" = "amd64" ]; then \ +RUN export GOOS=$(xx-info os) &&\ + export GOARCH=$(xx-info arch) &&\ + export ARCH=$(xx-info arch) &&\ + go-build-static.sh -gcflags=-trimpath=${GOPATH}/src -o bin/flanneld . +RUN export GOOS=$(xx-info os) &&\ + export GOARCH=$(xx-info arch) &&\ + export ARCH=$(xx-info arch) &&\ + go-assert-static.sh bin/* +RUN if [ "$(xx-info arch)" = "amd64" ]; then \ go-assert-boring.sh bin/* ; \ fi RUN install -s bin/* /usr/local/bin