← back to Commercialrealestate

deploy/push-frontend-kamatera.sh

49 lines

#!/usr/bin/env bash
# push-frontend-kamatera.sh — on-demand front-end deploy mac3 -> Kamatera CRCP prod.
#
# WHY THIS EXISTS: crcp.agentabrams.com is a Kamatera-LOCAL node app
# (/root/public-projects/commercialrealestate, 127.0.0.1:9911 behind nginx).
# There is NO auto code-sync, so the live front-end silently drifts stale
# (it was frozen 9 days — Jul 7 -> Jul 16 2026 — until an iPad-fix hotfix).
# This script is the MANUAL, reviewable way to push front-end changes to prod.
#
# SCOPE: static front-end ONLY (public/*.html, *.js, *.css). It does NOT touch
# data/ (Kamatera has its own snapshots) or scripts/serve.js (server logic) or
# .env — those are deliberately excluded to keep the blast radius small.
# serve.js uses express.static, so pushed files go live on next request (no restart).
#
# It is intentionally NOT scheduled: a cron would push uncommitted/half-baked
# local edits to prod unattended. Run it on purpose, after committing.
#
# Usage:  bash deploy/push-frontend-kamatera.sh [--dry-run]
set -euo pipefail

HOST="root@45.61.58.125"
REMOTE="/root/public-projects/commercialrealestate/public"
LOCAL="$(cd "$(dirname "$0")/.." && pwd)/public"
STAMP="$(date +%Y%m%d-%H%M%S)"

DRY=""
[ "${1:-}" = "--dry-run" ] && DRY="--dry-run"

echo "== CRCP front-end deploy -> $HOST:$REMOTE =="
echo "   local:  $LOCAL"
[ -n "$DRY" ] && echo "   (DRY RUN — no files written)"

# 1) timestamped backup of the current remote public/ (rollback point)
if [ -z "$DRY" ]; then
  ssh -o ConnectTimeout=10 "$HOST" \
    "cp -a '$REMOTE' '${REMOTE}.bak-$STAMP' && echo '   backup: ${REMOTE}.bak-$STAMP'"
fi

# 2) rsync front-end assets only (html/js/css), delete-protected (no --delete;
#    never removes remote files this script didn't place)
rsync -avz $DRY \
  --include='*/' \
  --include='*.html' --include='*.js' --include='*.css' \
  --exclude='*' \
  -e 'ssh -o ConnectTimeout=10' \
  "$LOCAL/" "$HOST:$REMOTE/"

echo "== done.  verify:  curl -sI -u admin:*** https://crcp.agentabrams.com/index.html | grep last-modified =="