This project demonstrates a blue-green deployment strategy for a Node.js application using AWS services including ECS, CodeCommit, CodeBuild, CodeDeploy, and CodePipeline.
Blue-green deployment is a technique that reduces downtime and risk by running two identical production environments called Blue and Green. At any time, only one of the environments is live, with the live environment serving all production traffic. For this project, the Blue environment is the current live version serving traffic, and the Green environment is a new version to be released.
By using ECS (Elastic Container Service), we can define our application in a Docker container and then deploy it to safely switch traffic between two identical environments.
Here's how each service helps in the blue-green deployment process:
- AWS CodeCommit: Used to store the source code of the Node.js application. This can also be replaced by other source control tools like GitHub or GitLab.
- AWS CodeBuild: Builds the Docker image of the application and pushes it to AWS ECR (Elastic Container Registry).
- AWS CodeDeploy: Manages the deployment process, allowing a switch from blue to green environment without downtime.
- AWS CodePipeline: Orchestrates the workflow that integrates CodeCommit, CodeBuild, and CodeDeploy to enable continuous integration and delivery.
- AWS Account.
- Docker installed on your local machine.
- AWS CLI installed and configured.
Fork or clone this repository using AWS CodeCommit or another source control tool:
git clone <repository-url>
This project is configured to use AWS CodeBuild which will automatically build the Docker image from the Dockerfile
present in the repository and push it to ECR.
Configure CodeBuild project to link it to your repository and specify build specifications in buildspec.yaml
.
Ensure CodeBuild is set up to push the Docker image to your ECR repository. Use the following AWS CLI commands to create a repository:
aws ecr create-repository --repository-name node-app --region us-east-1
Create an ECS cluster and define an ECS service with a task definition(taskdef.json
) that refers to the Docker image in ECR.
Set up CodeDeploy to manage the deployment of the new image from the ECR to the ECS service. CodeDeploy will automate the process of launching new tasks with the new image and terminating the old tasks. Define scripts in appspec.yaml
Create a CodePipeline that integrates CodeCommit, CodeBuild, and CodeDeploy:
- Source Stage: Triggered when a change is pushed to the source repository.
- Build Stage: Builds the Docker image and pushes it to ECR.
- Deploy Stage: Deploy the new image to ECS using CodeDeploy.
Through CodePipeline's simple console, you can visualize and manage the flow of updates through each stage.
By following these setup steps, you have created a robust pipeline for blue-green deployments for a Node.js application on ECS using Docker and AWS services. This approach minimizes downtime during application feature updates and improves rollback capabilities in production environments.