#!/bin/bash source _dockerhelper.sh # Print error message and exit with code 1 # Usage: die "error message" die() { echo -e "\033[91mError: $1\033[0m" exit 1 } # Load environment variables from .env file # Usage: load_env [path_to_env_file] # If no path is provided, looks for .env in the same directory as the script load_env() { local script_dir="$(dirname "${BASH_SOURCE[0]}")" local env_file if [ -z "$1" ]; then echo "Usage: $0 [path_to_env_file]" return 1 else # If path is relative, make it absolute using script directory as base if [[ "$1" != /* ]]; then env_file="$script_dir/$1" else env_file="$1" fi fi if [ -f "$env_file" ]; then set -a source "$env_file" set +a else echo "Warning: .env file not found at $env_file" return 1 fi } grey_start() { echo -e -n "\033[90m" } grey_end() { echo -e -n "\033[0m" } create_and_start_container() { if _is_container_exists $CONTAINER_NAME; then _is_container_running $CONTAINER_NAME && return 0 _start_container $CONTAINER_NAME else grey_start docker run -d \ --restart unless-stopped \ --name ${CONTAINER_NAME} \ -p ${HOST_PORT}:${CONTAINER_PORT} \ -v ${DATA_FOLDER}:/skdata \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} grey_end fi if ! _is_container_running $CONTAINER_NAME; then die "Container ${CONTAINER_NAME} failed to start" fi ID=$(_get_container_id $CONTAINER_NAME) echo "Container ${CONTAINER_NAME} is running with ID ${ID}" }