The name AutomatedIntegration refers to the integration of Git, Jenkins and Docker.
For this project to automate process, We have to make 3 jobs on Jenkins:
If Developer push to dev1 branch then Jenkins will fetch from dev and deploy on the dev-docker environment.
If Developer push to master branch then Jenkins will fetch from master and deploy on the master-docker environment. As they both dev-docker and master-docker environments are on different docker containers.
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
- Operating System: Base OS is Windows 10. Server OS is RedHat Enterprise Linux 8 (RHEL8) in Oracle Virtual Box.
- In RHEL8, the softwares needed are Docker (httpd image downloaded in it), Jenkins (github plugin installed), ngrok program, and also httpd.
- In Windows we need Git Bash software.
- At the starting stop the firewalld in RHEL8 and start the docker and jenkins services.
In this task, I've created a system, where there are two environments. The environments are two docker containers, that are created using Jenkins. The one environment is for Production and other is for Testing. Both the environments are under controll of Jenkins.
Now, using GitBash created one branch as dev1 and considering it as Testing branch and the master branch as Production branch. Commit whatever changes you makein dev1 manually.
- Now first of all, stop the firewall and start the services of docker, jenkins and httpd.
systemctl stop firewalld
setenforce 0
- Give jenkins all the power of Linux:
Edit the
sudoers
file using :gedit /etc/sudoers
in Redhat.
Writejenkins ALL=(ALL) NOPASSWD:ALL
after the lineroot ALL=(ALL) ALL
Also, make two directories in Redhat, named Production and Testing.
-
Create the git repository: First, change to the directory where you want to work. Then create repository(repo) on github by clicking on 'New Repository' After creating repo, clone that repo in that folder usiing Git Bash.
git clone URL-of-your-repo
This will clone/download that repo in your folder. Also, you have create some files in master branch usingnotepad filename.html
orcat filename.html
. -
Now, Create new branch from Git bash Like this and change the branch from master to dev1:
Add create some files in tha branch using notepad filename.html
or cat filename.html
.
and add them to git to commit and push. Following are the commands:
After pushing the files your files will appear on the Github:
- Post-commit:
Now change directory to git hooks to edit the post-commit file.
cd /.git/hooks/
edit the post commit file usingnotepad post-commit
add this to the file:
#!/bin/bash
echo "Welcome to Jenkins!!!"
git push -u origin dev1
-
As, you have started jenkins from redhat system, get the ip of the system using
ifconfig enp0s3
. after getting IP go to the browser type that IP and add port 8080 to it.192.168....:8080
this will start the jenkins GUI. Log in to your Jenkins account. If account is not set, runcat /var/lib/jenkins/secrets/initialAdminPassword
command in your redhat terminal, and copy that password and paste into that inputbox. You'll be loged In. Install the Github Plugins from there. Now, you'll be asked to set new credentials. Complete that step.
if sudo docker ps | grep production
then
echo "Prod server already running"
else
sudo docker run -d -t -i -p 8082:80 -v /root/Production:/usr/local/apache2/htdocs/ --name production httpd
fi
sudo cp -r -v -f * /root/Production/
Click on Apply and then Save.
if sudo docker ps | grep testing
then
echo "Test server already running"
else
sudo docker run -d -t -i -p 8081:80 -v /root/Testing:/usr/local/apache2/htdocs/ --name testing httpd
fi
sudo cp -r -v -f * /root/Testing/
Click on Apply and then Save.
- Proceed for Job3 (Merging):
Click on Apply and then Save.
- Now, Build all the jobs
and in your browser, type
192.168.****:8081
and192.168.****:8082
and browse the files of your testing and production server. In this task, my 8082 port is for production and 8081 for testing. You can now see the the production files in the testing server and testing files in the production server. Examples:
- NGROK deployment
Run ./ngrok httpd 8082
command in the folder where your ngrok program is located.
This ngrok url can be shared and can be accsessed from any device.