47 lines
1.8 KiB
Bash
Executable File
47 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
||
set -euo pipefail
|
||
|
||
# ==============================================================================
|
||
# SAQEL PLATFORM - DEPLOY & GIT SYNCHRONIZATION SCRIPT
|
||
# ==============================================================================
|
||
|
||
if [ -n "$1" ]; then
|
||
COMMIT_MSG="$1"
|
||
else
|
||
COMMIT_MSG="Update Saqel Platform: $(date +'%Y-%m-%d %H:%M:%S')"
|
||
fi
|
||
|
||
echo "📦 Staging all files..."
|
||
git add .
|
||
|
||
echo "📝 Committing: $COMMIT_MSG"
|
||
if git diff --cached --quiet; then
|
||
echo "ℹ️ No staged changes to commit."
|
||
else
|
||
git commit -m "$COMMIT_MSG"
|
||
fi
|
||
|
||
echo "🚀 Pushing to origin..."
|
||
git push origin main
|
||
echo "✅ Done! On the production server run:"
|
||
echo " git pull"
|
||
echo " (and if websocket server changed: php backend/websocket/server.php restart -d)"
|
||
|
||
# Optional remote continuation. Never guesses a host and never applies DDL
|
||
# unless the operator explicitly opts in after seeing status and dry-run.
|
||
if [ -n "${DEPLOY_SSH_TARGET:-}" ]; then
|
||
APP_DIR="${DEPLOY_APP_DIR:-/var/www/saqel}"
|
||
echo "🔐 Updating remote work tree: ${DEPLOY_SSH_TARGET}:${APP_DIR}"
|
||
ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && git pull --ff-only origin main"
|
||
echo "🔎 Remote migration status"
|
||
ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && php backend/scripts/run_migrations.php --status"
|
||
echo "🧪 Remote migration dry-run"
|
||
ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && php backend/scripts/run_migrations.php --dry-run"
|
||
if [ "${DEPLOY_RUN_MIGRATIONS:-0}" = "1" ]; then
|
||
echo "🚧 Applying remote migrations by explicit opt-in"
|
||
ssh "$DEPLOY_SSH_TARGET" "cd $(printf '%q' "$APP_DIR") && php backend/scripts/run_migrations.php"
|
||
else
|
||
echo "⏸️ Migrations were not applied. Set DEPLOY_RUN_MIGRATIONS=1 after reviewing dry-run."
|
||
fi
|
||
fi
|