Skip to content

Commit 08f5de5

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 25faff1 commit 08f5de5

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
@@ -29,6 +29,11 @@ services:
2929
ports:
3030
# 5432 may already in use by another PostgreSQL on host
3131
- "5433:5432"
32+
healthcheck:
33+
test: ["CMD-SHELL", "pg_isready"]
34+
interval: 5s
35+
timeout: 5s
36+
retries: 10
3237

3338
redis:
3439
image: redis:4.0

0 commit comments

Comments
 (0)