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.
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 :
Step 2. Launch a container through this Docker image :
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.
Now we will install either some specific plugins or all the suggested plugins , In my case i have installed all the suggested plugins.
After configuring the account, we will be at the Dashboard of Jenkins , i.e.,
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.
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.
This job will trigger the next job , i.e., job3
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.
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.
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.
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.
Hence, we have created a great integration of GitHub — Jenkins — Docker .
For the reference of the codes , refer to the below link :
Contribute to Anshika-Sharma-as/Task_02 development by creating an account on GitHub.
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 !!