@@ -26,13 +26,43 @@ jobs:
2626 - name : Docker Compose Logs
2727 run : docker compose logs
2828
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
3030 - name : Check containers status
3131 run : |
32+ # Create a flag to track if we found any issues
33+ FOUND_ISSUES=0
34+
3235 # If any container's STATUS shows "Exit" or "exited", fail
33- # because that means the container died or crashed.
3436 if docker compose ps | grep -q 'Exit'; then
3537 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
3666 exit 1
3767 fi
3868
0 commit comments