Setting up a testing & production environment using docker and automating it using Jenkins.
Docker : Docker is a set of platform as a service (PaaS) products that uses OS-level virtualization to deliver software in packages called containers. The software that hosts the containers is called Docker Engine
Github : GitHub is a global company that provides hosting for software development version control using Git. It offers the distributed version control and Source Code Management (SCM) functionality of Git, plus its own features.
Jenkins : Jenkins is a free and open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.
Problem Statement:
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-docke environment.
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
Prerequisites:
- git
- redhat
- docker
- jenkins
Use Case :
Step1: Creating demo repositories using Git.
We have created a GIT Repository without initializing it and created a sample html file for testing the setup then uploaded it on the git hub using the Git Push command.
We created the copy of the file in a Git Branch namely Dev for the development and testing.





I renamed the files as task1.html.
Step2: Creating Public tunnel
As we know that the Jenkins works on the port 8080 we made a public tunnel on port 8080 using the ngrok application.


Step3: Webserver Launch
We require a web server to launch the sample application we made, here we use the Apache HTTPD server using Docker httpd image.

Here we need 2 containers,
- Testing the application
- Production on which the clients connect.
Testing container is running on the port 8085 and the Production container is running on the port 8084.
Step4: Login into Jenkins:

We have to create 3 jobs for the automation of the entire process.

Job 1 : If the Developer push to Master Branch then Jenkins will fetch from master and deploy on prodOS container

Here we will use 2 Triggers one to check form the Remote repository (GitHub) for which we use Triggers builds remotely and the other is for local repository (Git) for which we use GitHub hook trigger for GITScm polling .

Now we have to add hooks in local Git Repository, which will automatically push the committed file and trigger the Build Trigger by creating a bash file called post-commit.

For the remote trigger we have to add web-hooks in the GitHub Repository, it’s use is, when any file in the GitHub is changed it pings the Jenkins to download these files, for this you have to go to settings and then web-hooks.

Now build/run the job you will see this page.
Output:

Job 2 : If the Developer push to dev branch then jenkins will fetch from dev and deploy on the testOS container, for this you have to go to the configure of Job1

For this we use the Poll SCM trigger and scheduled it to “ * * * * * “ which means it will go and check the Dev branch every minute for any changes in the file, if yes, it will download then into the test_activity Directory in the linux system.

Job 3 : Now the OAT will check the test application in the test environment and if it passes the test then the jenkins will merge the dev branch to master branch and trigger Job 1.

For this at first give the credentials while entering the repository link then go to the git publisher and enter the shown details, it will automatically merge the files.

If you go and Build/Run the job 3 will see this modified page which is made by merging the contents of both the master and branch of the repository.
