#!/bin/bash # Deploy core_nest to server # # Two deployment modes: # 1. Docker (default): Full core_nest structure + source code # 2. Bare metal (--bare-metal): Only pawprint source to systemd services # # Usage: # ./deploy.sh # Deploy Docker setup (default) # ./deploy.sh --bare-metal # Deploy bare metal pawprint only # ./deploy.sh --dry-run # Preview what would be synced # ./deploy.sh --bare-metal --dry-run # Preview bare metal sync set -e # Load configuration SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/.env.sync" 2>/dev/null || true SERVER="${DEPLOY_SERVER:-mariano@mcrn.ar}" REMOTE_PATH="${DEPLOY_REMOTE_PATH:-~/core_nest}" BARE_METAL_PATH="${DEPLOY_BARE_METAL_PATH:-~/pawprint}" # Source code paths (defaults if not in .env.sync) LOCAL_AMAR_BACKEND="${LOCAL_AMAR_BACKEND:-$HOME/wdir/ama/amar_django_back}" LOCAL_AMAR_FRONTEND="${LOCAL_AMAR_FRONTEND:-$HOME/wdir/ama/amar_frontend}" LOCAL_PAWPRINT="${LOCAL_PAWPRINT:-$HOME/wdir/ama/pawprint}" DRY_RUN="" BARE_METAL="" for arg in "$@"; do case $arg in --dry-run) DRY_RUN="--dry-run" ;; --bare-metal) BARE_METAL="true" ;; esac done cd "$SCRIPT_DIR/.." # Go to root (parent of ctrl/) # Common rsync options (using single .exclude file for everything) RSYNC_CMD="rsync -avz --mkpath --delete --progress --exclude-from=ctrl/.exclude" # ============================================================================= # BARE METAL DEPLOYMENT # ============================================================================= if [ -n "$BARE_METAL" ]; then echo "=== Deploying to Bare Metal (Systemd Services) ===" echo "" # Only sync pawprint source if [ -d "$LOCAL_PAWPRINT" ] && [ -f "$LOCAL_PAWPRINT/main.py" ]; then echo "Syncing pawprint source to bare metal..." $RSYNC_CMD $DRY_RUN \ "$LOCAL_PAWPRINT/" \ "$SERVER:$BARE_METAL_PATH/" echo " ✓ Pawprint synced to $BARE_METAL_PATH" else echo "⚠ Pawprint not found at: $LOCAL_PAWPRINT" exit 1 fi echo "" if [ -n "$DRY_RUN" ]; then echo "=== Dry run complete ===" exit 0 fi echo "=== Bare Metal Sync Complete ===" echo "" echo "Next steps on server (as mariano user):" echo " Restart systemd services:" echo " sudo systemctl restart pawprint artery album ward" echo "" echo " Check status:" echo " sudo systemctl status pawprint artery album ward" echo "" exit 0 fi # ============================================================================= # DOCKER DEPLOYMENT (DEFAULT) # ============================================================================= echo "=== Deploying to Docker ===" echo "" # 1. Sync core_nest structure (excluding src directories - they're synced separately) echo "1. Syncing core_nest structure..." $RSYNC_CMD $DRY_RUN \ --exclude='*/src/' \ ./ \ "$SERVER:$REMOTE_PATH/" echo " [OK] Core nest structure synced" echo "" # 2. Sync amar backend source if [ -d "$LOCAL_AMAR_BACKEND" ]; then echo "2. Syncing amar backend source..." $RSYNC_CMD $DRY_RUN \ "$LOCAL_AMAR_BACKEND/" \ "$SERVER:$REMOTE_PATH/amar/src/back/" echo " [OK] Backend synced" else echo "2. [WARN] Backend source not found at: $LOCAL_AMAR_BACKEND" fi echo "" # 3. Sync amar frontend source if [ -d "$LOCAL_AMAR_FRONTEND" ]; then echo "3. Syncing amar frontend source..." $RSYNC_CMD $DRY_RUN \ "$LOCAL_AMAR_FRONTEND/" \ "$SERVER:$REMOTE_PATH/amar/src/front/" echo " [OK] Frontend synced" else echo "3. [WARN] Frontend source not found at: $LOCAL_AMAR_FRONTEND" fi echo "" # 4. Sync pawprint source if [ -d "$LOCAL_PAWPRINT" ] && [ -f "$LOCAL_PAWPRINT/main.py" ]; then echo "4. Syncing pawprint source..." $RSYNC_CMD $DRY_RUN \ "$LOCAL_PAWPRINT/" \ "$SERVER:$REMOTE_PATH/pawprint/src/" echo " [OK] Pawprint synced" else echo "4. [INFO] Pawprint not found at: $LOCAL_PAWPRINT" fi echo "" # 5. Sync tests to ward (silent fail if not available) if [ -z "$DRY_RUN" ]; then echo "5. Syncing tests to ward..." if SILENT_FAIL=true "$SCRIPT_DIR/sync-tests.sh" >/dev/null 2>&1; then echo " [OK] Tests synced" else echo " [SKIP] Tests sync not configured or not available" fi echo "" fi if [ -n "$DRY_RUN" ]; then echo "=== Dry run complete ===" exit 0 fi echo "=== Docker Sync Complete ===" echo "" echo "Next steps on server (as mariano user):" echo " 1. Setup (first time only):" echo " ssh $SERVER 'cd $REMOTE_PATH/ctrl/server && ./setup.sh'" echo "" echo " 2. Setup test symlinks (optional, enables test sharing):" echo " ssh $SERVER 'cd $REMOTE_PATH/ctrl/server && ./setup-symlinks.sh'" echo " Or sync tests without symlinks: ./ctrl/sync-tests.sh" echo "" echo " 3. Build and start:" echo " ssh $SERVER 'cd $REMOTE_PATH/ctrl && ./build.sh && ./start.sh -d'" echo "" echo "Note: Bare metal services remain running as fallback (*.bare.mcrn.ar)"