mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 11:47:56 +01:00
Add env vars to docker-compose and improve env check
This commit is contained in:
@@ -4,8 +4,7 @@ POSTGRES_USER=yourusernamehere
|
|||||||
POSTGRES_PASSWORD=yourpasswordhere
|
POSTGRES_PASSWORD=yourpasswordhere
|
||||||
|
|
||||||
APP_NAME="You App Name Here"
|
APP_NAME="You App Name Here"
|
||||||
|
SHOW_LOGO=yes
|
||||||
EMAIL_CONFIRMATION=0
|
|
||||||
|
|
||||||
SHOW_LOGO=1
|
|
||||||
POSTS_PER_PAGE=15
|
POSTS_PER_PAGE=15
|
||||||
|
|
||||||
|
EMAIL_CONFIRMATION=no
|
||||||
43
check-env.sh
43
check-env.sh
@@ -1,19 +1,36 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e # Abort on error
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
function check_env_vars () {
|
|
||||||
for name; do
|
|
||||||
: ${!name:?$name must not be empty}
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
# Check if .env file is present
|
||||||
if [ ! -f .env ]; then
|
if [ ! -f .env ]; then
|
||||||
echo 'A .env file must be present.'
|
echo "A .env file must be present. Please create a .env file in the root directory."
|
||||||
|
exit 1
|
||||||
|
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
|
exit 2
|
||||||
fi
|
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
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ module App
|
|||||||
end
|
end
|
||||||
|
|
||||||
def email_confirmation?
|
def email_confirmation?
|
||||||
ENV["EMAIL_CONFIRMATION"] == "1"
|
ENV["EMAIL_CONFIRMATION"] == "yes"
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_logo?
|
def show_logo?
|
||||||
ENV["SHOW_LOGO"] == "1"
|
ENV["SHOW_LOGO"] == "yes"
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts_per_page
|
def posts_per_page
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
# and recreated between test runs. Don't rely on the data there!
|
# and recreated between test runs. Don't rely on the data there!
|
||||||
|
|
||||||
# Set up default environment variables
|
# Set up default environment variables
|
||||||
ENV["EMAIL_CONFIRMATION"] = "0"
|
ENV["EMAIL_CONFIRMATION"] = "no"
|
||||||
ENV["POSTS_PER_PAGE"] = "8"
|
ENV["POSTS_PER_PAGE"] = "15"
|
||||||
|
|
||||||
Rails.application.configure do
|
Rails.application.configure do
|
||||||
# Settings specified here will take precedence over those in config/application.rb.
|
# Settings specified here will take precedence over those in config/application.rb.
|
||||||
|
|||||||
@@ -12,9 +12,12 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- UPDATE=0
|
- UPDATE=0
|
||||||
- ENVIRONMENT
|
- ENVIRONMENT
|
||||||
- APP_NAME
|
|
||||||
- POSTGRES_USER
|
- POSTGRES_USER
|
||||||
- POSTGRES_PASSWORD
|
- POSTGRES_PASSWORD
|
||||||
|
- EMAIL_CONFIRMATION
|
||||||
|
- APP_NAME
|
||||||
|
- SHOW_LOGO
|
||||||
|
- POSTS_PER_PAGE
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
Reference in New Issue
Block a user