πŸš€ BG Deployer: A Shell-Based Blue-Green Deployment Solution

 

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:

  1. 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).
  2. Linux Packages:
    • AWS CLI (v2): For interacting with AWS resources.
    • Common Linux utilities: jq, awk, grep, etc.
  3. 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:

  1. πŸš€ 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.
  2. πŸ”„ Traffic Shifting:
    • Gradually shifts traffic to the Green environment via ALB’s weighted traffic routing.
    • Monitors traffic metrics using AWS CloudWatch.
  3. βœ… Validation:
    • Evaluates deployment success based on 2xx HTTP response codes or other predefined metrics.
  4. πŸ”™ Rollback (if required):
    • Reverts traffic to the Blue environment in case of any issues.
  5. πŸ”§ 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 and green) 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:
    1. Identifies the passive ASG (e.g., Green) and updates its instance count to match the active ASG.
    2. Updates ASG tags:
      • ActiveCluster tag is toggled between blue and green.
    3. Modifies ALB listener rules to route traffic safely.
    4. 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).

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

BG Deployer Workflow
(Editable in diagrams.net)

πŸ“₯ Download and Setup

  1. Download BG Deployer Script:
    wget https://github/repo/owner/src/master/extras/bgdeployer-v3.sh
    chmod +x bgdeployer-v3.sh
    
  2. 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! πŸš€