Automated CI/CD integrated system using Docker

Hello guys!!!

We are going to build an interesting CI/CD integration. In this we are going to launch Jenkins with the help of Dockerfile and then through this Jenkins we will create a CI/CD pipeline , GitHub — Jenkins — Docker .

For this integration we have required some basic Knowledge of Linux, Jenkins and Docker.

The plan for this setup would be :

Step 1. Create container image that’s has Jenkins installed using Dockerfile

Step 2. When we launch this image, it should automatically starts Jenkins service in the container.

Step 3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in Jenkins

Step 4. Create Job1 : Pull the GitHub repository automatically when some developers push repository to GitHub.

Step 5. Create Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code ( e.g., If code is of PHP, then Jenkins should start the container that has PHP already installed ).

Step 6. Create Job3 : Test your app if it is working or not.

Step 7. Create Job4 : if app is not working , then send email to developer with error messages.

Step 8. Create One extra job job5 for monitor : If container where app is running. fails due to any reason then this job should automatically start the container again.

Architecture of the setup

Now we start building this automated pipeline , step by step :

Step 1 : Create a separate Workspace named Task02, then create the Dockerfile in this folder :

separate workspace
Dockerfile to launch Jenkins
Building Docker image that contain jenkins

Step 2. Launch a container through this Docker image :

Launching container with Jenkins

After Launching the container , we need to copy the Authentication token provided and paste it on the Jenkins Front Page, then we will be at the Jenkins customization page.

Customize Jenkins

Now we will install either some specific plugins or all the suggested plugins , In my case i have installed all the suggested plugins.

Installing Jenkins plugins

After configuring the account, we will be at the Dashboard of Jenkins , i.e.,

Jenkins Dashboard

This is how, as soon as we launched the container it automatically started the Jenkins service.

Step 4. Now we will start creating the jobs,

Job 1 : This will download the code from the GitHub Repository and then create a folder named ‘webserver’ in the host directory on which we have mounted the container.

Whatever we are doing inside the launched container, but actually everything is going on the rhel8.I have used chroot to switch the root to host os and then run all the commands their.

Creating Job1
Downloading code from GitHub
Enabling trigger for executing the job every minute
Creating folder in host directory and trigger the next job

Step 5 : Creating Job 2 that will identify the type of the code and on the basis of this it will launch a container for launching the web server.

Job 2 : This job will identify the code is of which type like it is of HTML or PHP , on the basis of this it will launch the container to launch the web server.

Creating container named htmlwebserver

This job will trigger the next job , i.e., job3

Trigger job 3

Step 6 : Creating Job 3 that will check the status of the web server, that it is running or not.

Job 3 : This job will check the status of the container that has been launched in job 2 and then it will trigger job 4.

Checking status of the launched container
Trigger to Job 4

Step 7 : Create Job 4 to send E-mail notification if job 3 get failed.

Job 4 : This job will send a E-mail Notification to a specified Recipient if job 3 get failed.

Job to send E-mail notifications if job 3 get failed

Step 8 : Create an extra job , job 5 that will continuously monitor the launched web server and if it get failed then it will launch it again.

Job 5 : This job will continuously monitor the launched container and if it get failed then it will launch it again.

Poll SCM Trigger for continuous Monitoring
Monitor the containers

Now, we have successfully created the CI/CD integration for such setup. We will build a Build Pipeline to visualize the setup of all jobs and how they are connected.

Build Pipeline for the Integration

Hence, we have created a great integration of GitHub — Jenkins — Docker .

For the reference of the codes , refer to the below link :

Further we will be creating more such integrations in future.

For any queries, issue or suggestion, please feel free to contact anytime. I will try to respond as soon as possible.

Thank You !!

I am a tech enthusiast, researcher and work for integrations. I love to explore and learn about the new technologies and their right concepts from its core.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store