Automation using Dockerfile+Jenkins+Github
Aim:-
1.Create Docker file which will install jenkins.
2. As soon we run this docker image (docker file) it should install jenkins.
3. With the help of Job chaining , Now we have to create Jobs in Jenkins.
4. Job1 : Pull the Github repo automatically when some developers push 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 webpage if it is working or not.
7. Job4 : if app is not working , then send email to developer with error messages.
8. job5 for monitor : If container where app is running. fails due to any reason then this job should automatically start the container again.
STEP 1:
1.Create Dockerfile in workspace.My Dockerfile containing some code(keywords) for installation of following softwares.
*Running Jenkins URL with the help of “wget” command of Linux.
*Installing Java for running of Jenkins.
*Installing Python3 for running python code.
*Installing net-tools , so that we can check IP of our container/OS.
2.Creating Dockerfile for creating our own customized image and hence Running it with following command-
“docker build -t task:v1 /ws/”
“docker run -it — name my_jenkins -p 4321:8080 task:v1”
3.Setting UP Jenkins
Here as we have done patting and it will expose 8080 port through port number 4321.
Now our jenkins is ready to use.
4. Now creating Jobs and then we will perform job chaining-
(i) github_2 (job1):- It will check and put eye on the github repo “https://github.com/MIglaniAman/task1" and check for latest update/commit in repository.
It will create “/check” directory and copy all downloaded program files into it ,so that all recent program files will go to the testing job.
(ii)testing_launch (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 having that image/iso that has PHP installed).
(iii)test (job3):- With the help of curl command, we will see whether our webpage is working properly or not.
For success , the code is 200
and for any error (say HTTP error=500)
(iv)Email_notification (job4):-If our webpage is not working properly then job4 is to notify Developer.
*When everything is fine and working good,then it is OK.
*And When there is error/problem arises, then immediately an email will go to developer , so that they can go and rectify it.
For this I have created one Python program “send_email.py” for sending email.
(v)Again_Launch (job5):- After sending email to Developer then our webpage should start automatically.
NOTE:- job5 is optional.
*After Installing build pipeline plugin , created build pipeline job for=>Task(2)
we can observe this program flow.
Hence another task completed :)