From 0e39ad45d142d30375856744a18e283708cdbe32 Mon Sep 17 00:00:00 2001 From: Torben Haack Date: Fri, 11 Oct 2024 09:18:01 +0200 Subject: [PATCH] improve pulling mechanic --- packages/reservation-platform/docker/save.sh | 43 +++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/reservation-platform/docker/save.sh b/packages/reservation-platform/docker/save.sh index 6778602..2ce2712 100755 --- a/packages/reservation-platform/docker/save.sh +++ b/packages/reservation-platform/docker/save.sh @@ -1,21 +1,52 @@ #!/bin/bash -# Get image name and optional platform as arguments +# Get image name as argument IMAGE_NAME=$1 -PLATFORM="linux/arm64v8" # Fixed to linux/arm64v8 +PLATFORM="linux/arm64" # Define paths IMAGE_DIR="docker/images" IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME//[:\/]/_}.tar" COMPRESSED_FILE="${IMAGE_FILE}.xz" +# Function to pull the image +pull_image() { + local image=$1 + if [[ $image == arm64v8/* ]]; then + echo "Pulling image $image without platform specification..." + docker pull $image + else + echo "Pulling image $image for platform $PLATFORM..." + docker pull --platform $PLATFORM $image + fi + return $? +} + # Pull the image if it is not available locally if ! docker image inspect ${IMAGE_NAME} &>/dev/null; then - echo "Image $IMAGE_NAME not found locally. Pulling for platform $PLATFORM..." - docker pull --platform $PLATFORM ${IMAGE_NAME} - if [ $? -ne 0 ]; then + if pull_image ${IMAGE_NAME}; then + echo "Image $IMAGE_NAME pulled successfully." + else echo "Error occurred while pulling $IMAGE_NAME for platform $PLATFORM" - exit 1 + echo "Trying to pull $IMAGE_NAME without platform specification..." + + # Attempt to pull again without platform + if pull_image ${IMAGE_NAME}; then + echo "Image $IMAGE_NAME pulled successfully without platform." + else + echo "Error occurred while pulling $IMAGE_NAME without platform." + echo "Trying to pull arm64v8/${IMAGE_NAME} instead..." + + # Construct new image name + NEW_IMAGE_NAME="arm64v8/${IMAGE_NAME}" + if pull_image ${NEW_IMAGE_NAME}; then + echo "Image $NEW_IMAGE_NAME pulled successfully." + IMAGE_NAME=${NEW_IMAGE_NAME} # Update IMAGE_NAME to use the new one + else + echo "Error occurred while pulling $NEW_IMAGE_NAME" + exit 1 + fi + fi fi else echo "Image $IMAGE_NAME found locally. Skipping pull."