|
20 | 20 | - name: Start Docker Compose stack |
21 | 21 | run: | |
22 | 22 | 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 |
42 | 23 |
|
43 | 24 | - name: Wait for services with health checks to become healthy |
44 | 25 | run: | |
|
55 | 36 | done |
56 | 37 | ' |
57 | 38 |
|
58 | | - - name: Check errors inside service logs |
| 39 | + - name: Check that services are running. |
59 | 40 | 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." |
61 | 75 |
|
62 | 76 | - name: Tear down Docker Compose |
63 | 77 | if: always() |
|
0 commit comments