BG Deployer is a Linux shell script wrapper around AWS CLI that automates blue-green and canary deployments. Itβs designed to simplify backend application deployments with minimal changes to your Auto Scaling Groups (ASGs) or Application Load Balancers (ALBs).
This script provides a fully automated, zero-downtime deployment experience by managing ASG counts and ALB listener rules, leaving the actual deployment tasks to be configured in the instance userdata (e.g., using Ansible playbooks).
π§ Key Features
- π― Fully Automated: Streamlined deployment with zero downtime.
- β‘ Flexible: Customizable to suit any deployment process.
- π οΈ Full Userdata Control: Configure deployments remotely via userdata scripts.
- π Easy Rollbacks: Automated/manual rollback in case of deployment failures.
- π¦ Traffic Control: Gradual traffic migration from 1% to 100% for smooth transitions.
- β
Success Checks: Optional validation of
2xx
HTTP requests to ensure deployment success. - π Faster Deployments: Dynamic, optimized executionβusually under 2 minutes (depends on userdata execution).
- πΌ Simplified Rollbacks: Reset to the previous version effortlessly.
- π Scheduled Actions: Migrates active ASG schedules without hassle.
π Prerequisites
To use BG Deployer effectively:
- Infrastructure Requirements:
- Two ASGs: One for the Blue environment and one for the Green environment.
- Weighted traffic routing configured at the ALB level.
- Required tags added to both ASGs (explained below).
- Linux Packages:
- AWS CLI (v2): For interacting with AWS resources.
- Common Linux utilities:
jq
,awk
,grep
, etc.
- Jenkins Integration:
- Jenkins server with access to your ASGs.
- Configured jobs for build creation and deployment.
π₯οΈ How It Works
BG Deployer operates by managing the ASG counts and ALB listener rules. The deployment process involves:
- π Preparing the Green Environment:
- Increase the instance count of the passive ASG (Green) to match the active ASG (Blue).
- Userdata handles the deployment using Ansible playbooks configured in EC2.
- π Traffic Shifting:
- Gradually shifts traffic to the Green environment via ALBβs weighted traffic routing.
- Monitors traffic metrics using AWS CloudWatch.
- β
Validation:
- Evaluates deployment success based on 2xx HTTP response codes or other predefined metrics.
- π Rollback (if required):
- Reverts traffic to the Blue environment in case of any issues.
- π§ Update Tags and Resources:
- Dynamically updates ASG tags, ALB listener rules, and ASG scheduled actions.
π Important Notes
- BG Deployer controls only ASG counts and traffic routing; it does not execute deployment steps directly on instances.
- Deployment logic (e.g., pulling builds, configuring applications) must be defined in Userdata.
For example, Ansible playbooks can be included in Userdata to automate deployments on ASG instances.
ποΈ Setup Requirements
1οΈβ£ Infrastructure Prerequisites
- Two ASGs (e.g.,
blue
andgreen
) configured with BG Deployer Tags. - Weighted traffic routing enabled at ALB level.
- Proper IAM roles and permissions for AWS CLI operations.
2οΈβ£ BG Deployer Tags for ASGs
Add the following tags to both ASGs:
Tag | Required | Blue ASG | Green ASG | Type | Remarks |
---|---|---|---|---|---|
TechTeam |
β | project-abc | project-abc | Static | Identifies the project team. |
Environment |
β | Staging | Staging | Static | Defines the environment (e.g., Staging, Prod). |
Stack |
β | myapp-stage | myapp-stage | Static & Unique | Unique identifier for the app stack. |
Service |
β | myapp-stage-blue | myapp-stage-green | Static & Unique | Used for remote Ansible runs. |
BuildType |
β | rpm or jar | rpm or jar | Static | Defines the type of build artifact. |
Cluster |
β | blue | green | Static | Denotes the ASG type (blue/green). |
ActiveCluster |
β | blue | blue | Dynamic | Dynamically updated during deployment. |
3οΈβ£ Build Creation
-
A Jenkins job creates the application build (
.jar
,.rpm
,.war
) and uploads it to S3 in the following structure:s3://<bucket>/<project>/<env>/builds/<Build_Profile>/<Stack>/<AppName>/<BuildNo>-<Branch>-<Build_Profile>-<AppName>-<Build_TimeStamp>.<extension>
Example:
s3://mys3bucket/project/nonprod/builds/stage/myapp-stage/myapp-name/73-develop-stage-myapp-name-27Jul23-09-20.rpm
4οΈβ£ Deployment Execution
- Trigger a Jenkins deployment job that runs the BG Deployer script with specified parameters (e.g., build number, traffic percentage).
- The script performs the following:
- Identifies the passive ASG (e.g., Green) and updates its instance count to match the active ASG.
- Updates ASG tags:
ActiveCluster
tag is toggled betweenblue
andgreen
.
- Modifies ALB listener rules to route traffic safely.
- Migrates scheduled actions to the active ASG.
5οΈβ£ Userdata Configuration
- Configure userdata for ASGs to deploy the correct build.
- The userdata script should:
- Download the build info file (
yaml
,sh
) from S3. - Deploy the specified build artifact (e.g.,
filename.jar
).
- Download the build info file (
6οΈβ£ Traffic Migration
- Gradually migrate traffic from the Blue environment to the Green environment based on the specified percentage.
- Monitor deployment success using optional
2xx
checks.
7οΈβ£ Rollback (if necessary)
- If any stage fails, BG Deployer can revert traffic back to the Blue environment.
- Manual or automated rollbacks ensure minimal downtime and quick recovery.
π Workflow
(Editable in diagrams.net)
π₯ Download and Setup
- Download BG Deployer Script:
wget https://github/repo/owner/src/master/extras/bgdeployer-v3.sh chmod +x bgdeployer-v3.sh
- Run the Script:
Integrate it with your Jenkins pipeline for deployment automation.
π Why Choose BG Deployer?
- Automates complex deployments with ease.
- Provides robust traffic control for safer transitions.
- Simplifies integration with existing blue-green infrastructure.
- Enables faster, dynamic deployments.
π₯ Conclusion
BG Deployer simplifies Blue-Green and Canary deployments with zero-downtime, dynamic traffic control, and robust rollback mechanisms. Itβs fast, efficient, and integrates seamlessly with existing infrastructure.
π Ready to optimize your deployments? Try BG Deployer now! π