From 170ece8ddf466e7ea3e00a32c79942e62dec200c Mon Sep 17 00:00:00 2001 From: Sebastiaan la Fleur Date: Wed, 3 Jul 2024 14:48:41 +0200 Subject: [PATCH 1/3] 71: Only load .env if it exists on setup.sh and exit with error if any env variables from .env-template are missing. --- scripts/_load_dot_env.sh | 30 ++++++++++++++++++++++++++---- scripts/setup.sh | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/scripts/_load_dot_env.sh b/scripts/_load_dot_env.sh index 8b19274..60e3f3a 100644 --- a/scripts/_load_dot_env.sh +++ b/scripts/_load_dot_env.sh @@ -1,6 +1,28 @@ #!/bin/bash -echo "Using .env file at ${1}" -set -a -source $1 -set +a +PATH_TO_DOT_ENV=$1 + +if [ -f ${PATH_TO_DOT_ENV} ]; then + echo "Using .env file at ${PATH_TO_DOT_ENV}." + set -a + source $1 + set +a +else + echo ".env file at ${PATH_TO_DOT_ENV} does not exist. Environment variables are expected to be set in another way." +fi + +ENV_VARS=$(cat ./.env-template | sed 's/\=.*//' | grep . -) + +any_missing=false +while IFS= read -r ENV_VAR; do + if [[ -z "${!ENV_VAR}" ]]; then + echo "$ENV_VAR environment variable is not set." + any_missing=true + fi +done <<< "$ENV_VARS" + +if $any_missing ; then + echo "" + echo "ERROR: One or more environment variables were not set." + exit 1 +fi diff --git a/scripts/setup.sh b/scripts/setup.sh index a9b54d4..a563a40 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -3,6 +3,8 @@ ENV_FILE="./.env" DOCKER_COMPOSE_FILE="./docker-compose.yml" +set -e + ./scripts/setup_orchestrator_postgres_db.sh $ENV_FILE $DOCKER_COMPOSE_FILE ./scripts/setup_rabbitmq.sh $ENV_FILE $DOCKER_COMPOSE_FILE ./scripts/setup_influxdb.sh $ENV_FILE $DOCKER_COMPOSE_FILE From 3ffe31dea319c1467f972d73160215225bdc3cd2 Mon Sep 17 00:00:00 2001 From: Sebastiaan la Fleur Date: Fri, 5 Jul 2024 11:49:40 +0200 Subject: [PATCH 2/3] 71: Rename .env-template to .env.template for syntax highlighting in certain IDE's. --- .env-template => .env.template | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .env-template => .env.template (100%) diff --git a/.env-template b/.env.template similarity index 100% rename from .env-template rename to .env.template From 287f49fd915f17d3951a52e48cf8fe5fc8ca6810 Mon Sep 17 00:00:00 2001 From: Sebastiaan la Fleur Date: Fri, 5 Jul 2024 11:51:12 +0200 Subject: [PATCH 3/3] 71: Update references to .env-template to new name .env.template. --- README.md | 2 +- scripts/_load_dot_env.sh | 2 +- scripts/test_system.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1886c0a..690fd29 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The infrastructure consists of the following components: - Optimization workers ## Setup infrastructure -Copy `.env-template` to `.env` and fill with the appropriate values. +Copy `.env.template` to `.env` and fill with the appropriate values. To setup the infrastructure components (for windows run in `Git Bash`): ``` ./scripts/setup.sh diff --git a/scripts/_load_dot_env.sh b/scripts/_load_dot_env.sh index 60e3f3a..982cfb7 100644 --- a/scripts/_load_dot_env.sh +++ b/scripts/_load_dot_env.sh @@ -11,7 +11,7 @@ else echo ".env file at ${PATH_TO_DOT_ENV} does not exist. Environment variables are expected to be set in another way." fi -ENV_VARS=$(cat ./.env-template | sed 's/\=.*//' | grep . -) +ENV_VARS=$(cat ./.env.template | sed 's/\=.*//' | grep . -) any_missing=false while IFS= read -r ENV_VAR; do diff --git a/scripts/test_system.sh b/scripts/test_system.sh index c703469..b6ce826 100755 --- a/scripts/test_system.sh +++ b/scripts/test_system.sh @@ -6,7 +6,7 @@ export COMPOSE_PROJECT_NAME=omotes_system_tests ENV_FILE=".env.test" DOCKER_COMPOSE_FILE="./docker-compose.yml -f system_tests/docker-compose.override.yml" -cp .env-template ${ENV_FILE} +cp .env.template ${ENV_FILE} sed -i 's/LOG_LEVEL=[a-z]*/LOG_LEVEL=WARNING/gi' ${ENV_FILE} $DOCKER_COMPOSE --env-file ${ENV_FILE} -f $DOCKER_COMPOSE_FILE down -v