Skip to content

saintmalik/blue-green-ec2

Repository files navigation

Blue-Green CI/CD Pipeline Setup Guide

NB:- this is just a placeholder you can follow, you can improve and even revamp to fit the applications you use

Overview

This pipeline automates the build and continous deployment of a Go application containerized with Docker. It interacts with AWS services like ECR, SSM, and IAM, and uses OpenTofu to manage AWS infrastructure.

Prerequisites

  • An AWS account with necessary permissions.
  • OpenTofu installed on your machine.
  • zip the ansible-playbook folder and upload to your s3 bucket, this is needed because that how the user-script from locals.tf works.
  • A GitHub repository with your Go application code, thats where you will create the ci-cd.yaml here into
  • Slack integration for notifications (optional but recommended).

Step-by-Step Setup

  1. Set Up AWS Credentials:

    • Create an IAM role and policies as defined in the OpenTofu configuration.
    • Ensure that the GitHub Actions workflow has the necessary permissions via AWS_ROLE_ARN.
  2. Configure GitHub Actions:

    • Replace Placeholders:
      • In the GitHub Actions workflow file, replace:
        • YOURAWSREGION with your AWS region.
        • YOURECRREPO with your ECR repository name.
        • Other placeholders as needed.
    • Set Up GitHub Secrets:
      • Go to your repository's Settings > Secrets > Actions.
      • Add AWS_ROLE_ARN for AWS credentials.
      • Add SLACK_WEBHOOK_URL for Slack notifications (if used).
  3. Set Up OpenTofu Configuration:

    • Replace Placeholders:
      • In the OpenTofu files, replace:
        • YOURAWSREGION with your AWS region.
        • MYECRREPO with your container ECR REPO name
        • YOURROUTE53ZONEID with your Route 53 zone ID.
        • YOURORGNAME with your GitHub organization name.
    • Initialize and Apply OpenTofu:
      • Run OpenTofu init to initialize the configuration.
      • Run OpenTofu apply to set up AWS resources.
  4. Prepare the Application Code:

    • Ensure the Dockerfile and application code are in your GitHub repository.
  5. Test the Pipeline:

    • Push changes to the dev or whatever branch you use to trigger the workflow.
    • Monitor the GitHub Actions workflow for successful completion.
    • Verify that the EC2 instances are updated with the new Docker image.

Blue-Green Deployment Explanation

  • Blue-Green Deployment: This strategy involves running two identical production environments (Blue and Green). At any time, only one environment is active. When you deploy a new version, it is deployed to the inactive environment (Green), tested, and then traffic is switched to it, making it the active environment.
  • Implementation in Setup:
    • The pipeline is configured to deploy new versions to a staging environment.
    • Once verified, it can be promoted to the production environment.

Troubleshooting Tips

  • AWS IAM Policies: Ensure that the IAM role has the correct permissions for ECR, SSM, and other services.
  • Docker Build and Push: Verify that the Docker build and push steps in the workflow are correctly configured.
  • Slack Webhook: Confirm that the Slack webhook URL is correctly set in GitHub Secrets.

Best Practices

  • Environment Separation: Use separate environments for staging and production.
  • Security Measures: Regularly review and update IAM policies and security settings.
  • Monitoring and Logging: Implement monitoring and logging to track pipeline and application performance.

This guide provides a clear path to setting up your Blue-Green CI/CD pipeline, ensuring smooth and automated deployments of your Go application.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published