From a8cec62e0c232ee34bf7761856b100af397d7a7d Mon Sep 17 00:00:00 2001 From: Michal Gubricky Date: Thu, 26 Sep 2024 08:20:47 +0200 Subject: [PATCH] Add multi-arch support for amd64 and arm64 into Dockerfile (#758) * Add multi-arch support for amd64 and arm64 into Dockerfile Signed-off-by: michal.gubricky * Add check for the buildx docker plugin in dev-prerequests Signed-off-by: michal.gubricky --------- Signed-off-by: michal.gubricky --- .../Dockerfile | 23 +++++++++++-------- .../Makefile | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile b/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile index 5c75f80d3..86ca601cb 100644 --- a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile +++ b/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Dockerfile @@ -1,12 +1,19 @@ FROM golang:1.23 -# Install kubectl -# Note: Latest version may be found on: -# https://aur.archlinux.org/packages/kubectl-bin/ -RUN wget https://storage.googleapis.com/kubernetes-release/release/v1.21.3/bin/linux/amd64/kubectl -O /usr/bin/kubectl && \ - chmod +x /usr/bin/kubectl && \ - apt-get update && \ - apt-get install -y jq +# Use build arguments to get the correct architecture +ARG TARGETARCH + +# Install kubectl based on the architecture +#See https://github.com/kubernetes-sigs/kubespray/pull/10066 +RUN apt-get update && apt-get install -y wget jq && \ + if [ "$TARGETARCH" = "amd64" ]; then \ + wget https://cdn.dl.k8s.io/release/v1.31.1/bin/linux/amd64/kubectl -O /usr/bin/kubectl; \ + elif [ "$TARGETARCH" = "arm64" ]; then \ + wget https://cdn.dl.k8s.io/release/v1.31.1/bin/linux/arm64/kubectl -O /usr/bin/kubectl; \ + else \ + echo "Unsupported architecture: $TARGETARCH" && exit 1; \ + fi && \ + chmod +x /usr/bin/kubectl COPY ./scs_k8s_tests /src/scs_k8s_tests WORKDIR /src @@ -19,5 +26,3 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ go test -c -o custom.test ./... CMD ["bash", "-c", "go tool test2json ./custom.test -test.v"] - - diff --git a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Makefile b/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Makefile index 2202e9c2f..dbf6757c3 100644 --- a/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Makefile +++ b/Tests/kaas/kaas-sonobuoy-go-example-e2e-framework/Makefile @@ -57,6 +57,7 @@ dev-prerequests: @docker version @sonobuoy version --short @go version + @docker buildx version dev-setup: kind-init