Skip to content

Commit f3f5997

Browse files
committed
Wait for Postgres
Add healthcheck to docker-compose.yml Add a script to wait for DB healthcheck to pass Stop waiting for DB after 1 minute
1 parent 47639c5 commit f3f5997

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.github/workflows/dev-setup.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ jobs:
2020
- run: |
2121
# `make serve` daemonized
2222
docker-compose up -d
23+
- run: docker-compose ps
24+
- run: ./bin/wait-for-db.sh
2325
- run: make initdb
2426
- run: make tests

bin/wait-for-db.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
# healthy
4+
# unhealthy
5+
# starting
6+
7+
CONTAINER=warehouse_db_1
8+
check() {
9+
docker inspect --format "{{.State.Health.Status }}" $CONTAINER
10+
}
11+
12+
while [[ "$STATUS" != "healthy" ]]
13+
do
14+
STATUS=$(check)
15+
echo "$STATUS ${SECONDS}"
16+
(( SECONDS > 60 )) && exit 1
17+
sleep 3
18+
done

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ services:
2828
ports:
2929
# 5432 may already in use by another PostgreSQL on host
3030
- "5433:5432"
31+
healthcheck:
32+
test: ["CMD-SHELL", "pg_isready"]
33+
interval: 5s
34+
timeout: 5s
35+
retries: 10
3136

3237
redis:
3338
image: redis:4.0

0 commit comments

Comments
 (0)