Skip to content

Commit efaa9a6

Browse files
committed
feat(compose): ensure postgres server is ready
introduce a healthcheck for the postgres service to ensure the web and pgweb services do not start until the postgres server is ready. this ensures we don't get an Admin connection to PostgreSQL fail for web and an Error: connection refused error for pgweb when there is no postgres service already running when web or pgweb are started. This usually happens when the containers are first created.
1 parent 7288a6b commit efaa9a6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

compose.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ services:
88
image: caltrans/pems:web
99
command: ["-c", "bin/setup.sh && exec bin/start.sh"]
1010
depends_on:
11-
- postgres
11+
postgres:
12+
condition: service_healthy
1213
env_file: .env
1314
ports:
1415
- "${DJANGO_LOCAL_PORT:-8000}:8000"
@@ -34,6 +35,12 @@ services:
3435
- POSTGRES_DB
3536
- POSTGRES_USER
3637
- POSTGRES_PASSWORD
38+
healthcheck:
39+
test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB}", "-U", "${POSTGRES_USER}"]
40+
interval: 10s
41+
timeout: 60s
42+
retries: 6
43+
start_period: 10s
3744
ports:
3845
- "${POSTGRES_PORT:-5432}:5432"
3946
volumes:
@@ -45,7 +52,8 @@ services:
4552
ports:
4653
- "${PGWEB_PORT:-8081}:8081"
4754
depends_on:
48-
- postgres
55+
postgres:
56+
condition: service_healthy
4957
environment:
5058
- PGWEB_DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOSTNAME}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable
5159

0 commit comments

Comments
 (0)