Skip to content

Commit

Permalink
Multi Arch Image Build
Browse files Browse the repository at this point in the history
Bazel doesn't support creating a multi-arch manifest, so we can work around
that by using a container tool to add multiple architectures to a single manifest.

Signed-off-by: Ryan Hallisey <[email protected]>
  • Loading branch information
rthallisey committed Jan 6, 2023
1 parent 8947efe commit 2af4a05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ build-functests: bazel-build-functests
bazel-build-image-bundle:
hack/dockerized "export BUILD_ARCH=${BUILD_ARCH} && hack/bazel-fmt.sh && DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} IMAGE_PREFIX=${IMAGE_PREFIX} hack/bazel-build-image-bundle.sh"

multi-arch-build:
BUILD_ARCH=${BUILD_ARCH} && DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} DOCKER_TAG_ALT=${DOCKER_TAG_ALT} IMAGE_PREFIX=${IMAGE_PREFIX} IMAGE_PREFIX_ALT=${IMAGE_PREFIX_ALT} ./hack/multi-arch.sh

bazel-build-verify: bazel-build
./hack/dockerized "hack/bazel-fmt.sh"
./hack/verify-generate.sh
Expand Down Expand Up @@ -218,6 +221,7 @@ lint:
bazel-build \
bazel-build-image-bundle \
bazel-build-images \
multi-arch-build \
bazel-push-images \
bazel-test \
functest-image-build \
Expand Down
26 changes: 26 additions & 0 deletions hack/multi-arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

CONTAINER_BUILD="${CONTAINER_BUILD:-docker}"
image_list="virt-controller virt-handler virt-launcher virt-api virt-operator"

function get_tag {
local tag
tag=${DOCKER_TAG}
# Strip trailing $arch from the tag
for arch in ${BUILD_ARCH//,/ }; do
tag=${tag%"-$arch"}
done
echo $tag
}

for image in ${image_list}; do
amend=""
for arch in ${BUILD_ARCH//,/ }; do
tag="$(get_tag)"
amend+=" --amend $DOCKER_PREFIX/$image:$tag-$arch"
done

cmd="$CONTAINER_BUILD manifest create $DOCKER_PREFIX/$image:$tag-multi-arch $amend"
echo $cmd
$cmd
done

0 comments on commit 2af4a05

Please sign in to comment.