Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/scripts/docker-wait-for-health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail

if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 <container-with-health-check> [timeout-seconds] [poll-interval-seconds]" >&2
exit 2
fi

container="$1"
timeout_seconds="${2:-60}"
poll_interval_seconds="${3:-2}"
deadline=$((SECONDS + timeout_seconds))

while true; do
status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$container")"

case "$status" in
healthy)
exit 0
;;
unhealthy)
echo "Container ${container} is unhealthy." >&2
docker logs "$container" >&2 || true
exit 1
;;
starting)
;;
none)
echo "Container ${container} does not define a Docker health check." >&2
docker inspect "$container" >&2 || true
exit 1
;;
*)
echo "Container ${container} has unexpected health status: ${status}" >&2
docker inspect "$container" >&2 || true
exit 1
;;
esac

if [ "$SECONDS" -ge "$deadline" ]; then
echo "Container ${container} did not become healthy within ${timeout_seconds}s." >&2
docker logs "$container" >&2 || true
exit 1
fi

sleep "$poll_interval_seconds"
done
Loading
Loading