The population-ranked global top-500 skewed to Asian megacities and missed high-English-search-demand cities. gen_cities.py now tops up with the top ~250 cities from English-speaking countries (US/GB/CA/AU/NZ/IE/ZA) not already in the global set, so US coverage goes 13->146, GB 2->42, CA 3->29, etc. (Seattle, Boston, Manchester, Melbourne, Auckland, Dublin, ...). cities.json regenerated to 750. Both deploy scripts now launch warm_cities.py automatically after the health check, detached (dev: a systemd --user transient unit; prod: setsid/nohup), so the city pages serve from cache without a manual step; idempotent, so only the first deploy does the full warm. DEPLOY.md updated.
52 lines
1.8 KiB
Bash
Executable file
52 lines
1.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Pull the latest code and restart Thermograph. Run on the VPS — the GitHub
|
|
# Actions workflow invokes this over SSH, and you can run it by hand too.
|
|
#
|
|
# ssh deploy@vps '/opt/thermograph/deploy/deploy.sh'
|
|
set -euo pipefail
|
|
|
|
APP_DIR="${APP_DIR:-/opt/thermograph}"
|
|
BRANCH="${BRANCH:-main}"
|
|
cd "$APP_DIR"
|
|
|
|
# Pre-warm the ~750 city-page archives so /climate pages serve from cache and a
|
|
# search-engine crawl never bursts the archive API quota. Detached + backgrounded
|
|
# so it never blocks the deploy or health check; idempotent (skips already-cached
|
|
# cells), so it's cheap on every deploy after the first full warm.
|
|
warm_city_archives() {
|
|
mkdir -p "$APP_DIR/logs"
|
|
echo "==> Warming city-page archives in the background (logs/warm-cities.log)"
|
|
setsid nohup bash -c "cd '$APP_DIR/backend' && exec '$APP_DIR/.venv/bin/python' warm_cities.py --pace 2" \
|
|
</dev/null >"$APP_DIR/logs/warm-cities.log" 2>&1 &
|
|
}
|
|
|
|
echo "==> Fetching $BRANCH"
|
|
git fetch --prune origin "$BRANCH"
|
|
git reset --hard "origin/$BRANCH"
|
|
|
|
echo "==> Installing dependencies"
|
|
if [ ! -d .venv ]; then
|
|
python3 -m venv .venv
|
|
fi
|
|
.venv/bin/pip install --upgrade pip -q
|
|
.venv/bin/pip install -r backend/requirements.txt -q
|
|
|
|
echo "==> Restarting service"
|
|
sudo systemctl restart thermograph
|
|
|
|
echo "==> Health check"
|
|
PORT="$(sed -n 's/^PORT=//p' /etc/thermograph.env)"; PORT="${PORT:-8137}"
|
|
BASE="$(sed -n 's/^THERMOGRAPH_BASE=//p' /etc/thermograph.env)"; BASE="${BASE:-/}"
|
|
# Normalize: no double slash, allow root.
|
|
url="http://127.0.0.1:${PORT}${BASE%/}/"
|
|
for i in $(seq 1 15); do
|
|
if curl -fsS -o /dev/null "$url"; then
|
|
echo "==> OK: $url is serving"
|
|
warm_city_archives
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "!! Health check failed for $url" >&2
|
|
sudo systemctl status thermograph --no-pager -l || true
|
|
exit 1
|