Skip to content

Commit 3cf9605

Browse files
authored
Merge pull request #38245 from dims/build-and-push-multi-arch-images-using-docker-buildx
Build and push multi-arch images using docker buildx
2 parents 9b7ad7c + 4e6a4b1 commit 3cf9605

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ container-image: ## Build a container image for the preview of the website
7474
container-push: container-image ## Push container image for the preview of the website
7575
$(CONTAINER_ENGINE) push $(CONTAINER_IMAGE)
7676

77+
PLATFORMS ?= linux/arm64,linux/amd64
78+
docker-push: ## Build a multi-architecture image and push that into the registry
79+
docker run --rm --privileged tonistiigi/binfmt:qemu-v6.2.0-26@sha256:5bf63a53ad6222538112b5ced0f1afb8509132773ea6dd3991a197464962854e --install all
80+
docker buildx create --use --name=image-builder 2>/dev/null || docker buildx use --default image-builder
81+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
82+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
83+
docker buildx build \
84+
--push \
85+
--platform=$(PLATFORMS) \
86+
--build-arg HUGO_VERSION=$(HUGO_VERSION) \
87+
--tag $(CONTAINER_IMAGE) \
88+
-f Dockerfile.cross .
89+
docker buildx stop image-builder
90+
rm Dockerfile.cross
91+
7792
container-build: module-check
7893
$(CONTAINER_RUN) --read-only --mount type=tmpfs,destination=/tmp,tmpfs-mode=01777 $(CONTAINER_IMAGE) sh -c "npm ci && hugo --minify --environment development"
7994

cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ steps:
1818
- -c
1919
- |
2020
gcloud auth configure-docker \
21-
&& make container-push
21+
&& make docker-push
2222
substitutions:
2323
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
2424
# can be used as a substitution

0 commit comments

Comments
 (0)