Skip to content

Commit 63b337f

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 63b337f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ BUNDLE_METADATA_OPTS?=$(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1717
COMMIT_ID=$(shell git describe --abbrev=40 --always --exclude='*' --dirty=+ 2>/dev/null)
1818
GIT_VERSION=$(shell git describe --match='v[0-9]*.[0-9]' --match='v[0-9]*.[0-9].[0-9]' 2>/dev/null || echo "(unset)")
1919

20+
# List of supported CPU architectures
21+
ARCH_LIST:=amd64 arm64
22+
2023
CONFIG_KUST_DIR:=config/default
2124
CRD_KUST_DIR:=config/crd
2225
MGR_KUST_DIR:=config/manager
@@ -187,6 +190,28 @@ image-build-buildah: build
187190
$(BUILDAH_CMD) config --entrypoint='["/manager"]' $$cn && \
188191
$(BUILDAH_CMD) commit $$cn $(IMG)
189192

193+
.PHONY: image-build-multiarch
194+
image-build-multiarch: qemu-utils
195+
$(BUILDAH_CMD) manifest create $(IMG)
196+
for arch in $(ARCH_LIST); do \
197+
$(BUILDAH_CMD) bud \
198+
--manifest $(IMG) \
199+
--arch $${arch} \
200+
--tag "$(IMG)-$${arch}" \
201+
--build-arg=GIT_VERSION="$(GIT_VERSION)" \
202+
--build-arg=COMMIT_ID="$(COMMIT_ID)" \
203+
--build-arg=ARCH="$${arch}" . ; \
204+
done
205+
$(BUILDAH_CMD) manifest inspect $(IMG)
206+
207+
.PHONY: image-push-multiarch
208+
image-push-multiarch:
209+
$(BUILDAH_CMD) manifest push --all $(IMG) "docker://$(IMG)"
210+
211+
.PHONY: image-multiarch
212+
image-multiarch: image-build-multiarch image-push-multiarch
213+
214+
190215
# Push the container image
191216
docker-push: container-push
192217
container-push:
@@ -322,3 +347,12 @@ GITLINT=$(GOBIN_ALT)/gitlint
322347
else
323348
GITLINT=$(shell command -v gitlint ;)
324349
endif
350+
351+
.PHONY: qemu-utils
352+
qemu-utils:
353+
ifeq (, $(shell command -v qemu-x86_64-static ;))
354+
$(error "qemu-x86_64-static not found in PATH")
355+
endif
356+
ifeq (, $(shell command -v qemu-aarch64-static ;))
357+
$(error "qemu-aarch64-static not found in PATH")
358+
endif

0 commit comments

Comments
 (0)