From db28b839d59216c39e185448f046fd3f8ad1d51e Mon Sep 17 00:00:00 2001 From: PPawlowski Date: Fri, 15 Nov 2024 12:59:34 +0100 Subject: [PATCH] Change the way of checking if healthcheck is configured --- .github/workflows/test-docker-compose.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-docker-compose.yaml b/.github/workflows/test-docker-compose.yaml index 14fb603..c0f70ed 100644 --- a/.github/workflows/test-docker-compose.yaml +++ b/.github/workflows/test-docker-compose.yaml @@ -28,18 +28,25 @@ jobs: - name: Run tests run: | + has_healthcheck() { + local container=$1 + local health_status=$(docker inspect --format='{{if .Config.Healthcheck}}true{{else}}false{{end}}' "$container") + [ "$health_status" = "true" ] + } + check_containers() { containers=$(docker compose ps -q) for container in $containers; do container_name=$(docker inspect --format '{{.Name}}' "$container" | sed 's/\///') container_ip=$(docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container") - if docker inspect --format '{{.Config.Healthcheck}}' "$container" 2>/dev/null | grep -q .; then + if check_has_healthcheck "$container"; then + echo "Container has healthcheck defined" status=$(docker inspect --format "{{.State.Health.Status}}" "$container") if [ "$status" != "healthy" ]; then echo "❌ Container $container_name is not healthy (status: $status)" - return 1 - fi + return 1 + fi else running=$(docker inspect --format "{{.State.Running}}" "$container") if [ "$running" != "true" ]; then