From 4e6a4b1b17458a841bce2db1f6dfc8dbcea38b27 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Sat, 3 Dec 2022 19:50:31 -0500 Subject: [PATCH] Build and push multi-arch images using docker buildx Signed-off-by: Davanum Srinivas --- Makefile | 15 +++++++++++++++ cloudbuild.yaml | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f964ad79f2d21..794dd352e0750 100644 --- a/Makefile +++ b/Makefile @@ -74,6 +74,21 @@ container-image: ## Build a container image for the preview of the website container-push: container-image ## Push container image for the preview of the website $(CONTAINER_ENGINE) push $(CONTAINER_IMAGE) +PLATFORMS ?= linux/arm64,linux/amd64 +docker-push: ## Build a multi-architecture image and push that into the registry + docker run --rm --privileged tonistiigi/binfmt:qemu-v6.2.0-26@sha256:5bf63a53ad6222538112b5ced0f1afb8509132773ea6dd3991a197464962854e --install all + docker buildx create --use --name=image-builder 2>/dev/null || docker buildx use --default image-builder + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross + docker buildx build \ + --push \ + --platform=$(PLATFORMS) \ + --build-arg HUGO_VERSION=$(HUGO_VERSION) \ + --tag $(CONTAINER_IMAGE) \ + -f Dockerfile.cross . + docker buildx stop image-builder + rm Dockerfile.cross + container-build: module-check $(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development" diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 542d58016c7e9..c75e11fc906af 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -18,7 +18,7 @@ steps: - -c - | gcloud auth configure-docker \ - && make container-push + && make docker-push substitutions: # _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and # can be used as a substitution