Skip to content

Commit 4799b67

Browse files
Merge pull request #41 from igorcampos-dev/chore/workflow-container-health
chore(ci/cd): adjustment workflow
2 parents f544fba + dbbc4ef commit 4799b67

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Checking the health of the containers..."
5+
6+
SERVICES="$1"
7+
8+
for service in $SERVICES; do
9+
running=$(docker inspect -f '{{.State.Running}}' "$service" 2>/dev/null || echo "false")
10+
11+
if [ "$running" = "true" ]; then
12+
echo "$service is running ✔️"
13+
else
14+
exit_code=$(docker inspect -f '{{.State.ExitCode}}' "$service" 2>/dev/null || echo "1")
15+
if [ "$exit_code" = "0" ]; then
16+
echo "$service is stopped but exited with code 0 ✔️"
17+
else
18+
echo "::error ::$service is stopped and exited with code $exit_code"
19+
exit 1
20+
fi
21+
fi
22+
done

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,4 @@ jobs:
6565

6666
- name: Check container health
6767
run: |
68-
echo "Checking the health of the containers..."
69-
70-
SERVICES="${{ steps.services.outputs.services }}"
71-
72-
for service in $SERVICES; do
73-
running=$(docker inspect -f '{{.State.Running}}' "$service" 2>/dev/null || echo "false")
74-
75-
if [ "$running" = "true" ]; then
76-
echo "$service is running ✔️"
77-
else
78-
exit_code=$(docker inspect -f '{{.State.ExitCode}}' "$service" 2>/dev/null || echo "1")
79-
if [ "$exit_code" = "0" ]; then
80-
echo "$service is stopped but exited with code 0 ✔️"
81-
else
82-
echo "::error ::$service is stopped and exited with code $exit_code ❌"
83-
exit 1
84-
fi
85-
fi
86-
done
68+
./.github/scripts/check-container-health.sh "${{ steps.services.outputs.services }}"

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,4 @@ jobs:
6565

6666
- name: Check container health
6767
run: |
68-
echo "Checking the health of the containers..."
69-
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
68+
./.github/scripts/check-container-health.sh "${{ steps.services.outputs.services }}"

0 commit comments

Comments
 (0)