[object Object]

← back to Stock Vshape Viewer

One-command gated redeploy: redeploy.sh runs panel spec against a throwaway local server as a PRE-DEPLOY GATE (aborts if red), then rsync + zero-downtime pm2 reload + prod smoke test; npm run deploy

5b21ae42c718a9d16c2c8231185095ef18c7a6ae · 2026-08-27 19:01:03 -0700 · Steve

Files touched

Diff

commit 5b21ae42c718a9d16c2c8231185095ef18c7a6ae
Author: Steve <steve@designerwallcoverings.com>
Date:   Thu Aug 27 19:01:03 2026 -0700

    One-command gated redeploy: redeploy.sh runs panel spec against a throwaway local server as a PRE-DEPLOY GATE (aborts if red), then rsync + zero-downtime pm2 reload + prod smoke test; npm run deploy
---
 .deploy.conf |  2 ++
 package.json |  3 ++-
 redeploy.sh  | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/.deploy.conf b/.deploy.conf
index 953c675..ff4cb81 100644
--- a/.deploy.conf
+++ b/.deploy.conf
@@ -2,3 +2,5 @@ PROJECT_NAME=charts
 DEPLOY_PATH=/root/public-projects/charts
 PORT=9925
 HEALTH_URL=http://127.0.0.1:9925/
+REMOTE_HOST=root@45.61.58.125
+PUBLIC_URL=https://charts.agentabrams.com
diff --git a/package.json b/package.json
index a7618ad..6005670 100644
--- a/package.json
+++ b/package.json
@@ -6,6 +6,7 @@
   "main": "server.js",
   "scripts": {
     "start": "node server.js",
-    "test": "node test/panel.spec.mjs"
+    "test": "node test/panel.spec.mjs",
+    "deploy": "bash redeploy.sh"
   }
 }
diff --git a/redeploy.sh b/redeploy.sh
new file mode 100755
index 0000000..264df9b
--- /dev/null
+++ b/redeploy.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# redeploy.sh — gated one-command redeploy of charts.agentabrams.com to Kamatera.
+# PRE-DEPLOY GATE: spins up a throwaway local server, runs the panel spec against it,
+# and ABORTS the deploy if the spec is red. Only green builds reach production.
+#   Usage:  ./redeploy.sh            (gate + deploy)
+#           ./redeploy.sh --no-gate  (skip the spec, deploy anyway — discouraged)
+set -euo pipefail
+cd "$(dirname "$0")"
+source ./.deploy.conf
+REMOTE="${REMOTE_HOST:-root@45.61.58.125}"
+U="${VIEWER_USER:-admin}"; P="${VIEWER_PASS:-DW2024!}"
+PUB="${PUBLIC_URL:-https://charts.agentabrams.com}"
+
+# ---------- PRE-DEPLOY GATE ----------
+if [ "${1:-}" != "--no-gate" ]; then
+  echo "==> PRE-DEPLOY GATE: panel spec against a throwaway local server"
+  node server.js >/tmp/redeploy-server.log 2>&1 &   # PORT unset -> OS-assigned free port
+  SRV=$!
+  trap 'kill $SRV 2>/dev/null || true' EXIT
+  sleep 2
+  TESTURL=$(grep -oE 'http://localhost:[0-9]+' /tmp/redeploy-server.log | head -1)
+  if [ -z "$TESTURL" ]; then echo "❌ local server failed to start"; cat /tmp/redeploy-server.log; exit 1; fi
+  echo "    testing $TESTURL"
+  if ! node test/panel.spec.mjs "$TESTURL"; then
+    echo "❌ PRE-DEPLOY GATE FAILED — panel spec is red. NOT deploying."; exit 1
+  fi
+  kill $SRV 2>/dev/null || true; trap - EXIT
+  echo "✅ gate passed — proceeding to deploy"
+else
+  echo "⚠️  --no-gate: skipping the pre-deploy spec"
+fi
+
+# ---------- DEPLOY ----------
+echo "==> rsync to $REMOTE:$DEPLOY_PATH"
+rsync -az --delete \
+  --exclude '.git' --exclude 'node_modules' --exclude 'test' --exclude 'backtest' \
+  --exclude '5x' --exclude '.playwright-mcp' --exclude '*.png' --exclude '.deploy.conf' \
+  ./ "$REMOTE:$DEPLOY_PATH/"
+
+echo "==> pm2 reload $PROJECT_NAME (zero-downtime, preserves PORT=$PORT)"
+ssh "$REMOTE" "cd $DEPLOY_PATH && (pm2 reload $PROJECT_NAME 2>/dev/null || PORT=$PORT pm2 start server.js --name $PROJECT_NAME); pm2 save >/dev/null 2>&1"
+
+# ---------- POST-DEPLOY SMOKE ----------
+echo "==> prod smoke test ($PUB)"
+sleep 1
+c() { curl -s -o /dev/null -w "%{http_code}" "$@"; }
+G=$(c "$PUB/"); A=$(c -u "$U:$P" "$PUB/"); API=$(c -u "$U:$P" "$PUB/api/history?ticker=NVDA")
+echo "    gate:$G (401)  authed:$A (200)  api:$API (200)"
+if [ "$G" = "401" ] && [ "$A" = "200" ] && [ "$API" = "200" ]; then
+  echo "✅ redeploy complete → $PUB"
+else
+  echo "⚠️  redeploy finished but smoke test unexpected — check $PUB"; exit 2
+fi

← 7b59452 auto-data-snapshot: 2026-08-27T17:33:56 (1 data files) — .de  ·  back to Stock Vshape Viewer  ·  Ship the backtest into the UI: /api/backtest (built at boot, 340e745 →