Skip to content

Commit 67143fd

Browse files
committed
fix: use healthcheck for postgres instead of pinging
1 parent fd309d6 commit 67143fd

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

config/docker/docker-compose.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ services:
22
othello_postgres:
33
container_name: othello_postgres
44
image: postgres:latest
5-
ports:
6-
- "5432:5432"
75
environment:
86
- POSTGRES_DB=othello
97
- POSTGRES_USER=othello
108
- POSTGRES_PASSWORD=pwd
119
volumes:
12-
- "othello_pgdata:/var/lib/postgresql"
10+
- othello_pgdata:/var/lib/postgresql
11+
ports:
12+
- "5432:5432"
1313
networks:
1414
- othello_network
15+
healthcheck:
16+
test: ["CMD-SHELL", "pg_isready -U othello -d othello"]
17+
interval: 5s
18+
timeout: 5s
19+
retries: 5
1520
othello_redis:
1621
container_name: othello_redis
1722
image: redis:latest
@@ -28,8 +33,10 @@ services:
2833
ports:
2934
- "8000:8000"
3035
depends_on:
31-
- othello_postgres
32-
- othello_redis
36+
othello_postgres:
37+
condition: service_healthy
38+
othello_redis:
39+
condition: service_started
3340
volumes:
3441
- ../../:/app
3542
working_dir: /app
@@ -45,8 +52,10 @@ services:
4552
container_name: othello_celery
4653
image: othello_django
4754
depends_on:
48-
- othello_postgres
49-
- othello_redis
55+
othello_postgres:
56+
condition: service_healthy
57+
othello_redis:
58+
condition: service_started
5059
volumes:
5160
- ../../:/app
5261
working_dir: /app
@@ -62,8 +71,10 @@ services:
6271
container_name: othello_gamequeue
6372
image: othello_django
6473
depends_on:
65-
- othello_postgres
66-
- othello_redis
74+
othello_postgres:
75+
condition: service_healthy
76+
othello_redis:
77+
condition: service_started
6778
volumes:
6879
- ../../:/app
6980
working_dir: /app

config/docker/entrypoint.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ set -e
33

44
uv sync
55
uv run manage.py collectstatic --noinput
6-
7-
until (PGPASSWORD=pwd psql -h "othello_postgres" -U "othello" -c '\q') 2> /dev/null; do
8-
>&2 echo "waiting for postgres"
9-
sleep 1
10-
done
11-
126
uv run manage.py makemigrations --noinput
137
uv run manage.py migrate
148
uv run manage.py shell -c "

othello/settings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"default": {
2121
"BACKEND": "channels_redis.core.RedisChannelLayer",
2222
"CONFIG": {
23-
"hosts": [("localhost", 6379)],
23+
"hosts": [("othello_redis", 6379)],
2424
"capacity": 1500,
2525
"expiry": 2,
2626
},

0 commit comments

Comments
 (0)