add bin/deploy script for production deployments
This commit is contained in:
parent
7251930404
commit
fd8f39451c
1 changed files with 66 additions and 0 deletions
66
bin/deploy
Executable file
66
bin/deploy
Executable file
|
|
@ -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"
|
||||
Loading…
Add table
Reference in a new issue