Skip to content

Commit 052da28

Browse files
committed
makefile: build multi-arch image
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]>
1 parent eea7035 commit 052da28

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,28 @@ image-build-buildah: build
187187
$(BUILDAH_CMD) config --entrypoint='["/manager"]' $$cn && \
188188
$(BUILDAH_CMD) commit $$cn $(IMG)
189189

190+
191+
.PHONY: image-build-multiarch image-push-multiarch
192+
image-build-multiarch: image-build-multiarch-manifest \
193+
image-build-arch-amd64 image-build-arch-arm64
194+
$(BUILDAH_CMD) manifest inspect $(IMG)
195+
196+
image-build-multiarch-manifest:
197+
$(BUILDAH_CMD) manifest create $(IMG)
198+
199+
image-build-arch-%: qemu-utils
200+
$(BUILDAH_CMD) bud \
201+
--manifest $(IMG) \
202+
--arch "$*" \
203+
--tag "$(IMG)-$*" \
204+
--build-arg=GIT_VERSION="$(GIT_VERSION)" \
205+
--build-arg=COMMIT_ID="$(COMMIT_ID)" \
206+
--build-arg=ARCH="$*" .
207+
208+
image-push-multiarch:
209+
$(BUILDAH_CMD) manifest push --all $(IMG) "docker://$(IMG)"
210+
211+
190212
# Push the container image
191213
docker-push: container-push
192214
container-push:
@@ -322,3 +344,12 @@ GITLINT=$(GOBIN_ALT)/gitlint
322344
else
323345
GITLINT=$(shell command -v gitlint ;)
324346
endif
347+
348+
.PHONY: qemu-utils
349+
qemu-utils:
350+
ifeq (, $(shell command -v qemu-x86_64-static ;))
351+
$(error "qemu-x86_64-static not found in PATH")
352+
endif
353+
ifeq (, $(shell command -v qemu-aarch64-static ;))
354+
$(error "qemu-aarch64-static not found in PATH")
355+
endif

0 commit comments

Comments
 (0)