Skip to content

Commit d875f7d

Browse files
chore(spring-prometheus-grafana-example): adjustments to bring abstraction in the GitHub workflows
1 parent 5fe8824 commit d875f7d

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

.github/workflows/spring-kafka-example.yml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +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-kafka-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-kafka-example/compose.yaml'
51-
services: |
52-
app
53-
kafka
59+
services: ${{ steps.services.outputs.services }}
5460
up-flags: '--build'
5561
down-flags: '--volumes'
5662

@@ -59,19 +65,14 @@ jobs:
5965

6066
- name: Check container health
6167
run: |
62-
echo "Verificando saúde dos containers..."
63-
64-
APP_STATUS=$(docker inspect -f '{{.State.Running}}' app || echo "false")
65-
KAFKA_STATUS=$(docker inspect -f '{{.State.Running}}' kafka || echo "false")
66-
67-
echo "Status do app: $APP_STATUS"
68-
echo "Status do kafka: $KAFKA_STATUS"
69-
70-
if [ "$APP_STATUS" != "true" ] || [ "$KAFKA_STATUS" != "true" ]; then
71-
echo "::error ::Um ou ambos os containers estão inativos. PR não deve ser autorizado!"
72-
exit 1
73-
fi
68+
echo "Checking the health of the containers..."
7469
75-
# Se chegou aqui, ambos estão ativos
76-
- name: Success message
77-
run: echo "✅ Todos os containers estão rodando com sucesso!"
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

.github/workflows/spring-prometheus-grafana-example.yml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)