Files
proxmox/scripts/validation/validate-phoenix-deploy-targets.sh

49 lines
1.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Validate phoenix-deploy-api/deploy-targets.json structure.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
TARGETS_FILE="${1:-$PROJECT_ROOT/phoenix-deploy-api/deploy-targets.json}"
if [[ ! -f "$TARGETS_FILE" ]]; then
echo "[ERROR] Missing deploy targets file: $TARGETS_FILE" >&2
exit 1
fi
if ! command -v jq >/dev/null 2>&1; then
echo "[ERROR] jq is required to validate $TARGETS_FILE" >&2
exit 1
fi
jq -e '
(.targets | type == "array")
and (.targets | length > 0)
and all(.targets[]; (
(.repo | type == "string" and length > 0)
and ((.branch // "main") | type == "string" and length > 0)
and ((.target // "default") | type == "string" and length > 0)
and (.cwd | type == "string" and length > 0)
and (.command | type == "array" and length > 0)
and (all(.command[]; type == "string" and length > 0))
and ((.required_env // []) | type == "array")
and (all((.required_env // [])[]?; type == "string" and length > 0))
and (
(.healthcheck // null) == null or (
(.healthcheck.url | type == "string" and length > 0)
and ((.healthcheck.expect_status // 200) | type == "number")
and ((.healthcheck.attempts // 1) | type == "number")
and ((.healthcheck.delay_ms // 0) | type == "number")
and ((.healthcheck.timeout_ms // 10000) | type == "number")
)
)
))
and (
[.targets[] | [(.repo), (.branch // "main"), (.target // "default")] | join("|")]
| length == (unique | length)
)
' "$TARGETS_FILE" >/dev/null
echo "[OK] phoenix deploy targets valid: $TARGETS_FILE"