diff --git a/django/Dockerfile b/django/Dockerfile index 7f9c001..cafc8b3 100644 --- a/django/Dockerfile +++ b/django/Dockerfile @@ -35,4 +35,5 @@ COPY tts_be/ ./tts_be COPY university/ ./university COPY manage.py tasks.py ./ -CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] +COPY ./entrypoint_prod.sh ./entrypoint_prod.sh +ENTRYPOINT ["/usr/src/django/entrypoint_prod.sh"] diff --git a/django/entrypoint_prod.sh b/django/entrypoint_prod.sh new file mode 100755 index 0000000..b77e049 --- /dev/null +++ b/django/entrypoint_prod.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Waits for PostgreSQL initialization. +until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${POSTGRES_HOST}" -U "${POSTGRES_USER}" "${POSTGRES_DB}" -c 'select 1'; do + >&2 echo "PostgreSQL is unavailable - sleeping" + sleep 4 +done +>&2 echo "PostgreSQL is up - executing command" + +# Migrate the Django. +python manage.py inspectdb >university/models.py +python manage.py makemigrations +python manage.py migrate university --fake + +python manage.py runserver 0.0.0.0:8000