34 lines
938 B
Bash
34 lines
938 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ENV_NAME="${1:?Environment is required}"
|
|
COMPOSE_FILE="${2:?Compose file path required}"
|
|
ENV_FILE="${3:?Env file path required}"
|
|
|
|
if docker compose version >/dev/null 2>&1; then
|
|
DC_CMD=(docker compose)
|
|
elif command -v docker-compose >/dev/null 2>&1; then
|
|
DC_CMD=(docker-compose)
|
|
else
|
|
echo "Missing docker compose command. Install docker compose plugin or docker-compose."
|
|
exit 1
|
|
fi
|
|
|
|
max_attempts=20
|
|
sleep_seconds=3
|
|
|
|
for ((i=1; i<=max_attempts; i++)); do
|
|
status=$("${DC_CMD[@]}" -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" ps --status running --services | wc -l)
|
|
if [[ "${status}" -ge 2 ]]; then
|
|
echo "Healthcheck passed for ${ENV_NAME} environment."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Healthcheck waiting (${i}/${max_attempts})..."
|
|
sleep "${sleep_seconds}"
|
|
done
|
|
|
|
echo "Healthcheck failed for ${ENV_NAME} environment."
|
|
"${DC_CMD[@]}" -f "${COMPOSE_FILE}" --env-file "${ENV_FILE}" ps
|
|
exit 1
|