Home » Microservices » CI/CD DevOps: Steps To Create a CI/CD Pipeline With Jenkins, Containers, and Amazon ECS
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:
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.
Faster delivery: Multiple daily releases or continual releases can be made a reality using CI/CD Pipelines.
Observability: Having automation in place that generates extensive logs at each stage of the development process helps to understand if something goes wrong.
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.
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.
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.
Continuous Delivery: This is the process that lets us deploy the tested code to the Production whenever required.
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/CDPhases
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.
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.
Code pull: In this phase, the pipeline pulls the latest code whenever the pipeline is triggered.
Unit tests: In this phase, the pipeline performs tests that are there in the codebase. This is also referred to as unit tests.
Build or package: Once all the tests pass, the pipeline moves forward and builds artifacts or docker images in case of dockerized applications.
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.
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.
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
DevOps Automation Tools
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.
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
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.
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.
Linear – Traffic is shifted in equal increments, the percentage of traffic shifted in each increment, and the number of minutes between each increment.
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.
Clone the existing sample GitHub Repository
Create a new GitHub Repository and copy the code from the sample repository in it
Create a GitHub Token
Create an IAM User
Create an ECR Repository
Create an ECS Cluster
Create an EC2 Instance for setting up the Jenkins Server
Install Java, JSON processor jq, Node.js, and NPM on the EC2 Instance
Install Jenkins on the EC2 Instance
Install Docker on the EC2 Instance
Install Plugins
Create Credentials in Jenkins
Create a Jenkins Job
Integrate GitHub and Jenkins
Check the deployment
Cleanup the resources
We hope this blog helped you learn more about the integral parts of the CI/CD Docker Pipeline. Keep learning :).