diff --git a/app/Dockerfile b/app/Dockerfile index 639a7af..8536738 100644 --- a/app/Dockerfile +++ b/app/Dockerfile @@ -15,7 +15,6 @@ RUN mkdir -p $HOME && \ WORKDIR $APP_HOME -RUN COPY ./requirements.txt $APP_HOME RUN pip install --upgrade pip && \ pip install -r requirements.txt diff --git a/app/entrypoint.sh b/app/entrypoint.sh index 40a56e7..06e344d 100644 --- a/app/entrypoint.sh +++ b/app/entrypoint.sh @@ -1,14 +1,9 @@ #!/bin/sh echo "Waiting for postgres..." - -#while ! nc -z $SQL_HOST $SQL_PORT; do -# sleep 0.1 -#done - +python wait_for_db.py echo "PostgreSQL started" -python manage.py flush --no-input python manage.py makemigrations python manage.py migrate python manage.py collectstatic --noinput diff --git a/app/wait_for_db.py b/app/wait_for_db.py new file mode 100644 index 0000000..d955c98 --- /dev/null +++ b/app/wait_for_db.py @@ -0,0 +1,15 @@ +import socket +import time +import os + +port = int(os.environ["SQL_PORT"]) # 5432 +db_name = os.environ["SQL_DATABASE"] + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +while True: + try: + s.connect((db_name, port)) + s.close() + break + except socket.error as ex: + time.sleep(0.1) \ No newline at end of file diff --git a/docker-compose-example.yml b/docker-compose-example.yml index 9011ae3..8836296 100644 --- a/docker-compose-example.yml +++ b/docker-compose-example.yml @@ -26,7 +26,7 @@ services: container_name: bloonsworld-db image: postgres:17 volumes: - - ./.data/postgres_data:/var/lib/postgresql/data/ + - ./.data/postgres_data:/var/lib/postgresql/data/:rw environment: - POSTGRES_USER=$SQL_USER - POSTGRES_PASSWORD=$SQL_PASSWORD