-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check service health in
test-docker-compose.yml
- Loading branch information
1 parent
23ad257
commit 7a96e3a
Showing
1 changed file
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,39 @@ jobs: | |
uses: actions/[email protected] | ||
|
||
- name: Validate | ||
run: docker compose -f docker-compose.standalone.yml config -q | ||
run: docker compose -f docker-compose.standalone.yml config -q | ||
|
||
- name: Check Service Health | ||
run: | | ||
ENV=prod docker compose -f docker-compose.standalone.yml up -d | ||
sleep 10 | ||
RETRY=0 | ||
SERVICES=$(docker compose -f docker-compose.standalone.yml ps -q) | ||
echo "Services for checking health: $SERVICES" | ||
while true | ||
do | ||
ALL_HEALTHY=true | ||
for SERVICE in $SERVICES; do | ||
HEALTH_STATUS=$(docker inspect --format='{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}' "$SERVICE") | ||
if [ -z "$HEALTH_STATUS" ]; then | ||
echo "Service $SERVICE does not have a health check configured, passing through" | ||
elif [ "$HEALTH_STATUS" = "healthy" ]; then | ||
echo "$SERVICE is healthy" | ||
else | ||
echo "$SERVICE is not healthy" | ||
ALL_HEALTHY=false | ||
break | ||
fi | ||
done | ||
if [ $ALL_HEALTHY = true ]; then | ||
echo "All services are healthy" | ||
break | ||
fi | ||
if [ $RETRY -eq 5 ]; then | ||
echo "Failed to start services, some services are not healthy" | ||
exit 1 | ||
fi | ||
echo "Some services are not healthy. Retry times: $RETRY. Retrying..." | ||
sleep 10 | ||
((RETRY++)) | ||
done |