Skip to content

Commit

Permalink
makefile: build multi-arch image
Browse files Browse the repository at this point in the history
Build multi-architecture image using buildah and qemu static utilities.
Creates an image with manifest which refs amd64 (x86_64) and arm64
(aarch64) architecture-specific sub-images. Using the same Dockerfile
regardless of the actual CPU architecture, and let buildah+qemu do all
the low-level logic.

Note: typically, qemu would emulate arm64 on x86_64 which yields longer
build time.

Signed-off-by: Shachar Sharon <[email protected]>
  • Loading branch information
synarete committed Apr 17, 2023
1 parent eea7035 commit 052da28
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ image-build-buildah: build
$(BUILDAH_CMD) config --entrypoint='["/manager"]' $$cn && \
$(BUILDAH_CMD) commit $$cn $(IMG)


.PHONY: image-build-multiarch image-push-multiarch
image-build-multiarch: image-build-multiarch-manifest \
image-build-arch-amd64 image-build-arch-arm64
$(BUILDAH_CMD) manifest inspect $(IMG)

image-build-multiarch-manifest:
$(BUILDAH_CMD) manifest create $(IMG)

image-build-arch-%: qemu-utils
$(BUILDAH_CMD) bud \
--manifest $(IMG) \
--arch "$*" \
--tag "$(IMG)-$*" \
--build-arg=GIT_VERSION="$(GIT_VERSION)" \
--build-arg=COMMIT_ID="$(COMMIT_ID)" \
--build-arg=ARCH="$*" .

image-push-multiarch:
$(BUILDAH_CMD) manifest push --all $(IMG) "docker://$(IMG)"


# Push the container image
docker-push: container-push
container-push:
Expand Down Expand Up @@ -322,3 +344,12 @@ GITLINT=$(GOBIN_ALT)/gitlint
else
GITLINT=$(shell command -v gitlint ;)
endif

.PHONY: qemu-utils
qemu-utils:
ifeq (, $(shell command -v qemu-x86_64-static ;))
$(error "qemu-x86_64-static not found in PATH")
endif
ifeq (, $(shell command -v qemu-aarch64-static ;))
$(error "qemu-aarch64-static not found in PATH")
endif

0 comments on commit 052da28

Please sign in to comment.