From 16bd390c3641d68eb1d813c092a8e1bf0b72c278 Mon Sep 17 00:00:00 2001 From: Tai Lee Date: Tue, 4 Aug 2020 15:25:15 +1000 Subject: [PATCH] Require a `.env` file for `go.sh` runtime. Now that Docker Compose can parse Bash compatible env files, we can share a common file between Docker and `go.sh` runtimes. This replaces `.env.local`, and behaves more consistently to production Docker runtimes where env vars may be set on the container, before `entrypoint.sh` runs. --- project_template/.env.example | 10 ++++++++++ project_template/.env.local.sample | 4 ---- project_template/docker-compose.yml | 1 + project_template/go.sh | 8 ++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 project_template/.env.example delete mode 100644 project_template/.env.local.sample diff --git a/project_template/.env.example b/project_template/.env.example new file mode 100644 index 0000000..2d92dc2 --- /dev/null +++ b/project_template/.env.example @@ -0,0 +1,10 @@ +# These variables are sourced by 'go.sh', used in 'docker-compose.yml', and passed +# through to the 'django' service via 'env_file'. + +export COMPOSE_PROJECT_NAME='project_template-develop' +export DOTENV='develop' +export IMAGE_TAG='master' +export TRANSCRYPT_PASSWORD='' # Get from 1Password + +# export SRC_PGDATABASE='initial_data.sql' +# export WITHOUT_COVERAGE=1 diff --git a/project_template/.env.local.sample b/project_template/.env.local.sample deleted file mode 100644 index 92f8967..0000000 --- a/project_template/.env.local.sample +++ /dev/null @@ -1,4 +0,0 @@ -# export BASE_SETTINGS="$BASE_SETTINGS email_bandit.py" -export DOTENV='develop' -export TRANSCRYPT_PASSWORD='' # Get from 1Password -# export WITHOUT_COVERAGE=1 diff --git a/project_template/docker-compose.yml b/project_template/docker-compose.yml index f142ef1..bb79ea8 100644 --- a/project_template/docker-compose.yml +++ b/project_template/docker-compose.yml @@ -8,6 +8,7 @@ services: # - elasticsearch - postgres - redis + env_file: .env environment: DOTENV: ${DOTENV:-develop} # ELASTICSEARCH_ADDRESS: elasticsearch:9200 diff --git a/project_template/go.sh b/project_template/go.sh index 6817161..4a6a53a 100755 --- a/project_template/go.sh +++ b/project_template/go.sh @@ -45,11 +45,19 @@ if [[ "$CUR_PYTHON_VERSION" != "Python $REQ_PYTHON_VERSION" ]]; then >&2 echo "ERROR: Missing Python version: $REQ_PYTHON_VERSION" fi +if [[ ! -f .env ]]; then + MISSING=1 + >&2 echo "ERROR: Missing '.env' file. Copy '.env.example' and update." +fi + # Abort if any dependencies are missing. if [[ -n "${MISSING+1}" ]]; then exit 1 fi +# Configure environment. +source .env + # Get absolute project directory from the location of this script. # See: http://stackoverflow.com/a/4774063 export PROJECT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd -P)