@@ -26,13 +26,43 @@ jobs:
26
26
- name : Docker Compose Logs
27
27
run : docker compose logs
28
28
29
- # 2) Check if any containers have exited with an error
29
+ # 2) Check if any containers have exited with an error or are unhealthy
30
30
- name : Check containers status
31
31
run : |
32
+ # Create a flag to track if we found any issues
33
+ FOUND_ISSUES=0
34
+
32
35
# If any container's STATUS shows "Exit" or "exited", fail
33
- # because that means the container died or crashed.
34
36
if docker compose ps | grep -q 'Exit'; then
35
37
echo "A container has exited with an error."
38
+ FOUND_ISSUES=1
39
+ fi
40
+
41
+ # Check exit codes for any stopped containers
42
+ for container in $(docker compose ps -q); do
43
+ if [[ $(docker inspect --format='{{.State.Status}}' $container) == "exited" ]]; then
44
+ EXIT_CODE=$(docker inspect --format='{{.State.ExitCode}}' $container)
45
+ if [[ $EXIT_CODE -ne 0 ]]; then
46
+ echo "Container $container exited with non-zero exit code: $EXIT_CODE"
47
+ FOUND_ISSUES=1
48
+ fi
49
+ fi
50
+ done
51
+
52
+ # Check logs for panic messages
53
+ if docker compose logs | grep -i "panic" | grep -v "panic = 'abort'"; then
54
+ echo "Found panic messages in logs."
55
+ FOUND_ISSUES=1
56
+ fi
57
+
58
+ # Check logs for ERROR messages
59
+ if docker compose logs | grep -i "ERROR"; then
60
+ echo "Found ERROR messages in logs."
61
+ FOUND_ISSUES=1
62
+ fi
63
+
64
+ # Fail the build if any issues were found
65
+ if [[ $FOUND_ISSUES -eq 1 ]]; then
36
66
exit 1
37
67
fi
38
68
0 commit comments