This is a simple integration of GitHub , Jenkins and Docker to automate the end to end process of deploying a website .
Requirements : Docker (Pre-Installed)
Tasks to integrate :
1.Create container image that’s has Jenkins installed using dockerfile .
2. When we launch this image, it should automatically starts Jenkins service in the container .
3. Create a job chain of job1, job2, job3 and job4 using build pipeline plugin 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 app if it is working or not.
7. Job4 : if app is not working , then send email to developer with error messages.
8. Create One extra job job5 for monitor : If container where app is running. fails due to any reson then this job should automatically start the container again.
Lets start with the custom docker image creation ..but before this make sure you have docker (pre-installed) as per the requirements .
I’ll be using Centos image as the base os and use Dockerfile to install Jenkins in the container .
> docker pull centos
Note : if no version of the image is given it selects :latest as default
Note : There are many simple and optimized code to create a Jenkins Image ..as its my first custom image ..I created the Dockerfile in a simple way to my understanding .
Make a file named Dockerfile in the workspace (in any directory) ..copy the above code and save it
Creating Docker Image :
> docker build -t act:v2 .
Note : fate:v1 is the image name ..you can give any name for docker image & the (.) is to load the Dockerfile
Note : it will take 15–20 minutes to complete based on your internet speed .
After the image is created try “ docker images “ to check if its available or not .
Now lets run the Jenkins container using the docker run command
Note : — privileged=true -to give the docker in docker , I have mounted the docker.sock to launch the docker images in host system .
Now launch the jenkins using the ip :8080 (to get the ip of container use the docker inspect image )
To get the password copy the directory location and use cat command to view the password
kindly check my previous post to setup git post-commit and the web-hooks https://github.com/FateDaeth/github-jenkins.git
>Manage Jenkins > Manage Plugins ..install the Github and Build pipeline plugins
Job1: Pull Git repo from GitHub .
Job2: Launching the webserver container
> docker run -dit -p 80:80 -v /var/lib/jenkins/workspace/job1:/usr/local/apache2/htdocs/ — — name http vimal13/apache-webserver-php
Job4: Error Message
As the Testing said the app isnt running the Job4 gets executed to monitor the container is working or not if it isn't it will launch it.
Using the docker inspect to find the ip of the webserver container launched .
Note : Its just a sample project to understand the integration and the error faced during the integration of GitHub , Jenkins and Docker tools .
Hope you liked it ..!!