From 365a5fc0b54e6553d8ab2c941342067c099d6686 Mon Sep 17 00:00:00 2001 From: Pavel Sviderski Date: Tue, 20 May 2025 12:47:27 +1000 Subject: [PATCH] chore: build multiarch images for corrosion and ucind to support e2e tests on amd64 --- Dockerfile | 15 ++++++++++++--- Makefile | 12 ++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b8ac1b5d..763fb168 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,13 +17,22 @@ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o uncloudd cmd/uncloudd/main FROM alpine:${ALPINE_VERSION} AS corrosion-download -RUN wget -q -O /tmp/corrosion.tar.gz \ - https://github.com/psviderski/corrosion/releases/latest/download/corrosion-aarch64-unknown-linux-gnu.tar.gz \ +ARG TARGETARCH + +RUN CORROSION_ARCH=$(case "${TARGETARCH}" in \ + "amd64") echo "x86_64" ;; \ + "arm64") echo "aarch64" ;; \ + *) echo "Architecture '${TARGETARCH}' not supported" >&2 && exit 1 ;; \ + esac) \ + && wget -q -O /tmp/corrosion.tar.gz \ + "https://github.com/psviderski/corrosion/releases/latest/download/corrosion-${CORROSION_ARCH}-unknown-linux-gnu.tar.gz" \ && tar -xzf /tmp/corrosion.tar.gz -C /tmp \ && install /tmp/corrosion /usr/local/bin/corrosion \ && rm /tmp/corrosion.tar.gz /tmp/corrosion -FROM chainguard/wolfi-base:latest AS corrosion +# Beware that more modern images like chainguard/wolfi-base build glibc with flags that require newer CPU features, +# e.g. x86-64-v2. So such image may fail with "Fatal glibc error: CPU does not support x86-64-v2" on older CPUs. +FROM gcr.io/distroless/cc-debian12:latest AS corrosion COPY --from=corrosion-download /usr/local/bin/corrosion /usr/local/bin/corrosion CMD ["corrosion", "agent"] diff --git a/Makefile b/Makefile index 4254ae39..e9d3c5e4 100644 --- a/Makefile +++ b/Makefile @@ -49,14 +49,14 @@ proto: corrosion-image: docker build -t "$(CORROSION_IMAGE)" --target corrosion . -.PHONY: corrosion-image-push -corrosion-image-push: corrosion-image - docker push "$(CORROSION_IMAGE)" +.PHONY: corrosion-multiarch-image-push +corrosion-multiarch-image-push: + docker buildx build --push --platform linux/amd64,linux/arm64 -t "$(CORROSION_IMAGE)" --target corrosion . .PHONY: ucind-image ucind-image: docker build -t "$(UCIND_IMAGE)" --target ucind . -.PHONY: ucind-image-push -ucind-image-push: ucind-image - docker push "$(UCIND_IMAGE)" +.PHONY: ucind-multiarch-image-push +ucind-multiarch-image-push: + docker buildx build --push --platform linux/amd64,linux/arm64 -t "$(UCIND_IMAGE)" --target ucind .