CI/CD DevOps: Steps To Create a CI/CD Pipeline With Jenkins, Containers, and Amazon ECS

CI/CD Pipelines with Docker is best way for an organization to improve code quality and deliver software releases quickly without any human errors. We hope this blog will help you about the integral parts of the CI/CD Docker Pipeline.

Let start with basis, What is a CI/CD pipeline, What are its workflow and phases along with deployment strategy.

What Is a CI/CD Pipeline?

A CI/CD (Continuous Integration Continuous Delivery) Pipeline is a set of instructions to automate the process of Software tests, builds, and deployments. Benefits of implementing CI/CD in your project are:

  1. Smaller code change: The ability of CI/CD Pipelines to allow the integration of a small piece of code at a time helps developers recognize any potential problem before too much work is completed.
  2. Faster delivery: Multiple daily releases or continual releases can be made a reality using CI/CD Pipelines.
  3. Observability: Having automation in place that generates extensive logs at each stage of the development process helps to understand if something goes wrong.
  4. Easier rollbacks: There are chances that the code that has been deployed may have issues. In such cases, it is very crucial to get back to the previous working release as soon as possible. One of the biggest advantages of using the CI/CD Pipelines is that you can quickly and easily roll back to the previous working release.
  5. Reduce costs: Having automation in place for repetitive tasks frees up the Developer and Operation guys’ time that could be spent on Product Development.

What are CI/CD Workflow and Phases?

CI/CD Workflow

CI and CD Workflow allows us to focus on Development while it carries out the tests, build, and deployments in an automated way. 

  1. Continuous Integration: This allows the developers to push the code to the Version Control System or  Source Code Management System, build & test the latest code pushed by the developer, and generate and store artifacts.
  2. Continuous Delivery: This is the process that lets us deploy the tested code to the Production whenever required.
  3. Continuous Deployment: This goes one step further and releases every single change without any manual intervention to the customer system every time the production pipeline passes all the tests. 

CI/CD Phases

The primary goal of the automated CI/CD pipeline is to build the latest code and deploy it. There can be various stages as per the need. The most common ones are mentioned below.

  1. Trigger: The CI/CD pipeline can do its job on the specified schedule when executed manually or triggered automatically on a particular action in the Code Repository.   
  2. Code pull: In this phase, the pipeline pulls the latest code whenever the pipeline is triggered.
  3. Unit tests: In this phase, the pipeline performs tests that are there in the codebase. This is also referred to as unit tests.
  4. Build or package: Once all the tests pass, the pipeline moves forward and builds artifacts or docker images in case of dockerized applications.
  5. Push or store: In this phase, the code that has been built is pushed to the Artifactory or Docker Repository in case of dockerized applications.
  6. Acceptance tests: This phase or stage of the pipeline validates if the software behaves as intended. It is a way to ensure that the software or application does what it is meant to do.
  7. Deploy: This is the final stage in any CI/CD pipeline. In this stage, the application is ready for delivery or deployment.

Simple DevOps Project – CI/CD With Git, Jenkins, Ansible, Docker And Kubernetes

Simple DevOps Project - CI/CD With Git, Jenkins, Ansible, Docker And Kubernetes

DevOps Automation Tools

CI/CD automation flow diagram

CI/CD Deployment Strategy

A deployment strategy is a way in which containers of the micro-services are taken down and added. There are various options available.

Rolling Updates

In rolling updates, the scheduler in the ECS Service replaces the currently running tasks with new ones. The tasks in the ECS cluster are nothing but running containers created out of the task definition. Deployment configuration controls the number of tasks that Amazon ECS adds or removes from the service. The lower and the upper limit on the number of tasks that should be running is controlled by minimumHealthyPercent and maximumPercent, respectively. 

  1. minimumHealthyPercent example: If the value of minimumHealthyPercent is 50 and the desired task count is four, then the scheduler can stop two existing tasks before starting two new tasks
  2. maximumPercent example: If the value of maximumPercent is four and the desired task is four, then the scheduler can start four new tasks before stopping four existing tasks.

Blue/Green Deployment

Blue/Green deployment strategy enables the developer to verify a new deployment before sending traffic to it by installing an updated version of the application as a new replacement task set.

There are primarily three ways in which traffic can shift during blue/green deployment.

  1. Canary – Traffic is shifted in two increments. The percentage of traffic shifted to your updated task set in the first increment and the interval, in minutes, before the remaining traffic is shifted in the second increment.
  2. Linear – Traffic is shifted in equal increments, the percentage of traffic shifted in each increment, and the number of minutes between each increment.
  3. All-at-once – All traffic is shifted from the original task set to the updated task set all at once.

Example: Steps To Create a CI/CD Pipeline With Jenkins, Containers, and Amazon ECS

Here is the summary of what you have to do to set up a CI/CD Docker pipeline to deploy a sample Java/Node.js application on AWS ECS using Jenkins. 

  1. Clone the existing sample GitHub Repository
  2. Create a new GitHub Repository and copy the code from the sample repository in it
  3. Create a GitHub Token 
  4. Create an IAM User
  5. Create an ECR Repository
  6. Create an ECS Cluster
  7. Create an EC2 Instance for setting up the Jenkins Server
  8. Install Java, JSON processor jq, Node.js, and NPM on the EC2 Instance
  9. Install Jenkins on the EC2 Instance
  10. Install Docker on the EC2 Instance
  11. Install Plugins
  12. Create Credentials in Jenkins
  13. Create a Jenkins Job
  14. Integrate GitHub and Jenkins
  15. Check the deployment
  16. Cleanup the resources

We hope this blog helped you learn more about the integral parts of the CI/CD Docker Pipeline. Keep learning :).