automatically run migrations on docker container start by default

This commit is contained in:
Jenny Danzmayr 2023-11-12 16:21:46 +01:00
parent ddfa684c97
commit ebac0e5f77
2 changed files with 13 additions and 0 deletions

View file

@ -67,6 +67,7 @@ COPY --chown=root:root --chmod=0755 /docker/entrypoint.sh /usr/bin/entrypoint
ENV C3NAV_DEBUG="" \ ENV C3NAV_DEBUG="" \
C3NAV_LOGLEVEL="info" \ C3NAV_LOGLEVEL="info" \
C3NAV_DATA_DIR="/data" \ C3NAV_DATA_DIR="/data" \
C3NAV_AUTOMIGRATE="yes" \
MPLBACKEND="agg" \ MPLBACKEND="agg" \
UWSGI_WORKERS="8" UWSGI_WORKERS="8"

View file

@ -5,8 +5,17 @@ cd /app
# enable python virtual env # enable python virtual env
. /app/env/bin/activate . /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 case "$1" in
web) web)
automigrate
exec /app/env/bin/uwsgi --master \ exec /app/env/bin/uwsgi --master \
--wsgi "c3nav.wsgi" \ --wsgi "c3nav.wsgi" \
--pythonpath "/app/src" \ --pythonpath "/app/src" \
@ -15,6 +24,7 @@ web)
--http "0.0.0.0:8000" --http "0.0.0.0:8000"
;; ;;
webstatic) webstatic)
automigrate
exec /app/env/bin/uwsgi --master \ exec /app/env/bin/uwsgi --master \
--wsgi "c3nav.wsgi" \ --wsgi "c3nav.wsgi" \
--pythonpath "/app/src" \ --pythonpath "/app/src" \
@ -25,9 +35,11 @@ webstatic)
--http "0.0.0.0:8000" --http "0.0.0.0:8000"
;; ;;
web-async) web-async)
automigrate
exec python -m uvicorn --host 0.0.0.0 --proxy-headers --no-server-header ${*:2} c3nav.asgi:application exec python -m uvicorn --host 0.0.0.0 --proxy-headers --no-server-header ${*:2} c3nav.asgi:application
;; ;;
webstatic-async) webstatic-async)
automigrate
exec python -m uvicorn --host 0.0.0.0 --proxy-headers --no-server-header ${*:2} c3nav.asgi:static_app exec python -m uvicorn --host 0.0.0.0 --proxy-headers --no-server-header ${*:2} c3nav.asgi:static_app
;; ;;
worker) worker)