Big Refactor

This commit is contained in:
John
2025-04-27 12:34:26 +12:00
parent d5c7dc7de6
commit 8614d29b06
20 changed files with 64 additions and 101 deletions

View File

@ -14,41 +14,6 @@ die() {
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
# first load basic.env for the template defaults
if [ -f "$script_dir/_basic.env" ]; then
set -a
source "$script_dir/_basic.env"
set +a
else
echo "Warning: _basic.env file not found at $script_dir/_basic.env. Broken template?"
return 1
fi
# now load the server specific env file
if [ -z "$1" ]; then
echo "Usage: $0 [path_to_env_file]"
return 1
fi
env_file="$1/service.env"
if [ ! -f "$env_file" ]; then
echo "Warning: service.env file not found at $1/service.env"
return 1
fi
set -a
source "$env_file"
set +a
}
grey_start() {
echo -e -n "\033[90m"
}

View File

@ -4,5 +4,5 @@
CONTAINER_PORT=8181
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="example/example"
IMAGE_REGISTRY="docker.io"
IMAGE_REPO="nginx"

View File

@ -2,8 +2,14 @@
TEMPLATE=example
# Service settings specific to this server
# (can also override anything in the _basic.env file in the template to make it specific to this server)
HOST_PORT=80
# (can also override anything in the _default.env file in the template to make it specific to this server)
HOST_PORT=60123
LOCAL_DATA_FOLDER="${HOME}/.example"
CONTAINER_NAME=example-nginx
IMAGE_TAG="latest"
# Scripts will have these environment variables set, plus those in _default.env, plus:
# SERVER, SERVICE, CONFIG_PATH
# CONFIG_PATH points to this directory!

View File

@ -6,18 +6,23 @@
# It is called with the path to the server specific env file as an argument.
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOCAL_DATA_FOLDER"
# Create local data folder if it doesn't exist
if [ -d "${LOCAL_DATA_FOLDER}" ]; then
echo "Local data folder ${LOCAL_DATA_FOLDER} exists, using existing data."
else
echo "Local data folder ${LOCAL_DATA_FOLDER} does not exist, creating..."
mkdir -p "${LOCAL_DATA_FOLDER}"
cat <<EOF > "${LOCAL_DATA_FOLDER}/index.html"
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
EOF
fi
# Test Docker
@ -33,3 +38,4 @@ _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER
bash ./start.sh $1 || die "Failed to start container ${CONTAINER_NAME}"
echo "Installation of ${CONTAINER_NAME} complete"
echo "You can access the service at http://${SERVER}:{HOST_PORT}"

View File

@ -13,5 +13,5 @@ check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:"
grey_start
docker logs --tail 100 "${CONTAINER_NAME}"
docker logs "${CONTAINER_NAME}"
grey_end

View File

@ -11,4 +11,4 @@ load_env "$1" || die "Failed to load environment variables"
# Required environment variables
# check_required_env_vars "HOST_PORT"
# echo $HOST_PORT
echo $HOST_PORT

View File

@ -14,41 +14,6 @@ die() {
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
# first load basic.env for the template defaults
if [ -f "$script_dir/_basic.env" ]; then
set -a
source "$script_dir/_basic.env"
set +a
else
echo "Warning: _basic.env file not found at $script_dir/_basic.env. Broken template?"
return 1
fi
# now load the server specific env file
if [ -z "$1" ]; then
echo "Usage: $0 [path_to_env_file]"
return 1
fi
env_file="$1/service.env"
if [ ! -f "$env_file" ]; then
echo "Warning: service.env file not found at $1"
return 1
fi
set -a
source "$env_file"
set +a
}
grey_start() {
echo -e -n "\033[90m"
}

View File

@ -1,6 +1,5 @@
#!/bin/bash
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"

View File

@ -1,11 +1,10 @@
#!/bin/bash
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:"
grey_start
docker logs --tail 100 "${CONTAINER_NAME}"
docker logs "${CONTAINER_NAME}"
grey_end

View File

@ -2,7 +2,6 @@
source "$(dirname "$0")/_common.sh"
SERVICE_CONFIG_DIR="$1"
load_env "$SERVICE_CONFIG_DIR" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "INTERVAL"

View File

@ -1,6 +1,5 @@
#!/bin/bash
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME"

View File

@ -1,6 +1,5 @@
#!/bin/bash
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME"

View File

@ -1,6 +1,5 @@
#!/bin/bash
source "$(dirname "$0")/_common.sh"
load_env "$1" || die "Failed to load environment variables"
# Required environment variables
check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"