@@ -37,21 +37,26 @@ jobs:
3737 run : ./mvnw clean verify
3838
3939 health-check :
40+ name : Health Check on Services
4041 runs-on : ubuntu-latest
4142 steps :
4243 - name : Checkout repository and submodules
4344 uses : actions/checkout@v4
4445 with :
4546 submodules : true
4647
48+ - name : Extract service names from docker compose
49+ id : services
50+ run : |
51+ echo "services<<EOF" >> $GITHUB_OUTPUT
52+ docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
53+ echo "EOF" >> $GITHUB_OUTPUT
54+
4755 - name : Start containers with Compose Action
4856 uses :
hoverkraft-tech/[email protected] 4957 with :
5058 compose-file : ' ./spring-prometheus-grafana-example/compose.yaml'
51- services : |
52- app
53- prometheus
54- grafana
59+ services : ${{ steps.services.outputs.services }}
5560 up-flags : ' --build'
5661 down-flags : ' --volumes'
5762
@@ -62,19 +67,12 @@ jobs:
6267 run : |
6368 echo "Checking the health of the containers..."
6469
65- APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false")
66- PROMETHEUS_STATUS=$(docker inspect -f '{{.State.Running}}' prometheus || echo "false")
67- GRAFANA_STATUS=$(docker inspect -f '{{.State.Running}}' grafana || echo "false")
68-
69- echo "App status: $APP_STATUS"
70- echo "Prometheus status: $PROMETHEUS_STATUS"
71- echo "Grafana status: $GRAFANA_STATUS"
72-
73- if [ "$APP_STATUS" != "true" ] || [ "$PROMETHEUS_STATUS" != "true" ] || [ "$GRAFANA_STATUS" != "true" ]; then
74- echo "::error ::An error occurred while executing the containers."
75- exit 1
76- fi
77-
78- # Se chegou aqui, ambos estão ativos
79- - name : Success message
80- run : echo "Container testing completed successfully!"
70+ SERVICES="${{ steps.services.outputs.services }}"
71+ for service in $SERVICES; do
72+ status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
73+ echo "$service status: $status"
74+ if [ "$status" != "true" ]; then
75+ echo "::error ::Service $service is not running."
76+ exit 1
77+ fi
78+ done
0 commit comments