From ebac0e5f77ac4cbf43116505bc0c11a424c3d405 Mon Sep 17 00:00:00 2001 From: Jenny Danzmayr Date: Sun, 12 Nov 2023 16:21:46 +0100 Subject: [PATCH] automatically run migrations on docker container start by default --- docker/Dockerfile | 1 + docker/entrypoint.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index b0e6e912..f9b35fbc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -67,6 +67,7 @@ COPY --chown=root:root --chmod=0755 /docker/entrypoint.sh /usr/bin/entrypoint ENV C3NAV_DEBUG="" \ C3NAV_LOGLEVEL="info" \ C3NAV_DATA_DIR="/data" \ + C3NAV_AUTOMIGRATE="yes" \ MPLBACKEND="agg" \ UWSGI_WORKERS="8" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a30bb8ed..44d96f90 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -5,8 +5,17 @@ cd /app # enable python virtual env . /app/env/bin/activate +automigrate() { + AUTOMIGRATE="${C3NAV_AUTOMIGRATE:no}" + echo "Running migrations as automigrate is enabled. Set \"C3NAV_AUTOMIGRATE\" to \"no\" or \"false\" to disable." + if [[ "$AUTOMIGRATE" == "yes" || "$AUTOMIGRATE" == "true" ]]; then + python manage.py migrate + fi +} + case "$1" in web) + automigrate exec /app/env/bin/uwsgi --master \ --wsgi "c3nav.wsgi" \ --pythonpath "/app/src" \ @@ -15,6 +24,7 @@ web) --http "0.0.0.0:8000" ;; webstatic) + automigrate exec /app/env/bin/uwsgi --master \ --wsgi "c3nav.wsgi" \ --pythonpath "/app/src" \ @@ -25,9 +35,11 @@ webstatic) --http "0.0.0.0:8000" ;; web-async) + automigrate exec python -m uvicorn --host 0.0.0.0 --proxy-headers --no-server-header ${*:2} c3nav.asgi:application ;; webstatic-async) + automigrate exec python -m uvicorn --host 0.0.0.0 --proxy-headers --no-server-header ${*:2} c3nav.asgi:static_app ;; worker)