#!/bin/bash # Get image name and optional platform as arguments IMAGE_NAME=$1 PLATFORM="linux/arm64v8" # Fixed to linux/arm64v8 # Define paths IMAGE_DIR="docker/images" IMAGE_FILE="${IMAGE_DIR}/${IMAGE_NAME//[:\/]/_}.tar" COMPRESSED_FILE="${IMAGE_FILE}.xz" # 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 echo "Error occurred while pulling $IMAGE_NAME for platform $PLATFORM" exit 1 fi else echo "Image $IMAGE_NAME found locally. Skipping pull." fi # Save the Docker image echo "Saving $IMAGE_NAME Docker image..." docker save ${IMAGE_NAME} > $IMAGE_FILE # Compress the Docker image (overwriting if file exists) echo "Compressing $IMAGE_FILE..." xz -z --force $IMAGE_FILE if [ $? -eq 0 ]; then echo "$IMAGE_NAME Docker image saved and compressed successfully as $COMPRESSED_FILE" else echo "Error occurred while compressing $IMAGE_NAME Docker image" exit 1 fi