Script for multiarch image.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Stanislav Nikitin 2024-07-07 21:13:47 +05:00
parent c2977ada4d
commit 6590e5bd40
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550

30
build_multiarch.sh Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# This script builds arm64 toolbox image, pushes it to packages and create version manifest with
# both amd64 and arm64 images.
# This script is launched on my local machine (which is macbook with M2 Pro CPU) and uses
# lima with arm64 version of Docker.
IMAGE_NAME="code.pztrn.name/containers/go-toolbox"
VERSION=$1
if [ "${VERSION}" == "" ]; then
echo "! No version specified as first argument!"
exit 1
fi
echo "* Building multiarch image with amd64 and arm64 images for version '${VERSION}'..."
echo "* Pulling ${IMAGE_NAME}:${VERSION} (amd64)..."
docker pull "${IMAGE_NAME}:${VERSION}"
echo "* Retagging pulled image as ${IMAGE_NAME}:${VERSION}-amd64..."
docker image tag "${IMAGE_NAME}:${VERSION}" "${IMAGE_NAME}:${VERSION}-amd64"
echo "* Pushing ${IMAGE_NAME}:${VERSION}-amd64..."
docker push "${IMAGE_NAME}:${VERSION}-amd64"
echo "* Building arm64 version..."
docker build -t "${IMAGE_NAME}:${VERSION}-arm64" .
echo "* Pushing arm64 image..."
docker push "${IMAGE_NAME}:${VERSION}-arm64"
echo "* Creating multiarch manifest..."
docker manifest create "${IMAGE_NAME}:${VERSION}" "${IMAGE_NAME}:${VERSION}-amd64" "${IMAGE_NAME}:${VERSION}-arm64"
echo "* Pushing multiarch manifest as ${IMAGE_NAME}:${VERSION}..."
docker manifest push "${IMAGE_NAME}:${VERSION}"