scripts/push-deploy.sh
2025-12-27 17:23:31 -08:00

46 lines
1.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Push local changes to the remote and deploy on the nexus-vector host.
# Usage:
# ./scripts/push-deploy.sh # push current branch and deploy
# DRY_RUN=1 ./scripts/push-deploy.sh # show commands without executing
#
# Environment overrides:
# REMOTE=origin
# BRANCH=<current git branch>
# DEPLOY_HOST=nexus-vector
# DEPLOY_USER=root
# DEPLOY_PATH=/root/ANTIGRAVITY/honkingversion
set -euo pipefail
REMOTE="${REMOTE:-origin}"
BRANCH="${BRANCH:-$(git rev-parse --abbrev-ref HEAD)}"
DEPLOY_HOST="${DEPLOY_HOST:-nexus-vector}"
DEPLOY_USER="${DEPLOY_USER:-root}"
DEPLOY_PATH="${DEPLOY_PATH:-/root/ANTIGRAVITY/honkingversion}"
SSH_TARGET="${DEPLOY_USER}@${DEPLOY_HOST}"
DRY_RUN="${DRY_RUN:-0}"
info() { echo "[$(date +%H:%M:%S)] $*"; }
run() {
if [ "$DRY_RUN" != "0" ]; then
echo "DRY RUN: $*"
else
eval "$@"
fi
}
# Require clean working tree when actually deploying to avoid pushing unintended files.
if [ "$DRY_RUN" = "0" ] && [ -n "$(git status --porcelain)" ]; then
git status --short
echo "❌ Working tree is dirty. Commit or stash changes before deploying."
exit 1
fi
info "Pushing branch '$BRANCH' to '$REMOTE'..."
run "git push ${REMOTE} ${BRANCH}"
info "Deploying on ${SSH_TARGET}:${DEPLOY_PATH}..."
run "ssh ${SSH_TARGET} 'set -euo pipefail; cd ${DEPLOY_PATH} && git fetch ${REMOTE} ${BRANCH} && git checkout ${BRANCH} && git pull --ff-only ${REMOTE} ${BRANCH} && docker compose down && docker compose pull && docker compose up -d --build && docker compose ps'"
info "✅ Deploy complete."