Skip to content

Commit e1f2c9d

Browse files
committed
Add github workflow to validate docker compose and check services are healthy
1 parent a105e19 commit e1f2c9d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Docker Compose Validation
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
validate-compose:
10+
name: Spin up and test health of services
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
20+
- name: Start Docker Compose stack
21+
run: |
22+
docker compose up -d --build
23+
docker compose ps
24+
25+
- name: Wait for services with health checks to become healthy
26+
run: |
27+
timeout 180 bash -c '
28+
while true; do
29+
unhealthy=$(docker compose ps --format "{{.Service}} {{.Health}}" | awk '\''$2 != "healthy" && $2 != "" {print $1}'\'')
30+
if [ -z "$unhealthy" ]; then
31+
echo "✅ All services with health checks are healthy!"
32+
break
33+
fi
34+
echo "Still waiting for unhealthy services:"
35+
echo "$unhealthy"
36+
sleep 5
37+
done
38+
'
39+
40+
- name: Tear down Docker Compose
41+
if: always()
42+
run: docker compose down -v

0 commit comments

Comments
 (0)