From 7491218ccbd5cac76158dbfcf6fd83962d8346c1 Mon Sep 17 00:00:00 2001
From: Tim Neumann <neumantm@fius.informatik.uni-stuttgart.de>
Date: Sat, 13 Mar 2021 18:20:15 +0100
Subject: [PATCH] Add the ability to customize DJANGO settings in container

---
 .docker/entrypoint.sh | 8 ++++++++
 Dockerfile            | 2 ++
 INSTALL.md            | 7 +++++++
 3 files changed, 17 insertions(+)

diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh
index ecd068c6..e11fcd4b 100644
--- a/.docker/entrypoint.sh
+++ b/.docker/entrypoint.sh
@@ -32,6 +32,14 @@ if [ "$DJANGO_SUPERUSER_PASSWORD" != "" ] ;then
   ./manage.py createsuperuser --noinput
 fi
 
+env | while IFS= read -r line; do
+    value=${line#*=}
+    name=${line%%=*}
+    case $name in EXTRA_DJANGO_SETTING*)
+      echo -e "$value" > "./AKPlanning/settings/$name.py"
+    esac
+done
+
 ./manage.py collectstatic --noinput
 ./manage.py compilemessages -l de_DE
 uwsgi --ini .docker/uwsgi.ini
diff --git a/Dockerfile b/Dockerfile
index 8743d273..32041dcb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,5 +9,7 @@ RUN pip install -r requirements.txt -r .docker/extra_requirements.txt
 
 ENV DJANGO_SETTINGS_MODULE=AKPlanning.settings_production
 
+RUN mkdir /app/AKPlanning/settings
+
 EXPOSE 3035
 CMD ["sh", "/app/.docker/entrypoint.sh"]
diff --git a/INSTALL.md b/INSTALL.md
index 2c22591d..84e5cd8d 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -145,6 +145,7 @@ services:
       DJANGO_SUPERUSER_USERNAME: admin
       DJANGO_SUPERUSER_EMAIL: admin@example.com
       DJANGO_SUPERUSER_PASSWORD: supersecret
+      EXTRA_DJANGO_SETTING_FOO: DJANGO_FOO = True\nDJANGO_BAR = False
     depends_on:
       - mariadb
     networks:
@@ -226,6 +227,12 @@ Using the environment variables `DJANGO_SUPERUSER_{USERNAME,EMAIL,PASSWORD}`.
 The second way is to run the following command after the container has started:
 `docker-compose exec -it akplanning-server ./manage.py createsuperuser`
 
+### Extra djnago settings
+For simple cases you can pass environment variables starting with `EXTRA_DJANGO_SETTING`.
+The content of such variables is written into python files, which are loaded as settings.
+
+For more complex scenarios you can also mount a docker volume to `/app/AKPlanning/settings` and add any number of python files to the volume.
+
 ## Updates
 
 To update the setup to the current version on the main branch of the repository use the update script ``Utils/update.sh`` or ``Utils/update.sh --prod`` in production.
-- 
GitLab