Commit dfcb5f25 authored by Evili del Rio's avatar Evili del Rio

Add dj-database-url to parse DATABASE_URLs

parent 5bfb6965
......@@ -18,7 +18,7 @@ RUN apk update && \
${dev_packages} && \
pip install gunicorn \
"django${django_version}" \
django-health-check \
django-health-check dj-database-url \
psycopg2-binary mysql-connector whitenoise[brotli] && \
apk del ${dev_packages} && \
apk add ${lib_packages} && \
......
......@@ -43,7 +43,18 @@ export DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE:-${settings_found}}
## Find .wsgi
DJANGO_WSGI=${DJANGO_WSGI:-$(basename $(find . -maxdepth 2 -type f -name wsgi.py | head -1|awk -F/ '{print $2"."$3}') .py)}
DJANGO_LOG_LEVEL=${DJANGO_LOG_LEVEL:-info}
export DJANGO_LOG_LEVEL=${DJANGO_LOG_LEVEL:-info}
# Select POSTGRES_HOST (if any and no other database definition available):
if [[ -z "${DJANGO_DATABASES}" && -z "${DATABASE_URL}" && -z "${POSTGRES_HOST}" ]]
then
p_host = $(/bin/printenv | /bin/egrep -e 'POSTGRES.*HOST' | /usr/bin/sort | /usr/bin/head -1)
if [[ -n ${p_host} ]]
then
export POSTGRES_HOST=${p_host}
fi
fi
# Populate settings with default, and override them with environment variables
cat > /settings/final_settings.py <<EOF
......
......@@ -23,6 +23,7 @@
DEBUG = False
import os
import dj_database_url
from django.conf import global_settings as __global_settings
......@@ -49,18 +50,23 @@ for st,val in __settings.items():
else:
exec(st+" = "+env_setting)
if os.getenv('DJANGO_DATABASES', None) is None:
__PROJECT_NAME = os.getenv('DJANGO__PROJECT_NAME',
__default_settings.__package__.split('.')[0])
DATABASES = {
'default': {
'ENGINE': os.getenv('DJANGO_DATABASE_ENGINE','django.db.backends.postgresql'),
'HOST': os.getenv('DJANGO_DATABASE_HOST', os.getenv('POSTGRES_HOST', 'postgres')),
'NAME': os.getenv('DJANGO_DATABASE_NAME', os.getenv('POSTGRES_DB', __PROJECT_NAME)),
'USER': os.getenv('DJANGO_DATABASE_USER', os.getenv('POSTGRES_USER', __PROJECT_NAME)),
'PASSWORD' : os.getenv('DJANGO_DATABASE_PASSWORD', os.getenv('POSTGRES_PASSWORD', __PROJECT_NAME)),
if os.getenv('DATABASE_URL', None) is not None:
DATABASES['default'] = dj_database_url.config(conn_max_age=600)
else:
__PROJECT_NAME = os.getenv('DJANGO__PROJECT_NAME',
__default_settings.__package__.split('.')[0])
DATABASES = {
'default': {
'ENGINE': os.getenv('DJANGO_DATABASE_ENGINE','django.db.backends.postgresql'),
'HOST': os.getenv('DJANGO_DATABASE_HOST', os.getenv('POSTGRES_HOST', 'postgres')),
'NAME': os.getenv('DJANGO_DATABASE_NAME', os.getenv('POSTGRES_DB', __PROJECT_NAME)),
'USER': os.getenv('DJANGO_DATABASE_USER', os.getenv('POSTGRES_USER', __PROJECT_NAME)),
'PASSWORD' : os.getenv('DJANGO_DATABASE_PASSWORD', os.getenv('POSTGRES_PASSWORD', __PROJECT_NAME)),
}
}
}
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment