Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makefile: build multi-arch image #301

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

synarete
Copy link
Collaborator

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.

Copy link
Collaborator

@phlogistonjohn phlogistonjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good so far, I am a bit curious why it uses buidah directly rather than docker/podman. Were there features of the process that are only supported by buildah?

@phlogistonjohn
Copy link
Collaborator

Also, could we leverage make's typical target based workflows rather than an embedded shell loop? Something like:

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

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

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


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

.PHONY: image-multiarch
image-multiarch: image-build-multiarch image-push-multiarch

(I left out .PHONYs on my added rule names just to be a tad shorter in a gh comment)

@synarete
Copy link
Collaborator Author

synarete commented Apr 17, 2023

Looks pretty good so far, I am a bit curious why it uses buidah directly rather than docker/podman. Were there features of the process that are only supported by buildah?

docker uses the docker buildx to build multi-arch images; unfortunately, this is docker specific sub-command. I used BUILDAH_CMD instead of CONTAINER_CMD as it has the --manifest and --arch flags. With podman it would require multi-steps build.

@synarete
Copy link
Collaborator Author

Also, could we leverage make's typical target based workflows rather than an embedded shell loop? Something like:

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

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

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


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

.PHONY: image-multiarch
image-multiarch: image-build-multiarch image-push-multiarch

(I left out .PHONYs on my added rule names just to be a tad shorter in a gh comment)

Fair enough. Will fix.

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 <ssharon@redhat.com>
@mergify mergify bot added the priority-review This PR deserves a look label May 2, 2023
@synarete synarete marked this pull request as draft July 18, 2023 13:30
@phlogistonjohn phlogistonjohn removed the priority-review This PR deserves a look label Aug 15, 2023
@phlogistonjohn
Copy link
Collaborator

Removed priority-review label because this is a draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants