From 5ad7dd557609a8adc711514b2475bd45ecfa3106 Mon Sep 17 00:00:00 2001 From: Torben Haack Date: Thu, 10 Oct 2024 06:28:35 +0200 Subject: [PATCH] add build scripts and build container --- .../docker/build_image.sh | 22 ++++++-- .../docker/deploy_container.sh | 52 +++++++++++++++++++ .../docker/myp-rp_latest.tar.xz | 3 ++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100755 packages/reservation-platform/docker/deploy_container.sh create mode 100644 packages/reservation-platform/docker/myp-rp_latest.tar.xz diff --git a/packages/reservation-platform/docker/build_image.sh b/packages/reservation-platform/docker/build_image.sh index f2f7a7e..d5361d3 100755 --- a/packages/reservation-platform/docker/build_image.sh +++ b/packages/reservation-platform/docker/build_image.sh @@ -7,12 +7,28 @@ IMAGE_TAG="latest" # Specify the output file name OUTPUT_FILE="myp-rp_latest.tar.xz" -# Save the Docker image and compress it with xz -docker save ${IMAGE_NAME}:${IMAGE_TAG} | xz -z -T0 > ./${OUTPUT_FILE} +# Build the Docker image from Containerfile +echo "Building Docker image from Containerfile..." +docker build -t ${IMAGE_NAME}:${IMAGE_TAG} -f $PWD/Containerfile $PWD -# Check if the operation was successful +# Check if the build was successful +if [ $? -ne 0 ]; then + echo "Error occurred while building the Docker image" + exit 1 +fi + +echo "Docker image built successfully" + +# Save the Docker image and compress it with xz +echo "Saving and compressing the Docker image..." +docker save ${IMAGE_NAME}:${IMAGE_TAG} | xz -z -T0 > $PWD/docker/${OUTPUT_FILE} + +# Check if the save operation was successful if [ $? -eq 0 ]; then echo "Image successfully saved and compressed to ${OUTPUT_FILE}" else echo "Error occurred while saving and compressing the image" + exit 1 fi + +echo "Process completed successfully" diff --git a/packages/reservation-platform/docker/deploy_container.sh b/packages/reservation-platform/docker/deploy_container.sh new file mode 100755 index 0000000..a0de544 --- /dev/null +++ b/packages/reservation-platform/docker/deploy_container.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Specify the image name and tag +IMAGE_NAME="myp-rp" +IMAGE_TAG="latest" + +# Specify the input file name +INPUT_FILE="myp-rp_latest.tar.xz" + +# Path to the docker directory +DOCKER_DIR="$PWD/docker" + +# Path to the compose file +COMPOSE_FILE="$DOCKER_DIR/compose.yml" + +# Check if the input file exists +if [ ! -f "$DOCKER_DIR/$INPUT_FILE" ]; then + echo "Error: $INPUT_FILE not found in $DOCKER_DIR" + exit 1 +fi + +# Load the Docker image +echo "Loading Docker image from $INPUT_FILE..." +xz -dc "$DOCKER_DIR/$INPUT_FILE" | docker load + +# Check if the operation was successful +if [ $? -eq 0 ]; then + echo "Image successfully loaded into Docker" +else + echo "Error occurred while loading the image" + exit 1 +fi + +# Check if the compose file exists +if [ ! -f "$COMPOSE_FILE" ]; then + echo "Error: compose.yml not found in $DOCKER_DIR" + exit 1 +fi + +# Execute docker compose +echo "Running docker compose..." +docker compose -f "$COMPOSE_FILE" up -d + +# Check if the operation was successful +if [ $? -eq 0 ]; then + echo "Docker compose executed successfully" +else + echo "Error occurred while executing docker compose" + exit 1 +fi + +echo "Process completed successfully" diff --git a/packages/reservation-platform/docker/myp-rp_latest.tar.xz b/packages/reservation-platform/docker/myp-rp_latest.tar.xz new file mode 100644 index 0000000..422c153 --- /dev/null +++ b/packages/reservation-platform/docker/myp-rp_latest.tar.xz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6b303b29594a72a377d822889380548c0e090db28bf511dcc36c95d73e9bc0c +size 513615424