Getting Started with BGDeployer

 

What is BGDeployer ?

BGDeployer is a shell script-based blue-green deployment solution designed for seamless deployment with minimal downtime, leveraging AWS services and tools like Auto Scaling Groups (ASGs), Application Load Balancer (ALB), CloudWatch, and Ansible.

Key Components of BGDeployer

  1. Amazon Web Services (AWS):
    • ASGs (Auto Scaling Groups): Two distinct ASGs are maintained—Blue (current production environment) and Green (staging/testing environment for new builds).
    • Application Load Balancer (ALB): Handles traffic routing between the Blue and Green environments using target groups.
    • S3: Stores build artifacts and deployment metadata (e.g., build numbers, deployment configurations).
    • CloudWatch: Monitors traffic and validates deployment metrics.
  2. Shell Script:
    • The deployment logic is implemented using AWS CLI commands.
    • Allows dynamic operations like launching new ASGs, attaching target groups, updating configurations, and validating deployments.
  3. Ansible:
    • Handles configuration management for instances within the ASG during the deployment process.
    • Ensures that instances are provisioned with the necessary dependencies, configurations, and application code.
  4. Traffic Validation:
    • CloudWatch metrics and alarms are used to monitor the health of the Green environment during testing.
    • Validates metrics like HTTP response codes, instance health, and latency before switching traffic.
  5. Blue-Green Switch:
    • After successful validation of the Green environment, ALB gradually shifts traffic from the Blue ASG to the Green ASG.
    • Supports weighted traffic distribution for canary testing.
  6. Jenkins Integration:
    • BGDeployer can be triggered by Jenkins as part of the CI/CD pipeline, passing parameters like the build number and traffic percentage.
    • Enables automated, parameterized deployment workflows.

How BGDeployer Works

  1. Preparation:
    • Fetch the latest build from S3 based on the provided build number.
    • Spin up instances in the Green ASG with the specified AMI, initializing them with Ansible playbooks for the application and environment setup.
  2. Staging and Testing:
    • Attach the Green ASG instances to a dedicated ALB target group for testing.
    • Run validation scripts or simulate traffic to ensure that the Green environment is stable and ready.
  3. Weighted Traffic Shifting:
    • Use ALB’s weighted routing feature to send a percentage of traffic to the Green environment for canary testing.
    • Monitor key metrics via CloudWatch to ensure that the Green environment handles the traffic without issues.
  4. Full Traffic Switch:
    • If validation passes, update the ALB to shift 100% of traffic to the Green environment.
    • Detach the Blue ASG from the ALB but retain it for rollback if needed.
  5. Rollback (if necessary):
    • In case of a failure during or after deployment, revert traffic back to the Blue environment.
    • Utilize Ansible to debug and fix issues in the Green environment.

Features and Benefits

  • Zero Downtime Deployment: Ensures uninterrupted service to users during deployments.
  • Traffic Validation: Protects against failures by validating new changes in a controlled environment.
  • Automated Rollback: Quickly reverts to the previous version in case of issues.
  • Scalable and Flexible: Works seamlessly with different application types and AWS environments.
  • Simple Configuration Management: Uses Ansible to manage server configurations and application setup dynamically.

Use Cases

  1. Production Deployments:
    • Deploy updates for web applications or APIs with high availability requirements.
  2. Canary Releases:
    • Gradually roll out new features to a subset of users for testing before full-scale deployment.
  3. Disaster Recovery:
    • Utilize Blue-Green ASG pairs to maintain backup environments for rapid recovery.