Added proper wait for database and removed the wipe entire databases thingy LOL

This commit is contained in:
Walter 2025-02-20 23:29:29 +01:00
parent 7667e54635
commit 39a9566e40
4 changed files with 17 additions and 8 deletions

View File

@ -15,7 +15,6 @@ RUN mkdir -p $HOME && \
WORKDIR $APP_HOME WORKDIR $APP_HOME
RUN
COPY ./requirements.txt $APP_HOME COPY ./requirements.txt $APP_HOME
RUN pip install --upgrade pip && \ RUN pip install --upgrade pip && \
pip install -r requirements.txt pip install -r requirements.txt

View File

@ -1,14 +1,9 @@
#!/bin/sh #!/bin/sh
echo "Waiting for postgres..." echo "Waiting for postgres..."
python wait_for_db.py
#while ! nc -z $SQL_HOST $SQL_PORT; do
# sleep 0.1
#done
echo "PostgreSQL started" echo "PostgreSQL started"
python manage.py flush --no-input
python manage.py makemigrations python manage.py makemigrations
python manage.py migrate python manage.py migrate
python manage.py collectstatic --noinput python manage.py collectstatic --noinput

15
app/wait_for_db.py Normal file
View File

@ -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)

View File

@ -26,7 +26,7 @@ services:
container_name: bloonsworld-db container_name: bloonsworld-db
image: postgres:17 image: postgres:17
volumes: volumes:
- ./.data/postgres_data:/var/lib/postgresql/data/ - ./.data/postgres_data:/var/lib/postgresql/data/:rw
environment: environment:
- POSTGRES_USER=$SQL_USER - POSTGRES_USER=$SQL_USER
- POSTGRES_PASSWORD=$SQL_PASSWORD - POSTGRES_PASSWORD=$SQL_PASSWORD