Github And Docker Automation by Jenkins

 Github and Docker Automation


Task Description - 

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

 

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

 

3.   Create a Job chain of Job 1 , Job 2 ,Job 3 and Job 4 using build pipeline plugin in Jenkins

 

A.    JOB 1 – Pull the Github repo automatically when some developers push repo to Github.

 

B.    JOB 2 -  By looking at the code of program file, Jenkins should automatically start the respective language interpreter installed image container to deploy code ( if code is of PHP, then Jenkins should start the container that has PHP already installed.)

 

C.   JOB 3 – Test your App if it is working or not.

 

D.  JOB 4 – If App is not working, then send email to developer with error messages.

 

4.   Create one extra JOB, JOB 5 for monitor If container where app is running. Fails due to any reason then this JOB should automatically start the container again.


Building The Project



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

    For this we have to write DockerFile with following Commands.

   



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

             For this build the docker Image with following command.


                        docker build -t name:v1

 

3.   Create a Job chain of Job 1 , Job 2 ,Job 3 and Job 4 using build pipeline plugin in Jenkins .

 

               JOB 1 – Pull the Github repo automatically when some developers                 push repo to Github. For this we have to write following code.

                Install Github plugin in Jenkins and in github URL paste your Github  Link.

  •  First lets setup our Jenkins. 





  • Now install required plugins in Jenkins.                 
github plugin
Email notification plugin
SSH plugin
SMTP plugin
                    

                         sudo cp –v –r –f  * /root/mlops1







   

 

               JOB 2 -  By looking at the code of program file, Jenkins should                         automatically start the respective language interpreter installed                       image container to deploy code ( if code is of PHP, then Jenkins                       should start the container that has PHP already installed.). We are using html code here. So we have to install our new OS which has httpd server  installed in it. For this download new Docker image with httpd and start web server using following commands.

                #docker pull httpd

               #systemctl start httpd     

        Now run the docker image with following command.

             #docker run -it --name name --privileged -p 1234:8080 -v /:/host myOS:v1



  



JOB 3 – Test your App if it is working or not.                  

for this write the following code in execute shell.

export status= $(curl dev link -sw "$(http_code)" http://yourIP:1234/file.html)


if [status == 200]

then

exit 0

else

exit 1

fi





 JOB 4 – If App is not working, then send email to developer with error messages.

                 



         5.  This is only a extra JOB, JOB 5 for monitor If container where app is running. Fails due to any reason then this JOB should automatically start the container again



Comments