Hi [C***e N***e],
Below is a pared-down example from our Jenkinsfile and an excerpt of our ECS task definition to illustrate exactly how we handle env vars, secrets, health checks and autoscaling for blue/green vs. canary deployments.
1. Jenkinsfile Snippet (Migrate/Rollback)
```
pipeline {
agent any
environment {
DB_HOST = credentials('prod-db-host')
DB_USER = credentials('prod-db-user')
DB_PASSWORD = credentials('prod-db-pass')
AWS_CREDS = credentials('aws-deploy-creds')
APP_ENV = 'production'
}
stages {
stage('Pre-Migration Snapshot') {
steps {
withAWS(credentials: 'aws-deploy-creds', region: 'us-east-1') {
sh 'aws rds create-db-snapshot --db-instance-identifier mydb --db-snapshot-identifier snapshot-$(date +%s)'
}
}
}
stage('Run Migrations') {
steps {
sh '''
docker run --rm \
-e DB_HOST=$DB_HOST -e DB_USER=$DB_USER -e DB_PASSWORD=$DB_PASSWORD \
myapp:${GIT_COMMIT} \
bash -c "php artisan migrate --force"
'''
}
post {
failure {
echo 'Migration failed , rolling back...'
sh '''
docker run --rm \
-e DB_HOST=$DB_HOST -e DB_USER=$DB_USER -e DB_PASSWORD=$DB_PASSWORD \
myapp:${GIT_COMMIT} \
bash -c "php artisan migrate:rollback"
'''
error('Aborting pipeline after rollback')
}
}
}
}
}
```
Key points:
- We store DB creds and AWS keys in Jenkins Credentials, injected via `environment` and `withAWS`.
- On failure, the `post` block automatically triggers a `migrate:rollback`.
2. ECS Task Definition Excerpt & Autoscaling
```json
{
"family": "myapp-service",
"networkMode": "awsvpc",
"containerDefinitions": [
{
"name": "app",
"image": "123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:${TAG}",
"essential": true,
"portMappings": [{ "containerPort": 80, "protocol": "tcp" }],
"environment": [
{ "name": "APP_ENV", "value": "production" }
],
"secrets": [
{ "name": "DB_PASSWORD", "valueFrom": "arn:aws:ssm:...:parameter/prod/db/password" }
],
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost/health || exit 1"],
"interval": 30,
"timeout": 5,
"retries": 3,
"startPeriod": 60
}
}
]
}
```
Autoscaling & Deployment Strategies:
- Blue/Green (CodeDeploy):
• Initial shift: 10% traffic for smoke tests, ramp to 100% over 10 minutes.
• Rollback on any failing health check.
- Canary (Weighted ALB):
• We create a second target group, start at 5% weight for 15 minutes.
• CloudWatch alarms on 5xx error rate and CPU > 75% trigger rollback or weight increase.
• Gradually step to 25% → 50% → 100% if metrics stay healthy.
Would you like to walk through these configs live with our CTO and DevOps lead? I’m happy to book a 30-minute deep-dive,how does Tuesday 2pm or Wednesday 11am (UTC+5:30) look for you?
Best,
J***e