Build, Check, Test & Monitor you code using Integration of Github, Docker & Jenkins.
This is the task-2 of Mlops and Devops traning under the great mentor MR. Vimal Daga sir.
Overview of Task-
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 Jenkins 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 html, then Jenkins should start the container that has html & apache webserver already installed ).
6. Job3 : Test your app if it is working or not & if app is not working , then send email to developer with error messages.
7. Create One extra job job4 for monitor : If container where app is running. fails due to any reson then this job should automatically start the container again.
Now here the Task starts-
- Create container image that’s has Jenkins installed using dockerfile.
To create the image that start the jenkins when we run the image I have use the Centos docker image and install the jenkins over it . The code of the dockerfile that generates the image which launch the jenkins is:-
RUN yum install wget -y
RUN wget -O /etc/yum.repos.d/jenkins.repohttps://pkg.jenkins.io/redhat/jenkins.repo
RUN rpm — import https://pkg.jenkins.io/redhat/jenkins.io.key
RUN yum install java -y && yum install jenkins -y && yum install git -y && yum install sudo -y
RUN echo -e “jenkins ALL=(ALL) NOPASSWD: ALL” >> /etc/sudoers CMD java -jar /usr/lib/jenkins/jenkins.war
2. After we have to run this cmd.
docker build -t minejenkins:v1 /task2/
3. Now we have to Run the container and collecting needed informations.
docker run -it — privileged -P -v /:host — name jenkins minejenkins:v1
"-P" means it will go inside the image's configuration and will look for which port is exposed. It will then allocate one random port and link that with that exposed port.
"-v /:/host" this command will attach our base os absolute directory to the container.
" --privileged" this will allow our docker to go inside base os and from inside container we will be able to run any commands in base os.
Now Here we will find the initial password of jenkins. This is needed to unlock Jenkins for the 1st time.
Type the IP address and login this page.
Now here we have to make the jenkins JOBS which will work for us.
Job1 : Pull the Github repo automatically when some developers push 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 ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).
Now this is for Email Config-
Job3 Here again use the previous trigger. This code will check if our php code is working fine or not.
If our php code has any error then it will send notification to the developer.
Job4 This job will keep on checking each minutes if my docker container is running or not.These 5 start means each minute this job will automatically triggers itself.
Now here is the view of build pipeline
This shows that our site is working fine.
Thats all about my task. I really thankfull to MR. Vimal Daga sir our mentor who give this types of wonderful task and make me learn this new things.