65 lines
2.0 KiB
Bash
Executable File
65 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
env_file="${1:-compose/.env}"
|
|
compose_file="${BACKEND_COMPOSE_FILE:-compose/docker-compose.backend.yml}"
|
|
|
|
for required_command in curl docker jq sed; do
|
|
if ! command -v "$required_command" >/dev/null 2>&1; then
|
|
printf 'Required command is unavailable: %s\n' "$required_command" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
if [[ ! -r "$env_file" ]]; then
|
|
printf 'Environment file not found: %s\n' "$env_file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
env_value() {
|
|
sed -n "s/^${1}=//p" "$env_file" | head -n 1
|
|
}
|
|
|
|
project_name="$(env_value BACKEND_COMPOSE_PROJECT_NAME)"
|
|
frontend_bind_address="$(env_value FRONTEND_BIND_ADDRESS)"
|
|
frontend_host_port="$(env_value FRONTEND_HOST_PORT)"
|
|
if [[ -z "$project_name" || "$project_name" == "$(env_value COMPOSE_PROJECT_NAME)" ]]; then
|
|
printf 'BACKEND_COMPOSE_PROJECT_NAME must be set and differ from the infrastructure project.\n' >&2
|
|
exit 1
|
|
fi
|
|
compose_command=(
|
|
docker compose
|
|
--project-name "$project_name"
|
|
--env-file "$env_file"
|
|
-f "$compose_file"
|
|
)
|
|
"${compose_command[@]}" config --quiet
|
|
|
|
base_url="http://${frontend_bind_address}:${frontend_host_port}"
|
|
api_json=""
|
|
for _attempt in $(seq 1 18); do
|
|
if curl --fail --silent --show-error --max-time 5 "${base_url}/health" | grep -q '^ok'; then
|
|
if api_json="$(curl --fail --silent --show-error --max-time 5 "${base_url}/api/health" 2>/dev/null)"; then
|
|
if printf '%s' "$api_json" | jq -e '.status == "healthy" and .database == "connected"' >/dev/null; then
|
|
break
|
|
fi
|
|
fi
|
|
fi
|
|
api_json=""
|
|
sleep 5
|
|
done
|
|
if [[ -z "$api_json" ]]; then
|
|
printf 'Frontend or proxied API health check did not become healthy: %s\n' "$base_url" >&2
|
|
"${compose_command[@]}" ps >&2
|
|
exit 1
|
|
fi
|
|
|
|
index_html="$(curl --fail --silent --show-error --max-time 5 "${base_url}/")"
|
|
if ! printf '%s' "$index_html" | grep -q 'id="app"'; then
|
|
printf 'Frontend index does not contain the Vue application mount point.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf '%s\n' "$api_json" | jq .
|
|
"${compose_command[@]}" ps
|
|
printf 'Frontend static site and proxied backend health checks passed.\n'
|