Integrating Jenkins with GitHub and Docker to deploy Web Server

Integrating Jenkins with GitHub and Docker to deploy Web Server

Hello Connections , this is Milind Verma and once again I have written this article to showcase the integration of multiple technologies to automate the deployment of the web server.
Here in this article I have used technologies like Jenkins , Docker , Git and some algorithms. Basically in today's world automation of technologies is very much needed . Everyone wanted to make his deployment faster and more qualitative to the society.
So here I have presented a small task which will give you the idea about how to make the deployment of a service automated.

Mainly some SCM tools like Github , management tools like Jenkins and container tool like docker becomes the backbone of this pipeline of CI/CD to launch the applications within few clicks where all the internal works are done by these tools in the background. The main intention of this pipeline is to make this deployment as fast as possible wherein no human intervention occurs.

So here our task is :

  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 the build pipeline plugin in Jenkins.
  4. JOB1: pull the GitHub repository automatically when some developers push the repository to GitHub.
  5. JOB2: By looking at the code or program file , the Jenkins should automatically start the respective language interpreter installed image container to deploy code (e.g if the code is of PHP, then Jenkins should automatically start the container that has the PHP installed).
  6. JOB3: If the app is not working, then send the email to developer with the error messages.
  7. JOB4: one extra job for monitor : If the container where the app is running fails due to any reason then this job should automatically start the container again.

LETS START THE WORK .

Creation of the Dockerfile

So here using the Dockerfile I have built the image that has git and jenkins installed and starts the jenkins services as soon as the container is launched using that image.

FROM centos:latest
RUN yum install sudo -y
RUN yum install wget -y
RUN yum install curl -y
RUN yum install git -y
RUN yum install net-tools -y
RUN yum install ncurses -y
RUN sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
RUN yum install java -y
RUN yum install initscripts -y
RUN yum install jenkins -y
RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
CMD service jenkins start

Now build the image using the following command.

docker build -t jenkins:v1 .

This command will create the image , it will take some time to create . After creation you can use the image.

Launch the container using the above image .

docker run -dit --name jen1 -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock   -v /usr/bin/docker:/usr/bin/docker jenkins:v1

Here in this command I have directly mounted the "docker.sock file" and the docker config files on the jenkins container to make the docker commands executable and also expose the container.

Now launch the Jenkins using the port 8080, and enter the jenkins using the initial admin password provided by jenkins at the location /root/.jenkins/secrets/initialAdminPassword.

Install the github and the build pipeline plugin to make the github work inside the jenkins and make the jenkins environment ready for the work. .

No alt text provided for this image

After installing the plugin , now we move on to the JOBS.

JOB1:

This JOB pull the code from github and copies it in the folder named task2devops on the base container. I have used the github web hook to make this automatic.

No alt text provided for this image

Now making the JOB1.

No alt text provided for this image
No alt text provided for this image

JOB2:

This job triggers as soon as the JOB1 is built successfully and this job checks the code and launches the container according to it , i.e if the code is of PHP then it launches the container that have the PHP installed and if the code is of the HTML then it will launch the container of the HTML.

No alt text provided for this image

This job is running continuous with the JOB1

No alt text provided for this image


JOB3:

This job triggers after the successful build of the JOB2 and this job checks the "http code" (like 200 for success, 404 for unsuccessful) of the web server. If the job is unsuccessful then it will alert by sending the Email to the developer to recheck the code.

No alt text provided for this image
No alt text provided for this image

code for the email s below

No alt text provided for this image

JOB4:

After all the jobs are run successfully then this job triggers and keeps on monitoring the container if it is running and if in case the container stops it starts the container again.

No alt text provided for this image
No alt text provided for this image


my website

No alt text provided for this image

Finally the build pipeline for the task

No alt text provided for this image

Thank You very much for going through my article

Any suggestions are appreciated :)



要查看或添加评论,请登录

Milind Verma的更多文章

  • Red Hat OpenShift Deployment on AWS via ROSA Service

    Red Hat OpenShift Deployment on AWS via ROSA Service

    Hello everyone, welcome to my article. In this article, I will cover: what's Red Hat OpenShift Service on AWS (ROSA)?…

    10 条评论
  • JavaScript - "An Integral Part of Modern Apps"

    JavaScript - "An Integral Part of Modern Apps"

    Let’s see what’s so special about JavaScript, what we can achieve with it, and what other technologies play well with…

  • Cyber Crimes & Confusion Matrix

    Cyber Crimes & Confusion Matrix

    Cybercrime is vastly growing in the world of tech today. Criminals of the World Wide Web exploit internet users’…

  • AWS S3 Multipart Uploading

    AWS S3 Multipart Uploading

    Hello Guys, I am Milind Verma and in this article I am going to show how you can perform multipart upload in the S3…

  • ARTH TASK-6

    ARTH TASK-6

    OUR TASK: Create High Availability Architecture with AWS CLI The architecture includes- Webserver configured on EC2…

  • How Google uses Machine Learning

    How Google uses Machine Learning

    Google is the master of all. It takes advantage of machine learning algorithms and provides customers with a valuable…

  • Kubernetes CASE STUDY: Pearson

    Kubernetes CASE STUDY: Pearson

    Challenge A global education company serving 75 million learners, Pearson set a goal to more than double that number…

  • Launching webserver and python using Docker Conatiner

    Launching webserver and python using Docker Conatiner

    Our task: launching the HTTPD server over the docker container setting up the python interpreter and running python…

    2 条评论
  • Integrating LVM with Hadoop and providing Elasticity to DataNode Storage

    Integrating LVM with Hadoop and providing Elasticity to DataNode Storage

    In this article I am going to show you , how can we integrate the Hadoop with the LVM. First we will launch 2 EC2…

    1 条评论
  • Netflix Case Study on top of AWS

    Netflix Case Study on top of AWS

    NETFLIX Netflix is an American media services provider and production company headquartered in Los Gatos, California…

社区洞察

其他会员也浏览了