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.
- Docker Hub.
- AWS EC2 Instances.
- AWS EKS service.
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.
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.
- Set GitHub hook trigger for GITScm polling
- Provide the Git Repository URL and credentials
- Script Path as Jenkinsfile
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.
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
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.
Create Kubeconfig file to connect to EKS cluster.
- contains all the necessary for authentication
Push some changes to the Master branch our pipeline will be triggered.
Please comment for feedback.
Happy learning :)