diff --git a/bin/deploy b/bin/deploy new file mode 100755 index 00000000..24c15fb8 --- /dev/null +++ b/bin/deploy @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +set -euo pipefail + +cd "$(dirname "$0")/.." + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +log() { echo -e "${GREEN}==> $1${NC}"; } +warn() { echo -e "${YELLOW}==> $1${NC}"; } +die() { echo -e "${RED}ERROR: $1${NC}" >&2; exit 1; } + +# Ensure we're in a clean state +log "Checking working tree..." +if [ -n "$(git status --porcelain)" ]; then + die "Working tree is dirty. Commit or stash changes first." +fi + +# Pull latest from both branches +log "Pulling latest from origin..." +git fetch origin + +# Sync production image changes into main +log "Checking for CI image updates on production..." +git checkout production +git pull origin production + +IMAGE_COMMITS=$(git log main..production --oneline --grep="update production image" | wc -l | tr -d ' ') +if [ "$IMAGE_COMMITS" -gt "0" ]; then + log "Found $IMAGE_COMMITS image update(s) on production, merging into main..." + git checkout main + git merge production --no-edit +else + git checkout main +fi + +git pull origin main + +# Run all tests +log "Running precommit checks (compile + format + tests)..." +if ! mix precommit; then + die "Precommit checks failed. Fix issues before deploying." +fi + +# Push main (triggers staging deploy via Dokku) +log "Pushing to main (staging)..." +git push origin main + +# Merge main into production and push (triggers CI pipeline) +log "Merging main into production..." +git checkout production +git merge main --no-edit +git push origin production + +# Switch back to main +git checkout main + +log "Deploy triggered." +echo "" +echo " Staging: pushed to main (Dokku auto-deploys)" +echo " Production: pushed to production (CI runs tests, builds image, FluxCD applies)" +echo "" +echo " Monitor CI: https://git.mcintire.me/graham/towerops-web/actions" +echo " Monitor k8s: kubectl rollout status deployment/towerops -n towerops"