THE INTEGRATION OF GITHUB,DOCKER, AND JENKINS
THE TASK 2 OF DEVOPS TRAINING UNDER LINUXWORLD
The Tasks are …
1. Create a container image that’s has Jenkins installed using Dockerfile.
2. When we launch this image, it should automatically start the Jenkins service in the container.
3. Create a job chain of job1, job2, job3 and job4 using the build pipeline plugin in Jenkins.
4. Job1: Pull the GitHub repo automatically when some developers push the repo to GitHub.
5. Job2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
6. Job3: Test your app if it is working or not.
7. Job4: If the app is not working, then send an email to the developer with error messages.
8. Create One extra job job5 for monitor: If the container where the app is running. fails due to any reason then this job should automatically start the container again.
I start by creating a Dockerfile using centos: latest image pulled from docker hub.
- Sudo for root powers ,
2. Wget for downloading the files from url,
3. Installing net-tools for viewing IP address( specially for ifconfig)
4. Set the yum repository for Jenkins from URLs using wget command.
5. Install java for Jenkins.
5. Created Jenkins entry in the sudoers file to give it root powers without need of any password.
6. Installed git for Jenkins .
7. Installed Python3 for mailing via python code.
After creating image by command “docker build -t name:version”
We have to run the container from this image “docker run -itd -p 1234:8080 — name hw2 — privileged name:version”
Here we have to give admin password shown in terminal (shown below)
Here we Successfully ran the image and now download all suggested plugin first and then we can use the jenkins smoothly…
Now we will do the jobs as asked in give problem…
The first job is Pull the GitHub repo automatically,for this we have to do some steps as shown below..
Step 1. Click on the “Github project” in first general section and enter your github repository url in project url section…
Step 2. Click on the “Git” in Source Code Management section and enter github url again in repository url …
Step 3. Select “Github hook triggeer for GITScm polling” and in Build Environment section Select “Add Timestamps to The Console Output “
Step 4.In “Build” Section select the “Execute Shell” for writing code , in tjhis code we create a repo directoryif it is available then first remove it create a new web-repo directory it’s done for Job 1… Apply and save the job
Job 2 is simpler then previous one,From here we are going to start a chain of job. for this
Step 1. we select “Build After other project are built” in “Build Triggers” section
Step 2.We have to write a code which work After Job 1 built successfully it will deploy a container(httpd container named as “ak_dep”) on the host system… it’s done. apply and save
Step 1. For making chain select “Build after …..” as we did in Job 2
Step 2. For testing our application we have created this job. after test fails it will got to Job 4 for mail to developer email address.
Step 1. as in JOb 2 and Job 3 we have to create chain by selecting “build after projects are built” ..
Step 2. We only have to write here “python3 mail.py” because we have created a python program file along with the Dockerfile.. This job is for sending the mail to developer if tsting of our application fails..
In configuration of Job 5 we only have to do 2 things one to create job/task chain and select the “Build Periodically” to schedule the interval here we have given five stars this means that we need to run this job every minute ..
We have done the creation of job successfully,
All created jobs are successfully built (The blue ball shows that it is successfully built )…
Now we have to see the results in Build Pipeline View…
We have done the Task succesfully … Thanks to vimal sir