Rollback System Quick Reference
cd " $HOME /api"
./scripts/deploy.sh < SHA>
Rollback to Previous Version
cd " $HOME /api"
./scripts/deploy.sh --rollback
Rollback (non-interactive, for CI)
./scripts/deploy.sh --rollback --auto
./scripts/deploy.sh 7b3e9f1
Every successful deployment prepends image SHA to .deploy_history
History maintains last 5 deployments (newest first)
Rollback reads line 2 from .deploy_history and redeploys that image
Blue-green deployment ensures zero downtime
Health checks validate before switching traffic
┌──────────────┐
│ CI builds │
│ image SHA │
└──────┬───────┘
│
▼
┌──────────────────┐
│ deploy-blue │
│ green.sh <SHA> │
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Pull image │
│ Start container │
│ Health check │
│ Switch nginx │
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Prepend SHA to │
│ .deploy_history │
│ (keep last 5) │
└──────────────────┘
┌──────────────────┐
│ ./deploy.sh │
│ --rollback │
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Read .deploy_ │
│ history (line 2) │
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Show history & │
│ confirm with user│
└──────┬───────────┘
│
▼
┌──────────────────┐
│ deploy-blue │
│ green.sh <SHA> │
└──────────────────┘
✅ Interactive confirmation before rollback
✅ Health check validation (20 attempts × 3s)
✅ Nginx config validation before reload
✅ Automatic cleanup on failure
✅ Zero downtime blue-green deployment
✅ Immutable image SHAs
/api/
├── scripts/
│ └── deploy.sh # Deploy and rollback
└── .deploy_history (last 5 SHAs)
# Deploy new version
$ ./scripts/deploy.sh b8c4d2e
[DEPLOY] state=PULL_IMAGE ...
[DEPLOY] state=START_INACTIVE ...
[DEPLOY] state=HEALTH_CHECK_INTERNAL ...
[DEPLOY] state=SWITCH_NGINX ...
[DEPLOY] state=SUCCESS duration_sec=18
# Issue discovered - rollback
$ ./scripts/deploy.sh --rollback
Current deployment : b8c4d2e
Previous deployment: a4f91c2
Deployment history:
1. b8c4d2e (current)
2. a4f91c2 ← rollback target
3. 7b3e9f1
⚠️ WARNING: This will redeploy the previous version.
Current production will be replaced with: a4f91c2
Continue with rollback? (yes/no): yes
[DEPLOY] state=SUCCESS duration_sec=9 msg=DEPLOY_SUCCESS
Production is now running: a4f91c2
Issue
Solution
Script not executable
chmod +x scripts/deploy.sh
No deployment history
Deploy at least once before rollback
Insufficient history
Need at least 2 deployments to rollback
Image not found
Verify SHA exists in GHCR
Health check fails
Check logs: docker logs api-blue
Rollback time: <10 seconds
Health check: Up to 60 seconds
Zero downtime: Always maintained