#!/bin/bash # ════════════════════════════════════════════════════════════ # مُصادَق (Musadaq) — Production Synchronization Script # ════════════════════════════════════════════════════════════ # Usage: ./sync-to-server.sh "Your commit message" # ════════════════════════════════════════════════════════════ COMMIT_MESSAGE=$1 if [ -z "$COMMIT_MESSAGE" ] then COMMIT_MESSAGE="🚀 Musadaq deployment sync: $(date)" fi # ── 1. Push to Git ────────────────────────────────────────── echo "📤 Pushing changes to remote repository..." git add . git commit -m "$COMMIT_MESSAGE" git push origin main # ── 2. Deploy to Production ───────────────────────────────── # Update the variables below with your VPS credentials SERVER_USER="musadaq" SERVER_IP="194.163.173.157" # Contabo VPS PROJECT_DIR="/home/intaleqapp-musadeq/htdocs/musadeq.intaleqapp.com" echo "🌐 Synchronizing with production server ($SERVER_IP)..." ssh $SERVER_USER@$SERVER_IP << EOF set -e # Check for Docker Compose command if docker compose version > /dev/null 2>&1; then DOCKER_CMD="docker compose" else DOCKER_CMD="docker-compose" fi echo "🔐 Configuring Git safe directory..." git config --global --add safe.directory $PROJECT_DIR cd $PROJECT_DIR if [ ! -d ".git" ]; then echo "🌑 Initializing production repository (Force setup)..." git init git config --global --add safe.directory $PROJECT_DIR git remote add origin https://git.intaleqapp.com/Hamza/musadeq.git git fetch --all git reset --hard origin/main else echo "⬇️ Pulling latest changes from Git..." git remote add origin https://git.intaleqapp.com/Hamza/musadeq.git 2>/dev/null || true git fetch --all git reset --hard origin/main fi if [ -f "docker-compose.yml" ]; then echo "🧹 Cleaning up old containers and orphans..." \$DOCKER_CMD down --remove-orphans || true echo "🏗️ Rebuilding and starting production containers using \$DOCKER_CMD..." \$DOCKER_CMD up -d --build echo "🗄️ Running database migrations..." \$DOCKER_CMD exec -T api npm run migration:run:prod else echo "❌ Error: docker-compose.yml not found!" exit 1 fi echo "✅ Deployment successful at \$(date)!" EOF echo "✨ Sync completed successfully!"