Files
momentry_core/scripts/deploy_package.sh
Accusys ffc30d7377 M4 handover: coordinate fixes, detector registry, deploy v2, YOLOv8s, identity lifecycle
- Fix swift_pose/swift_ocr Y-flip bugs (BUG-003~006)
- Add heuristic_scene module + post-processing trigger (replaces Places365)
- YOLOv5nu → YOLOv8s CoreML (+33% detections, +390% scene indicators)
- Per-table SQL export (split 4.7GB single file → 478MB max per table)
- Version/build check in deploy.sh (compare /health vs file_info.json)
- Add file_uuid column to identities table + backfill
- Identity pre-clean step in deploy (avoids UNIQUE conflicts on re-deploy)
- Stranger_xxx naming fix with UUID context
- Add DETECTOR_REGISTRY.md (25 detectors), DETECTOR_SELECTION_SOP.md
- Update SPATIAL_COORDINATE_REGISTRY.md (P layer, 6-layer architecture)
- New IDENTITY_LIFECYCLE.md
- M4 response docs for deploy_script_fix and 111614 test report
2026-05-13 20:00:47 +08:00

129 lines
5.0 KiB
Bash

#!/bin/bash
# Momentry Release Package — Deploy Script
# Usage: bash deploy.sh [--db-only] [--skip-video]
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
UUID=$(basename "$DIR")
PG_BIN="${PG_BIN:-/Users/accusys/pgsql/18.3/bin}"
DB_NAME="${DB_NAME:-momentry}"
DB_USER="${DB_USER:-accusys}"
DEMO_DIR="${DEMO_DIR:-/Users/accusys/momentry/var/sftpgo/data/demo}"
OUTPUT_DIR="${OUTPUT_DIR:-/Users/accusys/momentry/output_dev}"
echo "=== Momentry Package Deploy ==="
echo "UUID: $UUID"
echo "Time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
echo "=== Momentry Package Deploy ==="
echo "UUID: $UUID"
echo "Time: $(date '+%Y-%m-%d %H:%M:%S')"
echo ""
# 0. Version & build compatibility check
echo "[0/8] Checking system version and build..."
PKG_VER=$(python3 -c "import json; f=json.load(open('$DIR/file_info.json')); print(f.get('momentry_version','?'))")
PKG_BUILD=$(python3 -c "import json; f=json.load(open('$DIR/file_info.json')); print(f.get('momentry_build','?'))")
SRV=$(curl -sf http://localhost:3003/health | python3 -c "
import json,sys
d=json.load(sys.stdin)
print(d.get('version','unknown'), d.get('build_git_hash','unknown'))
" 2>/dev/null || echo "down down")
SRV_VER=$(echo "$SRV" | cut -d' ' -f1)
SRV_BUILD=$(echo "$SRV" | cut -d' ' -f2)
if [ "$SRV_VER" = "down" ]; then
echo " ⚠️ Cannot reach server at localhost:3003, skipping version check"
elif [ "$SRV_VER" != "$PKG_VER" ] || [ "$SRV_BUILD" != "$PKG_BUILD" ]; then
echo " ❌ Mismatch:"
echo " Package Server"
echo " Version: $PKG_VER $SRV_VER"
echo " Build: $PKG_BUILD $SRV_BUILD"
echo ""
echo " Please obtain the matching system upgrade package."
exit 1
else
echo " ✅ Server v$SRV_VER (build $SRV_BUILD) matches package"
fi
# 1. Verify package integrity
echo "[1/8] Verifying package..."
MISSING=0
for f in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$DIR/$f" ]; then
echo " ❌ Missing: $f"
MISSING=1
fi
done
if [ $MISSING -eq 1 ]; then
echo "ERROR: Package incomplete"
exit 1
fi
echo " ✅ Package verified"
# 2. Pre-clean: remove existing identities for this file (avoids UNIQUE(name) conflicts on COPY)
echo "[2/8] Pre-cleaning existing identities for this file..."
"$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -c "DELETE FROM dev.identities WHERE file_uuid = '$UUID'" > /dev/null 2>&1
echo " ✅ Cleared identities for $UUID"
# 3. Import data.sql (uses \i to load per-table files from sql/)
echo "[3/8] Importing DB data..."
(cd "$DIR" && "$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -f data.sql 2>&1) | tail -5
echo " ✅ Data imported"
# 4. Copy video to demo dir (only this package's video, not scanning others)
VIDEO_FILE=$(ls "$DIR"/*.mp4 "$DIR"/*.mov "$DIR"/*.avi "$DIR"/*.mkv 2>/dev/null | head -1)
if [ -n "$VIDEO_FILE" ]; then
VIDEO_NAME=$(basename "$VIDEO_FILE")
DEST="$DEMO_DIR/$VIDEO_NAME"
if [ ! -f "$DEST" ]; then
cp "$VIDEO_FILE" "$DEST"
echo "[4/8] Video copied: $VIDEO_NAME$DEMO_DIR"
else
echo "[4/8] Video already in demo dir, skipping"
fi
else
echo "[4/8] No video file in package, skipping"
fi
# 5. Set video status to completed (package is fully processed)
echo "[5/8] Setting deployment status..."
"$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -c "UPDATE dev.videos SET status = 'completed' WHERE file_uuid = '$UUID'" > /dev/null 2>&1
echo " ✅ Status set to 'completed'"
# 6. Copy output files
echo "[6/8] Copying output files..."
COPIED=0
for f in "$DIR"/*.json "$DIR"/*.sqlite "$DIR"/*.sqlite; do
if [ -f "$f" ]; then
FNAME=$(basename "$f")
if [ "$FNAME" != "file_info.json" ] && [ "$FNAME" != "package.json" ]; then
cp "$f" "$OUTPUT_DIR/$FNAME"
COPIED=$((COPIED + 1))
fi
fi
done
echo "$COPIED files copied to $OUTPUT_DIR"
# 7. Verify deployment
echo "[7/8] Verifying deployment..."
CHUNKS=$("$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -t -A -c "SELECT COUNT(*) FROM dev.chunk WHERE file_uuid='$UUID'" 2>/dev/null || echo "?")
FACES=$("$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -t -A -c "SELECT COUNT(*) FROM dev.face_detections WHERE file_uuid='$UUID'" 2>/dev/null || echo "?")
IDENTS=$("$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -t -A -c "SELECT COUNT(*) FROM dev.identities WHERE file_uuid='$UUID'" 2>/dev/null || echo "?")
TKG_NODES=$("$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -t -A -c "SELECT COUNT(*) FROM dev.tkg_nodes WHERE file_uuid='$UUID'" 2>/dev/null || echo "?")
TKG_EDGES=$("$PG_BIN/psql" -U "$DB_USER" -d "$DB_NAME" -t -A -c "SELECT COUNT(*) FROM dev.tkg_edges WHERE file_uuid='$UUID'" 2>/dev/null || echo "?")
echo ""
echo "=== Deploy Complete ==="
echo " UUID: $UUID"
echo " Chunks: $CHUNKS"
echo " Faces: $FACES"
echo " Identities: $IDENTS"
echo " TKG nodes: $TKG_NODES"
echo " TKG edges: $TKG_EDGES"
echo " Output: $OUTPUT_DIR/"
echo ""
echo "Package is self-contained — no further processing needed."
echo ""
echo "Offline report:"
echo " python3 scripts/render_offline_report.py $OUTPUT_DIR/$UUID.sqlite"