From 04708a1a8385f005031d137a2f2ff1bf19b7e2fd Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Mon, 5 Dec 2022 09:43:36 -0500 Subject: [PATCH] Add DOCKER_BUILDX to inject path of buildx binary Signed-off-by: Davanum Srinivas --- Makefile | 15 +++++++++------ cloudbuild.yaml | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index bc61847811d85..b36f211313caf 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ CONTAINER_RUN = "$(CONTAINER_ENGINE)" run --rm --interactive --tty --volume CCRED=\033[0;31m CCEND=\033[0m +# Docker buildx related settings for multi-arch images +DOCKER_BUILDX ?= docker buildx + .PHONY: all build build-preview help serve help: ## Show this help. @@ -78,17 +81,17 @@ 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 version - docker buildx version - 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 \ + $(DOCKER_BUILDX) version + $(DOCKER_BUILDX) inspect image-builder > /dev/null 2>&1 || $(DOCKER_BUILDX) create --name image-builder --use + # copy existing Dockerfile and insert --platform=${TARGETPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile + sed -e 's/\(^FROM\)/FROM --platform=\$$\{TARGETPLATFORM\}/' 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 + $(DOCKER_BUILDX) stop image-builder rm Dockerfile.cross container-build: module-check diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 73293decf3140..7ab6d81e4cd6f 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -20,7 +20,8 @@ steps: - -c - | gcloud auth configure-docker \ - && make container-push + && apk add sed \ + && 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