Add env vars to docker-compose and improve env check

This commit is contained in:
riggraz
2019-09-24 18:57:42 +02:00
parent 9bdbcef0ab
commit 7d50454d14
5 changed files with 41 additions and 22 deletions

View File

@@ -4,8 +4,7 @@ POSTGRES_USER=yourusernamehere
POSTGRES_PASSWORD=yourpasswordhere
APP_NAME="You App Name Here"
SHOW_LOGO=yes
POSTS_PER_PAGE=15
EMAIL_CONFIRMATION=0
SHOW_LOGO=1
POSTS_PER_PAGE=15
EMAIL_CONFIRMATION=no

View File

@@ -1,19 +1,36 @@
#!/bin/bash
set -e # Abort on error
function check_env_vars () {
for name; do
: ${!name:?$name must not be empty}
done
}
# Exit immediately if a command exits with a non-zero status.
set -e
# Check if .env file is present
if [ ! -f .env ]; then
echo 'A .env file must be present.'
exit 2
echo "A .env file must be present. Please create a .env file in the root directory."
exit 1
fi
if ! check_env_vars "ENVIRONMENT" "APP_NAME" "POSTGRES_USER" "POSTGRES_PASSWORD"; then
echo 'Some variables are not set in .env, please refer to script/check-env.sh for the list'
exit 4
fi
# Array of environment variables that must be present
env_vars=(
"ENVIRONMENT" \
"POSTGRES_USER" \
"POSTGRES_PASSWORD" \
"EMAIL_CONFIRMATION" \
"APP_NAME" \
"SHOW_LOGO" \
"POSTS_PER_PAGE" \
)
# Check each one
n_of_errors=0
for each in "${env_vars[@]}"; do
if ! [[ -v $each ]]; then
echo "$each is not set in .env file"
n_of_errors=$((n_of_errors+1))
fi
done
if [ $n_of_errors -gt 0 ]; then
echo "You need to set these ${n_of_errors} variables in your .env file."
echo "See .env-example for a configuration example."
exit 2
fi

View File

@@ -21,11 +21,11 @@ module App
end
def email_confirmation?
ENV["EMAIL_CONFIRMATION"] == "1"
ENV["EMAIL_CONFIRMATION"] == "yes"
end
def show_logo?
ENV["SHOW_LOGO"] == "1"
ENV["SHOW_LOGO"] == "yes"
end
def posts_per_page

View File

@@ -4,8 +4,8 @@
# and recreated between test runs. Don't rely on the data there!
# Set up default environment variables
ENV["EMAIL_CONFIRMATION"] = "0"
ENV["POSTS_PER_PAGE"] = "8"
ENV["EMAIL_CONFIRMATION"] = "no"
ENV["POSTS_PER_PAGE"] = "15"
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

View File

@@ -12,9 +12,12 @@ services:
environment:
- UPDATE=0
- ENVIRONMENT
- APP_NAME
- POSTGRES_USER
- POSTGRES_PASSWORD
- EMAIL_CONFIRMATION
- APP_NAME
- SHOW_LOGO
- POSTS_PER_PAGE
volumes:
- .:/app
ports: