Integration of Github , Jenkins , Docker and running a container ( html or php )
This is article about working of Jenkins to automate the project from development done by developer till the deployment. Everything will we done automatically by writing the JOBS in Jenkins.
Task Given:
- Create a docker container from customized image that’s has Jenkins installed using Dockerfile.
- When the image is launched, it should automatically start the Jenkins service inside the container.
- Create a job chain of job1, job2, job3, job4 and job5 using build pipeline plugin in Jenkins
- Job1: Pull the Github repo automatically when some developers push the repo to Github.
- Job2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code. Here my code is of HTML, hence Jenkins should start the container that has HTML already installed.
- Job3: Test your app if it is working or not.
- Job4: if the app is not working, then send an email to the developer with error messages. This job not belonging to the pipeline to monitor: If the container where the app is running. fails due to any reason then this job should automatically start the container again
So without wasting any time let’s jump to the hands on part:
First we are going to create a file that will launch a Jenkins inside the the Docker with name DOCKERFILE , write all the commands required you can refer to the below image:
For docker file you can check on my Github here is the link: https://github.com/hvardhank7/task2.git
Then open your virtual machine and run the below command on terminal
Now we will check the status of Jenkins and start the Jenkins in your browser
JOB 1: Pull the Github repo automatically when some developers push the repo to Github.
Here we are copying all the file from my Github repo to the directory /root/task2/
JOB 2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code. Here my code is of HTML, hence Jenkins should start the container that has HTML already installed.
Here we give the html file name in my case it is testing.html.
The we will launch an container with name html_os using httpd
JOB 3: Test your app if it is working or not.
Here we check the status of an container by using the concept of status = value (generally 200 ) then it will restart the container again
JOB 4: if the app is not working, then send an email to the developer with error messages. This job not belonging to the pipeline to monitor: If the container where the app is running. fails due to any reason then this job should automatically start the container again
Here we will launch an OS in case of any failure and this job will send an email to the developer about the failure of the container
After running all the jobs ,it will show a web page we have created like this
We can also launch a php server by this method which is fully automated.