NB:- this is just a placeholder you can follow, you can improve and even revamp to fit the applications you use
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.
- 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).
-
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
.
-
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.
- In the GitHub Actions workflow file, replace:
- 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).
- Replace Placeholders:
-
Set Up OpenTofu Configuration:
- Replace Placeholders:
- In the OpenTofu files, replace:
YOURAWSREGION
with your AWS region.MYECRREPO
with your container ECR REPO nameYOURROUTE53ZONEID
with your Route 53 zone ID.YOURORGNAME
with your GitHub organization name.
- In the OpenTofu files, replace:
- Initialize and Apply OpenTofu:
- Run
OpenTofu init
to initialize the configuration. - Run
OpenTofu apply
to set up AWS resources.
- Run
- Replace Placeholders:
-
Prepare the Application Code:
- Ensure the Dockerfile and application code are in your GitHub repository.
-
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.
- Push changes to the
- 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.
- 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.
- 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.