Automation of WebServer

Sathvika Kolisetty
4 min readJul 1, 2020

--

Problem Statement

JOB#1

If Developer pushes to dev branch then Jenkins will fetch from dev and deploy on the dev-docker environment.

JOB#2

If Developer pushes to master branch then Jenkins will fetch from master and deploy on the master-docker environment.

both dev-docker and master-docker environments are on different docker containers.

JOB#3

Manually the QA team will check (test) for the website running in the dev-docker environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger #job 2

Pre-requisite

Git repository is created on Github. Yum is configured. Docker and Jenkins are already installed in RedHat8, Jenkins is provided with SUDO access.GIT for managing the source code, Docker for launching the webserver, and use it to serve our web application, Jenkins for automating the process and build a pipeline from end-to-end.

Do the following steps in your git bash

mkdir web_deploy
cd web_deploy
git init
git remote add origin <repo link>

Then next we will configure post-commit hook

touch .git/hooks/post-commit
vim .git/hooks/post-commit

Now add the following lines to the post-commit to push the code whenever developer commit the code

#!/bin/bash

git push

Jenkins should be provided with sudo access so that you have to make small changes in

vi /etc/sudoers

Job1- Developer push to master branch then Jenkins will fetch from master and deploy on the master-docker environment Same as dev-branch we will do it with the master branch also. We will clone the code.

if sudo docker ps | grep webdeploythendocker rm -f webdeploysudo docker run -dit -p 8081:80 -v /var/lib/jenkins/workspace/webjob1/:/usr/local/apache2/htdocs/ --name production_web httpd:latestelsesudo docker run -dit -p 8081:80 -v /var/lib/jenkins/workspace/webjob1/:/usr/local/apache2/htdocs/ --name production_web httpd:latestfi
job 1 output

JOB2 Developer push to master branch then Jenkins will fetch from master and deploy on the master-docker environment.

git checkout -b dev
echo "FIRST-BRANCH" >> index.html
git add .
git commit -m "second"
git push origin dev
if sudo docker ps | grep webdeploythendocker rm -f webdeployelsesudo docker run -dit -p 8084:80 -v /var/lib/jenkins/workspace/webjob2/:/usr/local/apache2/htdocs/ --name devv_web httpd:latest
fi

JOB3

QA team will check (test) for the website running in the dev-docker environment. If it is running fine then Jenkins will merge the dev branch to the master branch and trigger JOB1.

--

--

No responses yet