Skip to content

Commit 4778743

Browse files
committed
add extra checks in 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 6a8b851 commit 4778743

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

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

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@ jobs:
2020
- name: Start Docker Compose stack
2121
run: |
2222
docker compose up -d --build
23-
24-
- name: Check running services
25-
run: |
26-
defined=$(docker compose config --services | sort)
27-
running=$(docker compose ps --format '{{.Service}} {{.State}}' | awk '$2 == "running" {print $1}' | sort)
28-
29-
echo "✅ Currently running:"
30-
echo "$running"
31-
32-
# Compare
33-
missing=$(comm -23 <(echo "$defined") <(echo "$running"))
34-
35-
if [ -n "$missing" ]; then
36-
echo "❌ The following services are not running:"
37-
echo "$missing"
38-
exit 1
39-
else
40-
echo "✅ All services are up and running"
41-
fi
4223
4324
- name: Wait for services with health checks to become healthy
4425
run: |
@@ -55,9 +36,42 @@ jobs:
5536
done
5637
'
5738
58-
- name: Check errors inside service logs
39+
- name: Check that services are running.
5940
run: |
60-
docker compose logs --no-color | grep -i "error": | grep -v "uvicorn\.error" && exit 1 || echo "✅ No errors detected."
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."
6175

6276
- name: Tear down Docker Compose
6377
if: always()

0 commit comments

Comments
 (0)