Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

71: Only load .env if it exists on setup.sh and exit with error if an… #72

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 26 additions & 4 deletions scripts/_load_dot_env.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/test_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading