From 7958f3886467aef1a386e3111136f1d3c59f7149 Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Tue, 23 Apr 2024 13:12:10 +0300 Subject: [PATCH] deployment/docker: allow cross-platform building on arm64 platform (#6158) Added x86_64 libraries to allow building cross-platform images on arm64 --- deployment/docker/Makefile | 13 ++++++------- deployment/docker/builder/Dockerfile | 11 ++++++++--- docs/Release-Guide.md | 5 ----- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/deployment/docker/Makefile b/deployment/docker/Makefile index d9d2de7bd..00a73a48c 100644 --- a/deployment/docker/Makefile +++ b/deployment/docker/Makefile @@ -102,24 +102,23 @@ run-via-docker: package-via-docker app-via-docker-goos-goarch: APP_SUFFIX='-$(GOOS)-$(GOARCH)' \ - DOCKER_OPTS='--env CGO_ENABLED=$(CGO_ENABLED) --env GOOS=$(GOOS) --env GOARCH=$(GOARCH)' \ + DOCKER_OPTS='--env CGO_ENABLED=$(CGO_ENABLED) --env GOOS=$(GOOS) --env GOARCH=$(GOARCH) $(foreach v,$(EXTRA_ENVS),--env $(v))' \ $(MAKE) app-via-docker app-via-docker-pure: APP_SUFFIX='-pure' DOCKER_OPTS='--env CGO_ENABLED=0' $(MAKE) app-via-docker app-via-docker-linux-amd64: + EXTRA_ENVS='CC=/opt/cross-builder/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc' \ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(MAKE) app-via-docker-goos-goarch app-via-docker-linux-arm: - APP_SUFFIX='-linux-arm' \ - DOCKER_OPTS='--env CGO_ENABLED=0 --env GOOS=linux --env GOARCH=arm --env GOARM=5' \ - $(MAKE) app-via-docker + EXTRA_ENVS='GOARM=5' \ + CGO_ENABLED=0 GOOS=linux GOARCH=arm $(MAKE) app-via-docker-goos-goarch app-via-docker-linux-arm64: - APP_SUFFIX='-linux-arm64' \ - DOCKER_OPTS='--env CGO_ENABLED=1 --env GOOS=linux --env GOARCH=arm64 --env CC=/opt/cross-builder/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc' \ - $(MAKE) app-via-docker + CC=/opt/cross-builder/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc \ + CGO_ENABLED=1 GOOS=linux GOARCH=arm64 $(MAKE) app-via-docker-goos-goarch app-via-docker-linux-ppc64le: CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le $(MAKE) app-via-docker-goos-goarch diff --git a/deployment/docker/builder/Dockerfile b/deployment/docker/builder/Dockerfile index 0efb33b91..20543b7d5 100644 --- a/deployment/docker/builder/Dockerfile +++ b/deployment/docker/builder/Dockerfile @@ -3,7 +3,12 @@ FROM $go_builder_image STOPSIGNAL SIGINT RUN apk add git gcc musl-dev make wget --no-cache && \ mkdir /opt/cross-builder && \ - wget https://musl.cc/aarch64-linux-musl-cross.tgz -O /opt/cross-builder/aarch64-musl.tgz --no-verbose && \ cd /opt/cross-builder && \ - tar zxf aarch64-musl.tgz -C ./ && \ - rm /opt/cross-builder/aarch64-musl.tgz + for arch in aarch64 x86_64; do \ + wget \ + https://musl.cc/${arch}-linux-musl-cross.tgz \ + -O /opt/cross-builder/${arch}-musl.tgz \ + --no-verbose && \ + tar zxf ${arch}-musl.tgz -C ./ && \ + rm /opt/cross-builder/${arch}-musl.tgz; \ + done diff --git a/docs/Release-Guide.md b/docs/Release-Guide.md index f73bf55b3..e19d9b464 100644 --- a/docs/Release-Guide.md +++ b/docs/Release-Guide.md @@ -38,11 +38,6 @@ docker buildx create --use --name=qemu docker buildx inspect --bootstrap ``` -For ARM arch (M1/M2 processors) additionally configure docker with preferred platform: -``` -export DOCKER_DEFAULT_PLATFORM=linux/amd64 -``` - By default, docker on MacOS has limited amount of resources (CPU, mem) to use. Bumping the limits may significantly improve build speed.