Files
proxmox/scripts/verify/check-sankofa-consolidated-nginx-examples.sh
2026-04-13 21:41:14 -07:00

55 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Validate example nginx configs for Sankofa consolidated web/API hub (syntax only).
# Read-only; no mutations. Uses host `nginx -t` when available, else Docker `nginx:1.27-alpine`.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
NGINX_DIR="${PROJECT_ROOT}/config/nginx"
TMPDIR="${TMPDIR:-/tmp}"
WRAP="${TMPDIR}/sankofa-nginx-test-$$.conf"
cleanup() {
rm -f "$WRAP" "${TMPDIR}/sankofa-nginx-wrap-docker-"*.conf 2>/dev/null || true
rm -f "${TMPDIR}/sankofa-nginx-test-$$"/*.conf 2>/dev/null || true
rmdir "${TMPDIR}/sankofa-nginx-test-$$" 2>/dev/null || true
}
trap cleanup EXIT
mkdir -p "${TMPDIR}/sankofa-nginx-test-$$"
cp "${NGINX_DIR}/sankofa-non-chain-frontends.example.conf" "${TMPDIR}/sankofa-nginx-test-$$/01-web.conf"
cp "${NGINX_DIR}/sankofa-phoenix-api-hub.example.conf" "${TMPDIR}/sankofa-nginx-test-$$/02-api.conf"
cat >"$WRAP" <<'EOF'
events { worker_connections 1024; }
http {
include __INCLUDE_DIR__/*.conf;
}
EOF
sed -i "s|__INCLUDE_DIR__|${TMPDIR}/sankofa-nginx-test-$$|g" "$WRAP"
if command -v nginx >/dev/null 2>&1; then
echo "== nginx -t (host binary, wrapped includes) =="
nginx -t -c "$WRAP"
elif command -v docker >/dev/null 2>&1; then
DOCKER_WRAP="${TMPDIR}/sankofa-nginx-wrap-docker-$$.conf"
cat >"$DOCKER_WRAP" <<'INNER'
events { worker_connections 1024; }
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /tmp/inc/*.conf;
}
INNER
echo "== nginx -t (docker nginx:1.27-alpine) =="
docker run --rm \
-v "$DOCKER_WRAP:/etc/nginx/nginx.conf:ro" \
-v "${TMPDIR}/sankofa-nginx-test-$$:/tmp/inc:ro" \
nginx:1.27-alpine \
nginx -t
else
echo "SKIP: need host nginx or docker to run syntax check."
exit 0
fi
echo "OK: example configs parse."