Files

28 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
env_file="${1:-compose/.env}"
compose_file="${COMPOSE_FILE:-compose/docker-compose.infra.yml}"
if [[ ! -r "$env_file" ]]; then
printf 'Environment file not found: %s\n' "$env_file" >&2
exit 1
fi
compose_command=(docker compose --env-file "$env_file" -f "$compose_file")
"${compose_command[@]}" config --quiet
"${compose_command[@]}" exec -T postgres sh -ec 'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
"${compose_command[@]}" exec -T redis sh -ec 'redis-cli -a "$REDIS_PASSWORD" ping 2>/dev/null | grep -q PONG'
"${compose_command[@]}" exec -T minio sh -ec 'curl -fsS http://127.0.0.1:9000/minio/health/live >/dev/null'
minio_init_status="$("${compose_command[@]}" ps --all --format json minio-init)"
if ! printf '%s' "$minio_init_status" \
| jq -e 'if type == "array" then length == 1 and .[0].ExitCode == 0 else .ExitCode == 0 end' >/dev/null; then
printf 'MinIO bucket initialization did not complete successfully.\n' >&2
exit 1
fi
"${compose_command[@]}" ps
printf 'Infrastructure checks passed.\n'