From 6590e5bd40100ae9d2d9f604bb221fc09c53a614 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Sun, 7 Jul 2024 21:13:47 +0500 Subject: [PATCH] Script for multiarch image. --- build_multiarch.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 build_multiarch.sh diff --git a/build_multiarch.sh b/build_multiarch.sh new file mode 100755 index 0000000..4181b4e --- /dev/null +++ b/build_multiarch.sh @@ -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}"