Big Refactor
This commit is contained in:
@ -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"
|
||||
}
|
||||
|
@ -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"
|
@ -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!
|
||||
|
||||
|
||||
|
@ -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}"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Reference in New Issue
Block a user