Docker image can be built with Docker 20.10, deployment script probes health itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 19:48:34 +02:00
co-authored by Claude Opus 5.5
parent 6c59c87f27
commit 0b8ebc4bbb
3 changed files with 48 additions and 20 deletions
+44 -17
View File
@@ -267,28 +267,55 @@ run_container() {
docker run "${args[@]}" "$image" >/dev/null
}
# Waits until the container reports healthy. Returns 1 when it stops or stays unhealthy.
# Waits until the application in the container is up and can reach its database.
# Returns 1 when the container stops or does not get healthy in time.
wait_healthy() {
local container="$1" status
for _ in $(seq 1 90); do
status="$(docker inspect --format '{{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$container" 2>/dev/null || echo "missing")"
case "$status" in
"running healthy")
# Traefik picks a new container up a moment after it turns healthy
if [ "$PROXY" = "traefik" ]; then sleep 3; fi
return 0 ;;
# Image without a health check: running for a while is the best we can tell
"running none") sleep 5
[ "$(docker inspect --format '{{.State.Status}}' "$container" 2>/dev/null)" = "running" ] && return 0
return 1 ;;
"running starting") ;;
"running unhealthy") return 1 ;;
running*) ;;
local container="$1" state has_check
has_check="$(docker inspect --format '{{if .Config.Healthcheck}}yes{{else}}no{{end}}' "$container" 2>/dev/null || echo "no")"
if [ "$has_check" = "no" ]; then
# Image from before the health check: running for a while is the best we can tell
sleep 5
[ "$(docker inspect --format '{{.State.Status}}' "$container" 2>/dev/null)" = "running" ]
return
fi
# Probe directly instead of waiting for Docker: its first check comes only after the
# check interval, and the faster start interval needs Docker 25
local ready="no"
for _ in $(seq 1 60); do
state="$(docker inspect --format '{{.State.Status}}' "$container" 2>/dev/null || echo "missing")"
case "$state" in
running)
if docker exec "$container" /app/rezervator -c /app/config/config.toml --healthcheck >/dev/null 2>&1; then
ready="yes"
break
fi ;;
restarting|created) ;;
*) return 1 ;;
esac
# A container that fails at start is restarted by Docker over and over
if [ "$(docker inspect --format '{{.RestartCount}}' "$container" 2>/dev/null || echo 0)" -ge 3 ]; then
return 1
fi
sleep 2
done
return 1
[ "$ready" = "yes" ] || return 1
if [ "$PROXY" = "traefik" ]; then
# Traefik routes to the container only once Docker itself reports it healthy
for _ in $(seq 1 45); do
state="$(docker inspect --format '{{.State.Health.Status}}' "$container" 2>/dev/null || echo "missing")"
case "$state" in
healthy) sleep 3; return 0 ;;
starting) ;;
*) return 1 ;;
esac
sleep 2
done
return 1
fi
return 0
}
cmd_init() {