Allow for modular setting of database connection string

This commit is contained in:
AneurinPrice committed 2024-04-03 23:51:25 +01:00
1 parent 53bc0675c4
commit e7fa578074
2 files changed
+30

No files matched your search

+24
View File
@@ -4,6 +4,30 @@ if [ -f tmp/pids/server.pid ]; then
rm tmp/pids/server.pid
fi
# List of required variables to be set for modular database string generation
MODULAR_STRING_COMPONENTS=(
"DATABASE_HOST"
# "DATABASE_PORT"
"DATABASE_USER"
"DATABASE_PASSWORD"
"DATABASE_NAME"
)
# Check if the required vars are set, if they are, generate the URL string, else exit with error code 1
echo "Executing database url substitution hack"
env
if [ -z ${DATABASE_URL} ]; then
echo "DATABASE_URL appears to be empty, proceeding with modular string generation"
for VAR in ${MODULAR_STRING_COMPONENTS}; do
if [ -z "${VAR}" ]; then
echo "${VAR} = ${!VAR}"
echo "${VAR} is unset" && exit 1
fi
done
echo "Required variables check passed"
DATABASE_URL="postgresql://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?pool=5"
fi
echo "Preparing database..."
bundle exec rails db:prepare:with_data
+6
View File
@@ -11,6 +11,12 @@ services:
DATABASE_URL: postgresql://manyfold:password@db/manyfold?pool=5
SECRET_KEY_BASE: a_nice_long_random_string
REDIS_URL: redis://redis:6379/1
# or
DATABASE_HOST: db
DATABASE_USER: manyfold
DATABASE_PASSWORD: password
DATABASE_NAME: manyfold
# For details of other optional environment variables, including features such
# as multiuser mode, visit https://manyfold.app/sysadmin/configuration.html
depends_on: