Complete CI/CD pipeline
Akshay C A
Posted on February 24, 2022
A CI/CD pipeline is a series of steps that must be performed in order to deliver a new version of the software. Continuous integration/continuous delivery (CI/CD) pipelines are a practice focused on improving software delivery using either a DevOps or site reliability engineering (SRE) approach.
I've created a simple CI/CD pipeline with -
- GitHub for SCM.
- Jenkins.
- Docker.
- Docker Hub.
- AWS EC2 Instances.
- AWS EKS service.
Let's begin!
Step 1
Create an EC2 instance to run Jenkins.
I'm going to create an AWS EC2 instance and install docker in it to run Jenkins.
It is best practice for a user to access Jenkins with limited permission, so let's create a Jenkins user for this purpose.
Once this Jenkins container is up, edit the inbound rules to expose port 8080.
Let's finish up the initial settings
You need to make the data persist even after you restart the server.
So, stop the container, re-run docker the volume defined.
Next, provide the required access to docker.
So, we now have Jenkins up and running.
Step 2
Push your code to GitHub.
For this project, we will use the Java Maven App with a Postgres database.
You can clone my project for your reference - Repo Link
Here is the list of tasks that needs to be performed by Jenkins -
- Build the solution and increment the version number.
- Build the Docker Image using the Dockerfile and push the Image to the DockerHub.
- Trigger the automation tests.
- Deploy the App to a K8s cluster.
- Commit version update to SCM.
Step 3
Create a simple pipeline project in Jenkins.
- Set GitHub hook trigger for GITScm polling
- Provide the Git Repository URL and credentials
- Script Path as Jenkinsfile
Step 4
Create Jenkins shared library.
Jenkins Shared Libraries are written in Groovy and allow you to create common sets of logic, and share that among teams/projects/organizations.
I've created one for this project - Repo Link
Update your Jenkins file to read the shared library.
Build the Docker Image and Push it to the DockerHub -
Now if everything is configured properly, whenever you push your code to the master. Jenkins should trigger the pipeline and perform the below actions.
- Clone the git repository
- Increment the version number
- Build the Jar file
- Build Docker Image
- Push the Image to Docker Hub
Step 5
Deploy to K8s cluster
Now we are supposed to trigger the automation tests. Once all the tests are passed and all the checklists are cleared, we can deploy our App to the production.
Install Kubectl command-line tool inside Jenkins container.
Install aws-iam-authenticator tool inside Jenkins container.
I've create an EKS cluster called demo-cluster.
Create Kubeconfig file to connect to EKS cluster.
- contains all the necessary for authentication
Add AWS credentials on Jenkins for AWS account authentication
Adjust Jenkinsfile to configure EKS cluster deployment.
The last thing which you need to do once the deployment is successful is to commit the version update to the code repository.
The pipeline is now complete.
Now let's run it !!!
Push some changes to the Master branch our pipeline will be triggered.
Check the logs
Now let's connect to the EKS cluster from our local machine to verify.
Thank you!
Please comment for feedback.
Happy learning :)
Overview of our CI/CD pipeline -
Posted on February 24, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.