From 8a792a17a6dbb1ea0c9071273e7cf9dbbe5e5bab Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Wed, 19 Jun 2019 17:59:35 +0200 Subject: [PATCH] Add entrypoint script with wait function for db. --- app/Dockerfile | 6 ++++++ app/django-entrypoint.sh | 6 ++++++ docker-compose.yml | 8 ++++---- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 app/django-entrypoint.sh diff --git a/app/Dockerfile b/app/Dockerfile index 1612410..8a293af 100755 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -17,4 +17,10 @@ RUN pipenv install --skip-lock --system --dev # copy project COPY . /usr/src/app/ +# add wait for it +RUN git clone https://github.com/vishnubob/wait-for-it.git /wait-for-it +RUN chmod a+x /wait-for-it/wait-for-it.sh +# add entry point +ADD ./django-entrypoint.sh /django-entrypoint.sh +RUN chmod a+x /django-entrypoint.sh diff --git a/app/django-entrypoint.sh b/app/django-entrypoint.sh new file mode 100644 index 0000000..12b8972 --- /dev/null +++ b/app/django-entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/bash -x + +python manage.py collectstatic --noinput +python manage.py makemigrations --noinput +python manage.py migrate --noinput +exec "$@" diff --git a/docker-compose.yml b/docker-compose.yml index 1687b61..95cdf08 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,6 @@ version: '3.7' services: web: build: ./app - command: gunicorn bundesdata_app.wsgi:application --bind 0.0.0.0:8000 volumes: - ./app/:/usr/src/app/ - ./input_volume/:/usr/src/app/input_data @@ -12,12 +11,13 @@ services: - 8000 depends_on: - db + command: bash -c "/wait-for-it/wait-for-it.sh db:5432 --strict --timeout=0 -- bash django-entrypoint.sh && gunicorn bundesdata_app.wsgi:application --bind 0.0.0.0:8000" db: image: postgres:11.2 environment: - - POSTGRES_USER=databaseUserName - - POSTGRES_PASSWORD=totalSecurePassword - - POSTGRES_DB=databaseName + - POSTGRES_USER=bundesdata_app_user + - POSTGRES_PASSWORD=v3ry53cr3t + - POSTGRES_DB=bundesdata_db volumes: - ./postgres_data:/var/lib/postgresql/data/ nginx: