- Set-up of Jenkins on the AWS Cloud use this link to configure Set-up: Jenkins-SetUp-onAWS
WorkFlow Structure:
Streamlining web development workflows by automating code deployment from GitHub to an Apache web server using Jenkins on AWS, ensuring seamless updates without manual intervention.
- About Infrasturcture of this project(use case):
Developer create code and upload code on SCM GitHub , that code(webpage) will deploy webserver and this webserver can access by Client from google.
By Using jenkins i do this set-up automatic:
- Use following steps for do above set-up automatic by using 'Jenkins'
I use Git Bash on local laptop for create code as developer. This code is push to gitHub.
- Hooks: Here i use Hooks which make automation that is whenever i change code and commit that code it automatically update on GitHub.
Create workspace/working area:
cd documents
mkdir jenkins-2024
cd jenkins-2024
mkdir myproject
cd myproject
Initialize Git repo command:
git init myproject
Create Webpage:
notepad index.html
Addeds to tracking/stagging area of git:
git add index.html
Commit the file/webpage:
git commit index.html -m "mychange"
- Now, we create empty repo on GitHub for push local code . NOTE: Don't use README file.
On GitHub there commands give for push code locally.
git remote add origin https://-----------
git branch -M main
git push -u origin main
Now 1st time we push then need login we use command for login:
Command for login to the GitHub from Local:
git config --global user.email "____" <<-- email GitHub
git config --global user.name "______" <<-- password GitHub
Now, Developer set-up done ( push local code to GitHub SCM ):
- Note:
Pushing code is manual but we make this automatic by using Git "Hook" , In Hooks folder create new post-commit file for automation. as soon we commit the new code that code automatically push to GitHub this done by post-commit Hooks. (Below screenshot refer)
Now code change & need to only commit that code file ( Fully Automatic way to push code):
git commit index.html -m "hooksactivate"
- Note:- Whenever i change code and commit this code automatically updated on GitHub.
Now on jenkins i created two Jobs
- 1st job (webserver) that create websever setup by using jenkins.
- 2nd job (gitHubjob1) that pull code from gitHub and deploy that Code on webserver location /var/www/html .
on GitHub create new job named as webserver using freestyle & in Build step put below screenshot steps.
- Note:
For this we need jenkins have root level or admin level power so we give power to jenkins then build webserver job, for this we go to Ec2 instance where jenkins installed or run and give ALL power.
vim /etc/sudoers
Now, Build our webserver job, this jenkins job download Https webserver and start Httpd service.
In webserver need webpage , we pull webpage from gitHub using new Job.
Now here i create new job which pull the code from GitHub and Deploy that code 'webpage' to apache webserver DocumetRoot location that is /var/www/html.
- Note:
Here use GitHub repo URL and "Branches to build" same where our code kept on GitHub in my case main is branch.
-Note:
But every time new code push on GitHub by developer then i need to Build my job again this is make slow or manual because of this i use "triggers" Here use "Poll SCM" Schedule for every min. means this helps to automatically pull code from gitHub not need to manually Build job, Whenever new code on GitHub then Poll SCM trigger automatically download that code.
- Note:
That downloaded code is save in jenkins workspace of that job.(This save after when we 1st time Build job then automatically it updated by Poll SCM)
Now, last step of job is to copy code or webpage which is downloaded from GitHub, This downloaded code copy to /var/www/html
Now apply & save job.
-
Note: This job run on Jenkins and Jenkins is on EC2 amazon linux, This job run only if in our host amazon linux2 EC2 have Git. So we need to install Git on amazon linux2, Where Jenkins installed.
sudo yum install git -y
Now we need run 1st time manually job in my case name of job is GitHubjob1, after 1st time we run that job automatically run when new code updated on gitHub.
Click on Build now button of Jenkins of Githubjob1
All set-up is done now I can change in code as developer from local laptop using Git-Bash app and commit that code, After commit new code automatically push to GitHub by Hooks & whenever that new code go to GitHub, On Jenkins Job2 named as GitHubjob1 is automatically run using Poll SCM trigger.
Now check connect Webserver from browser for view Webpage or Content:
Public Ip of instance in my case public ip of EC2 is - "http://52.66.237.252/"
- Note :
EC2 Instance Inbound rule must allow port no 80 that is http:
- Note:
Whenever New Webpage (code from developer to GitHub) comes then Jenkins job work and new webpage come by Fully Automation no need to manual update or Build job again and again: