---> As today's the world is growing faster and so the technologies, so doing anything manual is not preferable nowadays because manual doing is slower,less efficient and even more time consuming.
---> Automation is the need of today's generation and here I came up with the automation within integration and deployment of our projects on the server-side so that whenever Developer finishes writting the code or change something into the code, within one click, the changes will be updated on the server and client can see the changes on their end without any breakdown in the site or anything else like that.
Continuous Integration Tools used to accomplish this automation are as follows:-
1. GIT - GIT is an open-source tool developers install locally to manage source code.
2. Github - Github is an online service to which developers who use Git can connect and upload or download resources.
3. Jenkins - Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build.
4. DOCKER CONTAINERIZATION - Containerization is a technology which I used here for Continuous Deployment.
5. RHEL8 - OS used
Although this project is very easy to build but all you need is a basic understanding of the concepts of git,github,jenkins,docker and rhel8 and also how to configure and setup all these in your system. If you know that, then follow the methodology given below to make it happen on your own.
We have to create 3 Jobs here on Jenkins:-
JOB 1
If Developer push to dev branch then Jenkins will fetch from dev and deploy on dev-docker environment.
JOB 2
If Developer push to master branch then Jenkins will fetch from master and deploy on master-docker environment.
Note- Both dev-docker and master-docker environment are on different docker containers.
JOB 3
Manually the QA team will check (test) for the website running in dev-docker environment. If it is running fine then Jenkins will merge the dev branch to master branch and trigger JOB 2
First of all, Create a Job in Jenkins which will create 2 directories in Rhel8, one for storing the data of Sub-Developer i.e. Developer Branch and another for storing the data of Main Developer i.e. Master Branch.
Here you can see that Developer finishes writting the code for their website and when he commit the code in GIT, automatically the code will push to the GITHUB through post- commit actions and also it will triggers the Job1 i.e. Developer Job in Jenkins.
In the Developer Job i.e. Job1, you have to write the following code in the execute shell-
sudo cp -vrf * /developer
if sudo docker ps | grep webdev
then
echo "Already Running"
else
sudo docker run -dit -p 8081:80 -v /developer:/usr/local/apache2/htdocs/ --name webdev httpd
fi
Above code of the execute shell will first copy all the data that jenkins downloaded from GITHUB repo. of Sub-Developer to the directory of Developer that we created earlier in Rhel8. After copying data, it will launch a container(give any name say 'webdev') through docker using httpd image so to deploy Developer's website on Dev-Docker environment.
Write the following code in the execute shell of Job2-
sudo cp -vrf * /master
if sudo docker ps | grep webmaster
then
echo "Already Running"
else
sudo docker run -dit -p 8082:80 -v /master:/usr/local/apache2/htdocs/ --name webmaster httpd
fi
This will launch the container for master branch and deploy the code of master on the master-docker environment. Here you can see the website of master.
Once the Quality Assurance Team give the verification check for the website running in Dev-Docker env and will approve the changes that are made to this website to be merged with the master's website then you have to go for Job3. Job3 will merge both the branches(dev and master) and trigger the master's Job i.e. Job2 for the changes to be reflected in the main website and so the client can see the updations made in the website.
For merging, you have to follow this-
This will successfully merge both the branches and the client can now see the updated website. See here:-
Here are the results below of the successful completion of all the Jobs. You can also watch it in a Pipeline View by using Build Pipeline View Plugin of Jenkins which shows all the jobs running in an interactive manner. But remember you can only use Build Pipeline View when you have to run the Jobs in Chaining like one after the another.
Note- You can face issues while merging the branches in regard of merge conflicts. But Don't worry I will explain you what is Merge Conflicts and how you can resolve them.
Merge Conflicts is nothing but the conflicts arises when at the same time, same line of code is manipulated by multiple Developers within the same repository. At that time, It becomes difficult for the GITHUB to decide which is the final change that Developer needs to keep. That's the reason it gives conflicts error messages. But you can resolve them by simply commiting the final code that you need to be there in your website and remove everything that you don't want to be part of your website. After commiting, GITHUB will get to know the finalise product(code) and then it will merge the branches for you easily. For more info about merge conflicts you can visit here.
I hope you understood the project but in case you have any queries you can connect with me on my LinkedIn Handle.