#!/bin/bash # Specify the image names and tags MYP_RP_IMAGE_NAME="myp-rp" MYP_RP_IMAGE_TAG="latest" CADDY_IMAGE_NAME="caddy" CADDY_IMAGE_TAG="latest" # Create a new builder instance with a sensible name BUILDER_NAME="myp-rp-arm64-builder" echo "Creating a new builder instance named $BUILDER_NAME..." docker buildx create --name $BUILDER_NAME --use # Build the myp-rp Docker image from Dockerfile for arm64 echo "Building myp-rp Docker image from Dockerfile for arm64..." docker buildx build --platform linux/arm64 -t ${MYP_RP_IMAGE_NAME}:${MYP_RP_IMAGE_TAG} -f $PWD/Dockerfile $PWD --output type=docker,dest=docker/${MYP_RP_IMAGE_NAME}_${MYP_RP_IMAGE_TAG}.tar # Check if the build was successful if [ $? -ne 0 ]; then echo "Error occurred while building the myp-rp Docker image" docker buildx rm $BUILDER_NAME exit 1 fi echo "myp-rp Docker image built successfully" # Compress the myp-rp tar file using xz MYP_RP_COMPRESSED_FILE="docker/${MYP_RP_IMAGE_NAME}_${MYP_RP_IMAGE_TAG}.tar.xz" echo "Compressing the myp-rp image to $MYP_RP_COMPRESSED_FILE..." # Check if the compressed file exists and remove it if [ -f "$MYP_RP_COMPRESSED_FILE" ]; then echo "Removing existing compressed file $MYP_RP_COMPRESSED_FILE..." rm "$MYP_RP_COMPRESSED_FILE" fi # Proceed with compression for myp-rp xz -z docker/${MYP_RP_IMAGE_NAME}_${MYP_RP_IMAGE_TAG}.tar # Check if the compression was successful if [ $? -ne 0 ]; then echo "Error occurred while compressing the myp-rp Docker image" docker buildx rm $BUILDER_NAME exit 1 fi echo "myp-rp Docker image compressed successfully as $MYP_RP_COMPRESSED_FILE" # Save the caddy Docker image echo "Saving caddy Docker image..." docker pull ${CADDY_IMAGE_NAME}:${CADDY_IMAGE_TAG} docker save ${CADDY_IMAGE_NAME}:${CADDY_IMAGE_TAG} > docker/${CADDY_IMAGE_NAME}.tar # Compress the caddy tar file using xz CADDY_COMPRESSED_FILE="docker/${CADDY_IMAGE_NAME}.tar.xz" echo "Compressing the caddy image to $CADDY_COMPRESSED_FILE..." # Check if the compressed file exists and remove it if [ -f "$CADDY_COMPRESSED_FILE" ]; then echo "Removing existing compressed file $CADDY_COMPRESSED_FILE..." rm "$CADDY_COMPRESSED_FILE" fi # Proceed with compression for caddy xz -z docker/${CADDY_IMAGE_NAME}.tar # Check if the compression was successful if [ $? -ne 0 ]; then echo "Error occurred while compressing the caddy Docker image" docker buildx rm $BUILDER_NAME exit 1 fi echo "Caddy Docker image compressed successfully as $CADDY_COMPRESSED_FILE" # Remove the builder instance docker buildx rm $BUILDER_NAME echo "Build process completed"