From 2326805c69086edb22c5375894ea21281f7b4f8c Mon Sep 17 00:00:00 2001 From: bitliu Date: Mon, 21 Nov 2022 16:28:59 +0800 Subject: [PATCH 1/2] fix: add buildx context setup before starting build Signed-off-by: bitliu --- Makefile | 15 ++++++++++++++- hack/build-and-push.sh | 7 ++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f7a4aee8f4..5470e2fd63 100644 --- a/Makefile +++ b/Makefile @@ -130,8 +130,21 @@ image.buildx.verify: docker buildx version; \ fi +BUILDX_CONTEXT = gateway-api-builder +BUILDX_PLATFORMS = linux/amd64,linux/arm64 + +# Setup multi-arch enviroment +# Recreate a buildx context for multi-arch images. +.PHONY: image.multiarch.setup +image.multiarch.setup: image.buildx.verify + @if [ "$(shell uname)" == "Linux" ]; then \ + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \ + fi + docker buildx rm $(BUILDX_CONTEXT) || : + docker buildx create --use --name $(BUILDX_CONTEXT) --platform "${BUILDX_PLATFORMS}" + .PHONY: release-staging -release-staging: image.buildx.verify +release-staging: image.multiarch.setup hack/build-and-push.sh # Generate a virtualenv install, which is useful for hacking on the diff --git a/hack/build-and-push.sh b/hack/build-and-push.sh index 31a55d9769..2f36ab754a 100755 --- a/hack/build-and-push.sh +++ b/hack/build-and-push.sh @@ -62,6 +62,11 @@ then BINARY_TAG="${BASE_REF}" fi +# Support multi-arch image build and push. +BUILDX_PLATFORMS="linux/amd64,linux/arm64" + +echo "Building and pushing admission-server image...${BUILDX_PLATFORMS}" + # First, build the image, with the version info passed in. # Note that an image will *always* be built tagged with the GIT_TAG, so we know when it was built. # And, we add an extra version tag - either :latest or semver. @@ -71,6 +76,6 @@ docker buildx build \ -t ${REGISTRY}/admission-server:${VERSION_TAG} \ --build-arg "COMMIT=${COMMIT}" \ --build-arg "TAG=${BINARY_TAG}" \ - --platform linux/amd64,linux/arm64 \ + --platform ${BUILDX_PLATFORMS} \ --push \ . From b542df802428720f63ca41432ded7701e71e0eee Mon Sep 17 00:00:00 2001 From: bitliu Date: Mon, 21 Nov 2022 19:16:53 +0800 Subject: [PATCH 2/2] docs: adds comments Signed-off-by: bitliu --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5470e2fd63..9cf42b3118 100644 --- a/Makefile +++ b/Makefile @@ -133,16 +133,20 @@ image.buildx.verify: BUILDX_CONTEXT = gateway-api-builder BUILDX_PLATFORMS = linux/amd64,linux/arm64 -# Setup multi-arch enviroment -# Recreate a buildx context for multi-arch images. +# Setup multi-arch docker buildx enviroment. .PHONY: image.multiarch.setup image.multiarch.setup: image.buildx.verify +# Ensure qemu is in binfmt_misc. +# Docker desktop already has these in versions recent enough to have buildx, +# We only need to do this setup on linux hosts. @if [ "$(shell uname)" == "Linux" ]; then \ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \ fi +# Ensure we use a builder that can leverage it, we need to recreate one. docker buildx rm $(BUILDX_CONTEXT) || : docker buildx create --use --name $(BUILDX_CONTEXT) --platform "${BUILDX_PLATFORMS}" +# Build and Push Multi Arch Images. .PHONY: release-staging release-staging: image.multiarch.setup hack/build-and-push.sh