Skip to content

Commit f82614d

Browse files
committed
Add checks to the docker compose test github workflow
- add a github workflow step after waiting for the health check, to check all services are running and didnt exit unexpectedly. - add a github workflow step to check for error logs.
1 parent e1f2c9d commit f82614d

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

.github/workflows/docker-compose-test.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
- name: Start Docker Compose stack
2121
run: |
2222
docker compose up -d --build
23-
docker compose ps
2423
2524
- name: Wait for services with health checks to become healthy
2625
run: |
@@ -37,6 +36,43 @@ jobs:
3736
done
3837
'
3938
39+
- name: Check that services are running.
40+
run: |
41+
errors=0
42+
docker compose ps --all --format "{{.Name}} {{.Service}} {{.State}}" | while read -r line; do
43+
name=$(echo "$line" | awk '{print $1}')
44+
service=$(echo "$line" | awk '{print $2}')
45+
state=$(echo "$line" | awk '{print $3}')
46+
health=$(echo "$line" | awk '{print $4}')
47+
48+
if [ "$state" = "running" ]; then
49+
if [ "$health" = "unhealthy" ]; then
50+
echo "❌ $service ($name) is running but unhealthy: $health"
51+
errors=$((errors+1))
52+
elif [ "$health" = "healthy" ]; then
53+
echo "🟢 $service ($name) is running, health: $health"
54+
else
55+
echo "🟢 $service ($name) is running, health: no health check"
56+
fi
57+
elif [ "$state" = "exited" ]; then
58+
echo "⚪ $service ($name) has exited normally (exit 0)"
59+
else
60+
echo "❌ $service ($name) failed or exited unexpectedly: state=$state, health=$health"
61+
docker compose ps --all
62+
errors=$((errors+1))
63+
fi
64+
done
65+
66+
if [ "$errors" -gt 0 ]; then
67+
echo "❌ $errors service(s) failed or unhealthy"
68+
exit 1
69+
else
70+
echo "✅ All services are running or exited normally"
71+
fi
72+
73+
- name: Check errors inside service logs
74+
run: docker compose logs --no-color | grep -v "uvicorn\.error" | grep -i "error" && exit 1 || echo "No errors detected."
75+
4076
- name: Tear down Docker Compose
4177
if: always()
4278
run: docker compose down -v

0 commit comments

Comments
 (0)