Skip to content

Commit

Permalink
Change the way of checking if healthcheck is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
ppawlowski committed Nov 15, 2024
1 parent a3e6d8f commit db28b83
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/test-docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db28b83

Please sign in to comment.