Web Develoyment Automated by Jenkins And With Docker , Github .
welcome Everyone,
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 and showing Pipeline : If container where app is running. fails due to any reson then this job should automatically start the container again.and pipeline will show that it Working Good
For This Task2 We Requires Linux Operating System And Jenkins And Docker , Git Also Required
yum install git -y //command to install in RHEL8 apt-get install git -y
And Docker Also:-
Dockerfile:-
Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession.
I Used This Docker file for this Task :-
FROM centos:7 RUN yum install wget -y RUN wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo RUN rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key RUN yum install java -y RUN yum install jenkins -y RUN yum install git -y RUN yum install sudo -y RUN echo -e "jenkins ALL=(ALL) NOPASSWD:ALL " >> /etc/sudoers CMD java -jar /usr/lib/jenkins/jenkins.war
1. Dockerfile for creating an image that has jenkins installed.
Using Vim Editor i Encode Dockerfile :-
we Build the image using these cmd :
docker build -t <image name> : <version> <Dockerfile path>
In my case it is -> docker build -t jenkins:v1 /ws/
docker build -t jenkins:v1 /root/aaditya
Then Process begins it Download & install Ouir Requirements :-
Successfully Done.
After making the image we have to run the docker container Using Command :-
docker run -it --privileged -p 90:8080 --name jenu host jenkins:v1
after this we will get a password and we will have to write that password for initial login into our jenkins container ...
We will Get a unique Password..
Use this Password while login in Jenkins Container..
Open your Browser And Go to port 90 which will Assign to Jenkins container.
Type Below cmd in Search Bar of Browser :-
localhost:90
We will redirect to this Window of Jenkins :-
Put That Password here ...
lets do All Processing Of Configuration Of Jenkins.
Create User Account To Jenkins:-
Now Jenkins IS Ready To Work
Now After Installation And After All Process Of Configuration of Jenkins Complete then First Download The Plugins Of SSH And All Relatable Plugins you have to download install ..
Next Step:-
After Setup Of Credentials setup SSH remote host:-
SSH Setup Completed.
After that we will write our first job :-
Jenkins Work Begins :-??
Create jobs :-
JOB 1 : Pull the Github repo automatically when some developers push repo to Github.
Put Your Git Repo Link And then setup Build Triggers
Output Of JOB1:-
Now Job1 Successfully Completed..
Now JOB2:-
#!/bin/bash if ls /root/aaditya | grep html then if sudo docker ps -a | grep OShtm then sudo docker rm -f OShtm echo "older container is terminated " sudo docker run -dit -p 777:80 -v /root/aaditya:/usr/local/apache2/htdocs --name OShtm httpd:latest echo "New container with updated code files is launched " else sudo docker run -dit -p 777:80 -v /root/aaditya:/usr/local/apache2/htdocs --name OShtm httpd:latest fi else if ls /root/aaditya | grep php then if sudo docker ps -a | grep OSphp then sudo docker rm -f OSphp echo "older container is terminated " sudo docker run -dit -p 777:80 -v /root/aaditya:/var/www/html --name OSphp vimal13/apache-webserver-php:latest echo "New container with updated code files is launched " else sudo docker run -dit -p 777:80 -v /root/aaditya:/var/www/html --name OSphp vimal13/apache-webserver-php:latest fi fi
fi
Here we have compatibility for python, html & php. If you want some more language to be handled then you can add it. One more thing here we need to take care of is we need to make containers for these language interpreter also.
Output of Job-2 :-
By Lookins Our code out Jenkins Launch Html Container And in this Above Output We see Container ID.
Job3 : This job will test the app/website , whether it is working or not.
status=$(sudo curl -o /dev/null -s -w "%{http_code}" 192.168.99.101:777) echo $status if [[$status = 200]] then echo "Congrats" fi if [[$status != 200]] then echo "Sorry" exit 1
fi
OutPut Of JOB3:-
Job4 : If app/website is not working , this job will send email to developer with error messages.
Here we Give email Address for Reciving mails about job.
OutPut Of JOB4:-
Job 4 completed , Now Job 5
OutPut Of Job5:-
And Final Pipeline Is:-
All Jobs Are Done Successfully !
*Now Final OutPut:-
And Final Page And Web deployed By Jenkins is :-
Task 2 Completed Succefully
Thank You So much @Vimal Daga Sir And Linux World!
Mainframe Developer at Wipro | Microsoft Certified Azure Administrator Associate | Cloud & Data Enthusiast.
4 年Excellent work brother ????