profile/scripts/deploy-site.sh
ilia 58f6088f66 fix(pwa,deploy): faster SW takeover, verify SITE_ROOT vs nginx
- Workbox: skipWaiting, clientsClaim, cleanupOutdatedCaches
- NetworkFirst for navigations so HTML shell updates after deploy
- deploy-site: cmp index.html vs SITE_ROOT; print nginx root hints; SW tips

Made-with: Cursor
2026-03-24 23:37:25 -04:00

65 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run on the production host from the repo clone (e.g. /var/www/iliadobkin.com-src).
# Fixes stuck deploys: local edits to package.json / lockfile block git pull — this resets to origin/main.
#
# Requires Node >= 20.19 (see .nvmrc). Example: nvm install && nvm use
#
# Optional: SITE_ROOT=/var/www/iliadobkin.com (default). Rsync runs only if that directory exists.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_ROOT"
# Nginx must use this path as `root` for this site. If wrong, you will still see an old build.
SITE_ROOT="${SITE_ROOT:-/var/www/iliadobkin.com}"
echo "==> Node $(node -v) (Vite 7 needs 20.19+ or 22.12+)"
echo "==> Git: match origin/main exactly (drops local changes to tracked files)"
git fetch origin
git checkout main
git reset --hard origin/main
echo "==> Dependencies (clean)"
rm -rf node_modules
npm ci
echo "==> Build"
npm run build
if [[ -d "$SITE_ROOT" ]]; then
echo "==> Publish dist/ -> $SITE_ROOT/"
if command -v rsync >/dev/null 2>&1; then
rsync -av --delete "${REPO_ROOT}/dist/" "${SITE_ROOT}/"
else
echo " (rsync not installed — using rm + cp; install rsync for faster syncs: apt-get install -y rsync)"
find "$SITE_ROOT" -mindepth 1 -exec rm -rf {} +
cp -a "${REPO_ROOT}/dist/." "$SITE_ROOT/"
fi
echo "==> Verify publish (fails if SITE_ROOT is not where nginx reads files)"
if ! cmp -s "${REPO_ROOT}/dist/index.html" "${SITE_ROOT}/index.html"; then
echo "ERROR: dist/index.html and ${SITE_ROOT}/index.html differ or one is missing."
echo " Your nginx root is probably NOT ${SITE_ROOT}. Find it with:"
echo " grep -RIn --include='*.conf' 'root\\s' /etc/nginx/"
exit 1
fi
echo " OK: index.html on disk matches dist (same deploy)."
echo "==> Nginx roots (check that one of these is SITE_ROOT=${SITE_ROOT})"
if command -v nginx >/dev/null 2>&1; then
nginx -T 2>/dev/null | grep -E 'server_name|^[[:space:]]*root[[:space:]]' | head -60 || true
else
echo " (nginx binary not in PATH — skip)"
fi
echo "==> Done. Reload: systemctl reload nginx"
echo " If the browser still shows the old UI:"
echo " • Confirm URL hits THIS server (no second host / CDN)."
echo " • Hard refresh (Ctrl+Shift+R) or Incognito."
echo " • DevTools → Application → Service Workers → Unregister, then reload."
else
echo "WARN: SITE_ROOT '$SITE_ROOT' is not a directory — not copying dist."
echo " Set SITE_ROOT to your nginx root, or copy ${REPO_ROOT}/dist/ manually."
fi