From 8ff65a24539d2436461629c43c33dd16e9075820 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Tue, 25 Feb 2025 16:16:44 +0100 Subject: [PATCH] create manifest script --- build-image.sh | 18 ++++++++++++------ create-manifest.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 create-manifest.sh diff --git a/build-image.sh b/build-image.sh index a3557ed..ca1d59a 100755 --- a/build-image.sh +++ b/build-image.sh @@ -48,20 +48,26 @@ echo "✅ Successfully built and tagged:" echo " 📌 ${IMAGE_ARCH}" echo " 🔄 ${IMAGE_LATEST}" +# Ask whether to push the image read -p "🚀 Do you want to push the image to ${REPO}? (y/N): " PUSH_CONFIRM if [[ "$PUSH_CONFIRM" =~ ^[Yy]$ ]]; then echo "📤 Pushing images..." docker push ${IMAGE_ARCH} docker push ${IMAGE_LATEST} echo "✅ Successfully pushed images to ${REPO}" - - echo "â„šī¸ Next step: If you have built and pushed both amd64 and arm64 versions, run the following command to create a multi-arch manifest:" - echo " docker manifest create ${REPO}/${IMAGE_NAME}:${COMMIT_ID} \\" - echo " ${REPO}/${IMAGE_NAME}:${COMMIT_ID}-amd64 \\" - echo " ${REPO}/${IMAGE_NAME}:${COMMIT_ID}-arm64" - echo " docker manifest push ${REPO}/${IMAGE_NAME}:${COMMIT_ID}" else echo "â„šī¸ Skipping push. You can manually push later with:" echo " docker push ${IMAGE_ARCH}" echo " docker push ${IMAGE_LATEST}" + exit 0 +fi + +# After pushing, check if both architectures are available and create the manifest +echo "🔍 Checking if both architectures are pushed..." +if docker manifest inspect "${REPO}/${IMAGE_NAME}:${COMMIT_ID}-amd64" &>/dev/null && \ + docker manifest inspect "${REPO}/${IMAGE_NAME}:${COMMIT_ID}-arm64" &>/dev/null; then + echo "📜 Both architectures are available. Creating multi-architecture manifest..." + ./create-manifest.sh ${IMAGE_NAME} ${COMMIT_ID} +else + echo "âš ī¸ Only one architecture is available. Multi-arch manifest will not be created yet." fi diff --git a/create-manifest.sh b/create-manifest.sh new file mode 100644 index 0000000..75124d1 --- /dev/null +++ b/create-manifest.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -e # Stop on error + +if [ $# -ne 2 ]; then + echo "Usage: $0 " + echo "Example: $0 base-debian 0e85448" + exit 1 +fi + +IMAGE_NAME=$1 +COMMIT_ID=$2 +REPO="registry.tomastm.com" + +# Define image tags +IMAGE_AMD64="${REPO}/${IMAGE_NAME}:${COMMIT_ID}-amd64" +IMAGE_ARM64="${REPO}/${IMAGE_NAME}:${COMMIT_ID}-arm64" +IMAGE_MULTI="${REPO}/${IMAGE_NAME}:${COMMIT_ID}" +IMAGE_LATEST="${REPO}/${IMAGE_NAME}:latest" + +# Check if both architectures exist in the registry +echo "🔎 Checking if both architectures exist..." +if ! docker manifest inspect ${IMAGE_AMD64} &>/dev/null || ! docker manifest inspect ${IMAGE_ARM64} &>/dev/null; then + echo "❌ Error: One or both architectures are missing in the registry." + echo "Ensure both ${IMAGE_AMD64} and ${IMAGE_ARM64} are pushed before running this script." + exit 1 +fi + +# Create the multi-architecture manifest for the commit ID +echo "📜 Creating multi-architecture manifest for ${COMMIT_ID}..." +docker manifest create ${IMAGE_MULTI} ${IMAGE_AMD64} ${IMAGE_ARM64} + +# Push the multi-arch manifest for the commit ID +docker manifest push ${IMAGE_MULTI} +echo "✅ Successfully pushed multi-arch manifest: ${IMAGE_MULTI}" + +# Create and push the latest multi-architecture manifest +echo "🔄 Updating latest multi-architecture manifest..." +docker manifest create ${IMAGE_LATEST} ${IMAGE_AMD64} ${IMAGE_ARM64} +docker manifest push ${IMAGE_LATEST} +echo "✅ Successfully updated latest manifest: ${IMAGE_LATEST}"