
Problem Statement (MLOps + DevOps Task 1):
Given tools : Git, GitHub, Docker and Jenkins.
You have to deploy a Website using docker and GitHub.
But the website must be tested before deployment.
So you have to create two Environments using docker :
1) Testing Environment
This Environment is accessed by only Quality Assurance Team(Q.A.T).
This environment will deploy the Testing/Development Branch.
2) Deployment Environment
This Environment will be the main deployment server which will deploy the master branch of your website on GitHub.
Developer will develop the Website on his local machine and PUSH it to GitHub.
The task of Jenkins is to create both these Environment using docker , keeping them updated with each push to GitHub and give a token to Q.A.T by which they will be able to command Jenkins to merge development branch to the master branch.
Note : Development Environment must be created Freshly everytime.
Solution
Step 1: Create a repository for your website. Clone/Initialize repository to local machine where developer will work.

I have already initialize and uploaded a repository on GitHub with a simple website.
Step 2: Create Job1(autoweb) in Jenkins to deploy master branch using docker and keep updating this environment on any PUSH commit to master branch.

This is How I have Configured my Job1(autoweb) in Jenkins.
As you can see I have set project URL to my GitHub repository URL.
The git files are copied on server in folder “/masterenv” and I have attached this directory to my docker instance.
I have used httpd image from DockerHub to deploy my website.
If docker container is already running it won’t do any thing but if its not running the it will run a new docker container and connect the directory masterenv to container.
Step 3: Create Job2 (dev) in Jenkins to deploy develpment(dev1) branch using docker and keep updating this environment on any PUSH commit to this branch.

Most configuration is same as job1. But as you can see this job Creates a new development environment using docker everytime because it is better to create fresh environments in testing.
Note : Both Job1 and Job2 uses GitHub WebHook to trigger build process.
Step 4: To create a Job3(merge) in Jenkins which will merge development branch to master branch.

I have set up my GitHub username and password to merge and push the development branches to GitHub.
I have used GitHub plugin and Added additional behavior i.e merge before build to Merge the development branch to master branch.
I have added post build feature to push the branch after build is done.
Also I have build a remote trigger with token by which Q.A.T will be able to command Jenkins to merge the branches.
Step 5: You will need a public IP address by which GitHub-WebHook will have access to Jenkins Interface.

I have used Ngrok to expose my Jenkins to Internet
Step 7: To create GitHub Webhook

You have to go to you repository → Setting → Webhook
And paste the ngrok url on which Jenkins Web-Interface is present.
Step 8: Give Q.A.T the access token
Once they have the access token they can command Jenkins to merge the branches. Whenever there will be a get request using this URL job3 will start building, hence merging the branches.