Deployment overview
Prerequisites
Before deploying, ensure:- PR is merged: Your changes are in the
mainbranch - Tests pass: All CI checks are green
- AWS credentials: GitHub Actions has access to AWS (configured in repository secrets)
- Secrets configured: Required secrets are in AWS Secrets Manager
Deployment to staging
Step 1: Create a pre-release
- Go to the Releases page
- Click Draft a new release
- Fill in the release form:
- Tag:
v0.1.0-rc.1(increment the RC number for each staging release) - Release title:
v0.1.0-rc.1 - Staging Release - Description: Describe what changed
- ✅ Check: “Set as a pre-release”
- Tag:
- Click Publish release
Step 2: Monitor the deployment
The deployment workflow will automatically start. Monitor it in the Actions tab. Workflow steps:- Checkout code - Clone the repository
- Set up Go - Install Go 1.23.1
- Run tests - Execute integration tests
- Build Docker image - Create container image
- Push to ECR - Upload image to staging ECR
- Terraform apply - Update infrastructure
- Wait for deployment - ECS rolling deployment
- Smoke test - Verify
/healthzendpoint
Step 3: Verify the deployment
Once the workflow completes:Step 4: Test your changes
Deployment to production
Step 1: Verify staging
Before deploying to production:- Test thoroughly on staging
- Check CloudWatch logs for errors
- Monitor CloudWatch alarms for anomalies
- Get approval from team lead (if required)
Step 2: Create a full release
- Go to the Releases page
- Click Draft a new release
- Fill in the release form:
- Tag:
v0.1.0(same version as staging, without-rc.X) - Release title:
v0.1.0 - Production Release - Description: Describe what changed
- ❌ Do NOT check: “Set as a pre-release”
- Tag:
- Click Publish release
Step 3: Monitor the deployment
The production deployment workflow will start automatically. Monitor it in the Actions tab. Production deployment is identical to staging, but targets the production AWS account and domain.Step 4: Verify the deployment
Step 5: Monitor production
After deployment, monitor:- CloudWatch logs:
/ecs/prod/address-api - CloudWatch alarms: Check for any triggered alarms
- Better Stack: Monitor API call metrics and error rates
- ECS service: Verify all tasks are healthy
Deployment workflow details
GitHub Actions workflow
The deployment is handled by.github/workflows/deploy-app.yml:
Environment detection
The workflow automatically detects the environment based on the release tag:| Tag format | Environment | Example |
|---|---|---|
v*-rc.* | Staging | v0.1.0-rc.1 |
v* (no rc) | Production | v0.1.0 |
Docker image tagging
Images are tagged with the release version:| Environment | Image tag | ECR repository |
|---|---|---|
| Staging | v0.1.0-rc.1 | 127214192604.dkr.ecr.ap-south-1.amazonaws.com/staging/address-api |
| Production | v0.1.0 | 429032495558.dkr.ecr.ap-south-1.amazonaws.com/prod/address-api |
Terraform apply
The workflow runs Terraform to update the infrastructure:- ECS task definition (with new image tag)
- Secrets Manager (with latest secrets)
- Any infrastructure changes from code
ECS rolling deployment
ECS performs a rolling deployment with these settings:| Setting | Value | Description |
|---|---|---|
| Minimum healthy percent | 100% | Keep all tasks running during deployment |
| Maximum percent | 200% | Can run double the tasks temporarily |
| Circuit breaker | Enabled | Automatically rollback on failure |
| Health check grace period | 60 seconds | Wait before checking health |
- Start new tasks with new image
- Wait for new tasks to pass health checks
- Drain connections from old tasks
- Stop old tasks
- Repeat until all tasks are updated
Smoke test
After deployment, the workflow tests the/healthz endpoint:
Rollback
If a deployment fails or causes issues, you can rollback:Automatic rollback
The ECS circuit breaker automatically rolls back if:- New tasks fail health checks
- New tasks crash repeatedly
- Deployment doesn’t stabilize within 10 minutes
Manual rollback
To manually rollback to a previous version:- Find the previous release tag (e.g.,
v0.0.9) - Redeploy the previous version:
- Go to Releases
- Find the previous release
- Click “Edit release”
- Click “Update release” (this triggers a new deployment)
Deployment checks
The deployment workflow includes several checks:| Check | Description | Failure action |
|---|---|---|
| Integration tests | Run full test suite | Abort deployment |
| Docker build | Build container image | Abort deployment |
| Terraform plan | Preview infrastructure changes | Abort deployment |
| ECS deployment | Rolling update of tasks | Circuit breaker rollback |
| Smoke test | Health check endpoint | Mark deployment as failed |
Deployment frequency
| Environment | Typical frequency | Purpose |
|---|---|---|
| Staging | Multiple times per day | Test new features and bug fixes |
| Production | 1-2 times per week | Stable releases only |
Deployment notifications
Deployment status is reported in:- GitHub Actions: Workflow status and logs
- Slack (if configured): Deployment start/success/failure notifications
- Better Stack: Deployment events and metrics
Troubleshooting deployments
Deployment stuck at “Waiting for ECS deployment”
Cause: New tasks are failing health checks. Fix:- Check CloudWatch logs for errors
- Verify the health check endpoint is responding
- Check security group rules
- Verify secrets are correct
Error: “Image not found in ECR”
Cause: Docker image wasn’t pushed successfully. Fix:- Check the “Build and push Docker image” step in GitHub Actions
- Verify ECR repository exists
- Check AWS credentials
Error: “Terraform apply failed”
Cause: Infrastructure changes have errors. Fix:- Review the Terraform plan output
- Check for resource conflicts
- Verify AWS permissions
Circuit breaker triggered rollback
Cause: New tasks are unhealthy or crashing. Fix:- Check CloudWatch logs for crash reasons
- Verify environment variables and secrets
- Test the Docker image locally
- Check database connectivity
Best practices
Before deploying
- ✅ Run tests locally
- ✅ Test on staging first
- ✅ Review Terraform plan
- ✅ Check for breaking changes
- ✅ Update documentation
During deployment
- ✅ Monitor GitHub Actions workflow
- ✅ Watch CloudWatch logs
- ✅ Check ECS service events
- ✅ Monitor CloudWatch alarms
After deployment
- ✅ Verify health endpoint
- ✅ Test critical endpoints
- ✅ Monitor error rates
- ✅ Check Better Stack metrics
- ✅ Update release notes