lilith-platform.live/deployments/@domains/ftw.pw/deploy.sh
2026-06-08 05:23:12 -07:00

53 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../../../" && pwd)"
REMOTE="quinn-vps"
REMOTE_NGINX_CONF="/etc/nginx/sites-available/ftw.pw"
# ---------------------------------------------------------------------------
# [1/4] Typecheck @features/api (ensure short-link code is valid)
# ---------------------------------------------------------------------------
echo "==> [1/4] Type-checking @features/api..."
cd "$REPO_ROOT/codebase/@features/api"
bun run typecheck
# ---------------------------------------------------------------------------
# [2/4] Sync nginx config to VPS
# ---------------------------------------------------------------------------
echo "==> [2/4] Syncing nginx config to ${REMOTE}:${REMOTE_NGINX_CONF}..."
ssh "$REMOTE" "mkdir -p /etc/nginx/sites-available"
rsync -avz "$SCRIPT_DIR/nginx/prod.conf" "$REMOTE:$REMOTE_NGINX_CONF"
# ---------------------------------------------------------------------------
# [3/4] Enable vhost (idempotent symlink), test nginx syntax + reload
# ---------------------------------------------------------------------------
echo "==> [3/4] Testing nginx syntax and reloading..."
ssh "$REMOTE" bash -euo pipefail <<'ENDSSH'
set -euo pipefail
# Ensure the vhost is enabled (symlink is idempotent on re-deploy).
ln -sfn /etc/nginx/sites-available/ftw.pw /etc/nginx/sites-enabled/ftw.pw
echo " Testing /etc/nginx/sites-available/ftw.pw..."
nginx -t
echo " Reloading nginx..."
systemctl reload nginx
echo " Nginx reloaded."
ENDSSH
# ---------------------------------------------------------------------------
# [4/4] Health check
# ---------------------------------------------------------------------------
echo "==> [4/4] Running health check..."
sleep 2
status_code=$(curl -s -o /dev/null -w "%{http_code}" "https://ftw.pw/" || echo "000")
if [[ "$status_code" == "301" ]]; then
echo "✓ Health check passed: ftw.pw returns 301 redirect"
else
echo "✗ Health check failed: expected 301, got $status_code"
exit 1
fi
echo ""
echo "Deploy completed at $(date '+%Y-%m-%d %H:%M:%S %Z')"