43 lines
1.4 KiB
Bash
Executable File
43 lines
1.4 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"
|
|
|
|
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 "==> Done. Reload nginx if needed: systemctl reload nginx"
|
|
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
|