From f03cce703a921e3f70136dc39a7784d81cf186c3 Mon Sep 17 00:00:00 2001 From: Torben Haack Date: Thu, 10 Oct 2024 07:17:10 +0200 Subject: [PATCH] use compressed docker images --- .gitattributes | 2 +- packages/reservation-platform/.gitattributes | 1 - .../docker/build_image.sh | 32 ++++++++++++++++--- .../docker/deploy_container.sh | 21 ++++++++++-- 4 files changed, 48 insertions(+), 8 deletions(-) delete mode 100644 packages/reservation-platform/.gitattributes diff --git a/.gitattributes b/.gitattributes index 42f3855..c5e7318 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -packages/reservation-platform/docker/myp-rp_latest.tar filter=lfs diff=lfs merge=lfs -text +packages/reservation-platform/docker/myp-rp_latest.tar.xz filter=lfs diff=lfs merge=lfs -text diff --git a/packages/reservation-platform/.gitattributes b/packages/reservation-platform/.gitattributes deleted file mode 100644 index 5a97bca..0000000 --- a/packages/reservation-platform/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.tar filter=lfs diff=lfs merge=lfs -text diff --git a/packages/reservation-platform/docker/build_image.sh b/packages/reservation-platform/docker/build_image.sh index d4af9e4..daf3d63 100755 --- a/packages/reservation-platform/docker/build_image.sh +++ b/packages/reservation-platform/docker/build_image.sh @@ -4,8 +4,8 @@ IMAGE_NAME="myp-rp" IMAGE_TAG="latest" -# Specify the output file name (changed extension to .tar) -OUTPUT_FILE="myp-rp_latest.tar" +# Specify the output file name (changed extension to .tar.xz for compressed file) +OUTPUT_FILE="myp-rp_latest.tar.xz" # Build the Docker image from Containerfile echo "Building Docker image from Containerfile..." @@ -21,11 +21,35 @@ echo "Docker image built successfully" # Save the Docker image without compression echo "Saving the Docker image..." -docker save ${IMAGE_NAME}:${IMAGE_TAG} > $PWD/docker/${OUTPUT_FILE} +docker save ${IMAGE_NAME}:${IMAGE_TAG} > $PWD/docker/myp-rp_latest.tar # Check if the save operation was successful if [ $? -eq 0 ]; then - echo "Image successfully saved to ${OUTPUT_FILE}" + echo "Image successfully saved to myp-rp_latest.tar" + + # Compress the saved image using xz + echo "Compressing the Docker image with xz..." + xz -z $PWD/docker/myp-rp_latest.tar + + # Check if the compression was successful + if [ $? -eq 0 ]; then + mv $PWD/docker/myp-rp_latest.tar.xz $PWD/docker/${OUTPUT_FILE} + echo "Image successfully compressed to ${OUTPUT_FILE}" + + # Remove the original .tar file + echo "Cleaning up the original .tar file..." + rm $PWD/docker/myp-rp_latest.tar + + if [ $? -eq 0 ]; then + echo ".tar file removed successfully" + else + echo "Error occurred while removing the .tar file" + exit 1 + fi + else + echo "Error occurred while compressing the image" + exit 1 + fi else echo "Error occurred while saving the image" exit 1 diff --git a/packages/reservation-platform/docker/deploy_container.sh b/packages/reservation-platform/docker/deploy_container.sh index 622be46..954f695 100755 --- a/packages/reservation-platform/docker/deploy_container.sh +++ b/packages/reservation-platform/docker/deploy_container.sh @@ -4,8 +4,9 @@ IMAGE_NAME="myp-rp" IMAGE_TAG="latest" -# Specify the input file name (changed extension to .tar) +# Specify the input file name for the compressed and uncompressed Docker image INPUT_FILE="myp-rp_latest.tar" +COMPRESSED_INPUT_FILE="myp-rp_latest.tar.xz" # Path to the docker directory DOCKER_DIR="$PWD/docker" @@ -13,7 +14,23 @@ DOCKER_DIR="$PWD/docker" # Path to the compose file COMPOSE_FILE="$DOCKER_DIR/compose.yml" -# Check if the input file exists +# Check if the compressed input file exists +if [ -f "$DOCKER_DIR/$COMPRESSED_INPUT_FILE" ]; then + echo "Found compressed Docker image: $COMPRESSED_INPUT_FILE" + + # Decompress the .tar.xz file + echo "Decompressing the Docker image..." + xz -d "$DOCKER_DIR/$COMPRESSED_INPUT_FILE" + + # Check if the decompression was successful + if [ $? -ne 0 ]; then + echo "Error occurred while decompressing $COMPRESSED_INPUT_FILE" + exit 1 + fi + echo "Decompression completed: $INPUT_FILE" +fi + +# Check if the uncompressed input file exists if [ ! -f "$DOCKER_DIR/$INPUT_FILE" ]; then echo "Error: $INPUT_FILE not found in $DOCKER_DIR" exit 1