Build Pipeline

Build Pipeline

Would you believe me if I tell you that your hard work to create a website is successful and you can run your website within minutes and monitor it at the same time? In the first instance, this might sound funny, but yes this is possible.

In the world of automation, various tools enable you to accomplish this process within a few minutes or even seconds. Launching a Docker container to run Jenkins and then further launching a new container to run your website after downloading the code from GitHub and then keep a check if the build is successful or not. If not, you will get an E-mail and hence you have no need to keep checking it manually. So just relax and watch your website reach out to the world.

During my learning of DevOps, I worked on a task to implement a website or any other file with an extension by launching the relevant container and check the proper functioning of the code.

Description of the task:

1. Create a container image that has Jenkins installed using Dockerfile 

2. When we launch this image, it should automatically start 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 the repo to Github.

5. Job2: By looking at the code or program file, Jenkins should automatically start the respective language interpreter and install image container to deploy code.

6. Job3: Test your app if it is working or not.

7. Job4: If the app is not working, then send an email to the developer with error messages.

8. Create One extra job job5 for monitoring: If the container where the app is running, fails due to any reason then this job should automatically start the container again.

Tools Used:

  1. Github
  2. Jenkins
  3. Docker

Creating the Dockerfile for a container with Jenkins configured as follows:

No alt text provided for this image
FROM centos
RUN yum install wget -y
RUN yum install net-tools -y
RUN yum install python3 -y
RUN yum install httpd -y
RUN yum install sudo -y
RUN yum install git -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-11-openjdk.x86_64 -y
RUN echo -e "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

USER jenkins
ENV USER jenkins

CMD ["java", "-jar", "/usr/lib/jenkins/jenkins.war"]


Build the image and then run it exposing a port to run Jenkins WebUI to configure jobs.

docker build -t mytask:v1 /mlops_task/
docker run -it --name --privileged -p 8082:8080 -v /task2:/task mytask:v11

Before you start using Jenkins make the following configurations to use SSH for running commands on the base OS and installing and configuring plugin to send an E-mail.

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

This job will automatically pull the files present in the GitHub repository and copy it to the mounted directory of the container as soon as changes are made as it monitors it all the time.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
sudo cp -r . /task/

This job checks the extension of the file and starts the relevant container as per the requirement.

No alt text provided for this image
cd /task2
if ls | grep *.html 
then
if sudo docker ps -a | grep html_container
then
  sudo docker rm -f  html_container
  sudo docker run -dit -p 85:80 -v /task2:/usr/local/apache2/htdocs/  --name html_container httpd
else
sudo docker run -dit -p 85:80 -v /task2:/usr/local/apache2/htdocs/  --name html_container httpd
fi


elif ls | grep *.php 
then
if sudo docker ps -a | grep php_container
then
  sudo docker rm -f  php_container
  sudo docker run -dit -p 88:80 -v /task2:/var/www/html --name php_container vimal13/apache-webserver-php
else
sudo docker run -dit -p 88:80 -v /task2:/var/www/html --name php_container vimal13/apache-webserver-php
fi


else
echo "Container Unknown"
fi


This job tests if the code is working or not.

No alt text provided for this image
export status=$(curl -o /dev/null -s -w "%{http_code}" https://192.168.1.2:85/index.html)
if [[ $status==200 ]]
then
exit 0
else
exit 1

fi

This job will send an e-mail to the developer if the build fails due to any kind of error.

No alt text provided for this image

Finally, in case if the container fails it will be restarted within seconds so that the viewers do not face any kind of lag or delay in viewing the content.

No alt text provided for this image
cd /task2
if ls | grep *.html 
then
if sudo docker ps | grep html_container
then
  exit 0
else
sudo docker run -dit -p 85:80 -v /task2:/usr/local/apache2/htdocs/  --name html_container httpd
fi

elif ls | grep *.php 
then
if sudo docker ps | grep php_container
then
exit 0
else
sudo docker run -dit -p 88:80 -v /task2:/var/www/html --name php_container vimal13/apache-webserver-php
fi

else
echo "Container Unknown"
fi


And here we go with the complete pipeline of running your website!

No alt text provided for this image

Happy Learning!

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

Tanuj Mathur的更多文章

  • Hybrid Cloud

    Hybrid Cloud

    In this era of Artificial Intelligence and robots, we humans tend to relax and let these artificial human beings…

  • Hybrid Cloud

    Hybrid Cloud

    A tool like Terraform, which makes the process of maintaining multiple clouds easier also provides a document or the…

  • Hybrid Cloud

    Hybrid Cloud

    With the ever-changing technology, companies requirements keep on changing as well. Companies who shifted to the Cloud…

  • Hybrid Cloud

    Hybrid Cloud

    Would you believe me if I tell you that you can launch a new Operating Systems within a few seconds or you can run a…

  • Hybrid Cloud

    Hybrid Cloud

    Every time we think of hosting a website, speed and security are the two most important factors we need to take into…

  • Transfer Learning

    Transfer Learning

    Humans are known to be the most intelligent and powerful creatures on this planet. They have the control over…

  • Hybrid Cloud

    Hybrid Cloud

    Still thinking behind the mystery of almost no latency or delay in responding to your requests while working on the AWS…

  • Hybrid Cloud Day-4

    Hybrid Cloud Day-4

    Are you using your AWS account with friends or are you worried if someone tries to sneak into your account and use it…

    2 条评论
  • Hybrid Cloud

    Hybrid Cloud

    What if you are working on a project in a team using the same account and worried if the settings might get changed by…

  • MLOPS

    MLOPS

    As a developer how would you feel if your only job is to write and upload the code and the accuracy of the model that…

社区洞察

其他会员也浏览了