Jenkins CI/CD Pipeline - SonarQube, Docker, Github Webhooks on AWS | Resume Project | English
Jenkins CI/CD Pipeline - SonarQube, Docker, Github Webhooks on AWS | Resume Project | English
In this video, we will explore how to set up a Jenkins CI/CD pipeline using Github, Sonarqube, and Docker on an AWS EC2 instance.
Jenkins is a popular open-source automation server that helps automate various tasks in the software development process, including building, testing, and deploying software. Github is a code repository that provides version control and collaboration tools, and Sonarqube is a code quality management tool that helps analyze and manage code quality in software projects. Docker is a containerization platform that helps simplify the deployment of software applications.
First, we will create an AWS EC2 instance and install Jenkins on it. We will then set up a Github repository and integrate it with Jenkins. Next, we will configure Sonarqube to analyze code quality in our Github repository. Finally, we will create a Docker image of our application and deploy it using Jenkins.
Throughout the video, we will explain the importance of each step and provide detailed instructions on how to configure each tool to work together seamlessly. By the end of this video, you will have a working CI/CD pipeline that will help automate the software development process and ensure the quality of your code.
Whether you are a developer, software engineer, or DevOps professional, this video will provide you with valuable insights on how to set up a CI/CD pipeline using Jenkins, Github, Sonarqube, and Docker on an AWS EC2 instance. Join us in this exciting journey and learn how to streamline your software development process today!
Make sure to subscribe to our channel if this video helped you and you want to see more content like this. Don’t forget to give this video a thumbs up if you found it helpful and hit the notification bell icon so you don’t miss any updates from our channel. Thank you for watching! #cicd #jenkins #devopsprojects
Content
0.66 -> hello everyone welcome to my YouTube channel
and in today's video we will be creating a
4.32 -> cicd pipeline in which we will push the
code to the GitHub and form the GitHub we
8.7 -> will pull the code through Jenkins and after
pulling the code from the GitHub we will test
13.68 -> the code on Sonar Cube which is a static code
analysis tool on which we can scan the bugs
19.86 -> and vulnerabilities of the code and also we can
add the rules uh record regarding the scanning
26.28 -> and then after scanning the code if our
code pass we will deploy it on docker
32.22 -> and everything will be done on ec2 instance so
you will need three ec2 instances one for the
37.98 -> Jenkins one for the sonar Cube and one for the
docker deployment so then after deploying in on
44.52 -> Docker we will access it on our browser just
to verify if it's working or not so I have a
50.22 -> website here which I've downloaded not long ago
it is the basic HTML template as you can see
60.96 -> this is the template that we're gonna use and
if you want to download template then you can
65.46 -> search for free CSS and here's the website
that you can download the templates from
75.96 -> you can just download any template
that you want so after downloading
80.34 -> that template just extract it anywhere
on a desktop or anybody want and after
85.62 -> accepting the template what we have to
do is we have to log into the GitHub
100.5 -> and after logging in the GitHub just create a new
Repository so I've created a repository called
106.32 -> Jenkins sonar Cube docker and in which I've also
uploaded the code and after pushing the code to
114.24 -> the repository what we have to do is we have to
create three easy to install one for the Jenkins
122.7 -> let's just create a easy tune sounds
126.66 -> click on launch instance and just give it any
name that you want let me just give it Jenkins
133.68 -> and from here just select the operating system
that you want to use so I will be using Ubuntu
140.28 -> so I will click on Ubuntu and after selecting
the operating system just select the type of
145.92 -> the instance so I'm gonna select T2 medium
which has two virtual cores and 4GB memory
154.26 -> and after selecting the instance type we
have to create a key pair so we can SSH into
159.3 -> the virtual machine so give it any name that
you want let's just give it uh SSH e Jenkins
170.46 -> give it any name you want and
then click on create key pair
176.64 -> and as you can see the key is
downloaded in the downloads folder
180.54 -> and after selecting the key pair just
scroll down and click on launch instance
189.36 -> and it will take only a few minutes only a
few seconds to launch and let's just create
195.12 -> another instance while it's in pending state to
click on launch instance again and then give it
201.96 -> a name sonar Cube so we will be using
this instance Photoshop installation
207.48 -> and then select the operating system also you
have to keep in mind that so now you consume
212.34 -> a lot of memory so make sure you have at least
two or four GB of memory just for the Smart Cube
218.22 -> then select the instance type and from
here we're going to select the key that we
223.5 -> have created earlier so we're not gonna create
another key we're gonna just use the older one
230.64 -> and after selecting the key
just click on Lots instance
236.58 -> so this is also creating and once it's created
just let's just create another one for the docker
243.66 -> give it the name docker
247.08 -> server and from here select
the image that you want
253.86 -> like the instance type for the docker I will be
using T2 medium also and then select the key pair
263.52 -> and thus click on launch instance
272.4 -> and once the instance is created as you can
see the sonar cube is in running State and
278.28 -> the Jenkins is in also running state so let's
just SSH into the Jenkins instance just click
285.84 -> on the insurance ID that you want to access it and
just copy its public IP and after copying the IP
292.14 -> just open your terminal and from terminal
just go to the downloads folder by typing
299.34 -> flash downloads and then the name of the key
then we have to type SSH hyphen I and then
307.98 -> pass the key that we want to use so what was
the name of the key that we created earlier it
312.6 -> was SSH key Jenkins so SSH key Jenkins and after
the key we have to type the username so whenever
320.7 -> we installed the Ubuntu on ec2 and Suns it created
it creates a user named Ubuntu by default so we're
327.3 -> going to use the default user and then pass
the IP address and here we will get an error
333.66 -> as you can see we got a permission denied error
it says bad permissions for the key so it says
339.18 -> the permission 0664 for the SSH key are to open
it is required that your private key files are
346.74 -> not accessible by others so what we have to do is
we have to give it the permissions so it can only
352.44 -> be accessible by the current user so to change the
permissions you have to type CH mode 440 or double
359.16 -> zero and then the name of the key and now FP SSH
we will be able to access it into the machine
368.58 -> as you can see we are in the virtual machine
now so after getting into the virtual machine
372.54 -> you have to type sudo apt update so we can update
it and then we're gonna install the Jenkins in it
383.04 -> and once it's updated we're gonna solve open
jdk11 open jre11 Java runtime environment which
390.9 -> is required for the Jenkins solution so while it's
updating let's just open jenkins.io on our browser
399.9 -> and after opening the jenkins.io website click
on documentation and click on installing Jenkins
406.32 -> and after clicking on the installing the
engines select your desired operating
410.82 -> system in my case it's Linux so I will
click on Linux and from here it says
416.28 -> Debian Ubuntu so click on Debian you want
to inform here just copy the whole command
422.22 -> and before pasting the command we have to install
Java runtime environment go to install the Java
429 -> runtime environment you have to type sudo
EPT install open jtk hyphen 11 hyphen JRE
437.52 -> just like yes and it's downloading now it
will take less than a minute it depends
443.94 -> on your internet speed so if you're using on
ec2 instance then it will be as quick as that
468.12 -> so the open jdk is installed successfully
and now we're gonna install the Jenkins
474.9 -> just paste the Jenkins command and hit enter
and while the Jenkins is installing let's just
482.16 -> allow the port 8080 so we can access it on
our browser just go to the ec2 instance and
489.3 -> from here just scroll down a little bit and you
will see security groups in the security section
495.84 -> and just click on the security groups and from
here just scroll down and click on edit inbound
501.96 -> tools so we're gonna allow the port 8080 on this
specific virtual machine just click on ADD rule
509.76 -> from here select custom TCP and here give it the
port that you want to open in my case it's 8080
516.78 -> which is the default port for the Jenkins and
click on Save rules and we have successfully
523.02 -> added the security group rule and now let's just
verify if if the Jenkins is installed or not
533.64 -> this type system CTL status Jenkins and here you
can see it's running and from here you will see
541.2 -> something like this what you have to do is copy
the secret key here just copy it using the Ctrl
548.28 -> shift C command uh not the command but the key
and then go to the instance and copy its public IP
565.62 -> so just copy the Jenkins public IP and
paste it here and write the port 8080
573.96 -> and as you can see we can
access the Jenkins web page
579 -> it's loading it will take less than a few seconds
so while it's loading let's just copy our token
590.76 -> it's taking a while to load let's just
refresh it again and it's still loading
598.62 -> so here so if you forgot to copy the secret key
and it's not visible in the system CTL status
606.36 -> Jenkins command then what you can do is you can
go to the certain path which is mentioned here
613.32 -> and what you have to do is just copy the path
and just type cat and then the path so it says
622.38 -> permission then I just write sudo before the cad
command and here you can see the keys also here
628.26 -> the same key which we copied from the system CTL
command just paste the key and click on continue
646.44 -> click on install suggested plugins
660.3 -> now the plugins are installing uh uh
it got some error then let's just retry
677.28 -> so as you can see the plugins are
installing in the background and
680.82 -> while the plugins are installing let's
just uh look what we have done till now
686.34 -> so we have created a server for the Jenkins and we
have also pushed the code to the GitHub now what
692.4 -> we are going to do we're gonna pull the code
that we have pushed to the GitHub repository
696.54 -> this code in the Jenkins server and then
we're gonna set up the sonar Cube server
702.9 -> and from the sonar Cube we will test the
code if it's okay to deploy and if the
708.66 -> code is passed then we will deploy it on
the next instance which will be on docker
717.24 -> so here the plugins are installed
just create a user give it a username
722.82 -> and give it any password that you
want and give it the full name
732.18 -> just give it any email address that you want
736.86 -> then click on Save and continue
742.08 -> and click on finish
746.04 -> now we can start using Jenkins so first what
we have to do is we have to create a pipeline
753.72 -> and to create a pipeline just click on new item
and from the new item just give it any name that
760.98 -> just give it uh automated pipeline and select
the project type so in my case I will be creating
767.94 -> a freestyle project and you can also look at the
other projects but it's not in the scope right now
773.22 -> so I will be just going with the freestyle project
click on OK and once the project is created
785.58 -> what we have to do is scroll down a little bit
and from here you will see source code management
789.96 -> you can also see it from here if you click here it
will just bring you here and from the source code
796.02 -> management we will be using git so we will click
on get and here it's asking for a repository URL
802.38 -> just go to the repository and click on code and
then the and then copy the URL from the https tab
810.42 -> and then just paste the URL here and
814.44 -> give it a branch so our branch
is main so I will just write Main
823.68 -> and after adding the branch just click on Save
and we also have to do one more thing here
829.44 -> so just go to the configure again
834.24 -> and just from here you will have to click on
841.08 -> GitHub hook trigger for SCM Cooling so what this
will do is it will just trigger the pipeline
848.82 -> automatically whenever we make changes to the rep
Repository so just enable this option and go to
856.38 -> the Jenkins by GitHub repository and from the
repository just click on the settings from here
862.38 -> and we will be adding a GitHub webbook so
whenever we whenever we make changes to the
866.7 -> code it will trigger the pipeline automatically
and from here just look for web books here
875.1 -> to click on the Web Box and after clicking on the
Web book just let me just delete the older one
883.32 -> uh so it will ask me for the authentication let
me just verify the access from my mobile phone
902.16 -> so I've approved it from
my phone and now it should
906.66 -> login within a second yes as you can see
we have logged in now click on ADD web book
912.3 -> and what we're going to do here we're gonna copy
the Jenkins URL which is the IP and the port
920.76 -> just paste it and after pasting it
type slash GitHub hyphen webhook
927.96 -> slash and then scroll down and from here
click on let me select individual events
935.7 -> and from the events we have to allow
the pull requests and the pushes
941.46 -> and then click on ADD web book so now let's
just verify the webbook if it's working or not
948.48 -> so let's just build our pipeline without
the web first verify if it's working or not
956.88 -> click on build now and as you can see the status
is success so the pipeline is running successfully
966.84 -> so now we're gonna verify it using the webbooks
just go to the repository and make any changes
973.32 -> that you want first let me just verify and show
you something so when you're in the pipeline
980.82 -> just click on workspace here you can see we
only have three folders two folders and two
988.2 -> files which is one is HTML file and one is the
config file and two are the folders one for the
993.78 -> kit and one for the HTML website so let's just
create a file here click on create file and just
1001.76 -> give it any name test Dot txt and just write
something this is a test to verify the GitHub
1016.58 -> and just click on Commit new file and it should
trigger the pipeline let's just go to the Jenkins
1023.78 -> again and verify as you can see the pipeline
is in pending state and it is successfully
1034.88 -> let's just verify as you can see the pipeline
is working fine so what we have done we have
1042.14 -> automated this process till here so whenever the
developer changes the code or adds some file or
1049.28 -> anything in the code or in the repository
it will trigger the Jenkins automatically
1054.14 -> and Jenkins will pull the code from the GitHub
we have done till Here and Now what we're gonna
1059.9 -> do we're gonna create a server for the snare
Cube so let's just go to our different installs
1070.34 -> and copy its public IP then go back
to your terminal just open a new tab
1079.28 -> and from here you have to do the same
step SSH hyphen I and the name of the key
1084.32 -> which was SSH key Jenkins and then the
username and then the IP of the instance
1095.96 -> so we are into the sonar Cube
machine now let's just change its
1099.74 -> uh hostname host mctl set hyphen hostname so in
our Cube also write the pseudo before the command
1111.38 -> then type slash bin slash Bash as you can see
the hostname has changed to sonar Cube let's
1117.2 -> just do the same with the Jenkins one so sudo
hostname CTL that hyphen hostname and Jenkins
1129.14 -> and type in slash Bash so its name also change
so we won't be confused if we're working on it
1139.46 -> so first let's just update the system
update the repositories uh sudo apt update
1156.08 -> and after updating the repository we are going
to install sonar Cube and for the sonar Cube
1161.24 -> we need Java 11. so to install the Java runtime
environment 11 just type sudo EPT install open
1171.32 -> jtk 5.17 Jr we need the Java 17 version 4000rq
1178.76 -> so let's just call the Java while the Java is
installing let's just go to the sonar Cube website
1189.02 -> and after searching for the sonar
Cube just click on the download link
1193.58 -> and from here we're going to
download the Community Edition
1196.58 -> so to download the Community Edition just right
click on the download for free and copy the link
1203.48 -> and after copying the link we have to paste
it here and download it using the wget command
1212.84 -> so let's just type duplicate
1216.92 -> and paste the URL here and hit enter and as you
can see the sonar cube is downloading right now
1222.68 -> and let's just
1227.24 -> see so here we have a zip to unzip it
we have to install a utility called
1232.64 -> unzip so to install it type sudo apt install unzip
1241.28 -> and it's installed right now
and to unzip it just type unzip
1249.8 -> and the name of the zip and it's I'm
compressing it right now and as you can
1257.18 -> see we got the snarky folder here just go to the
sonar Cube folder and from here just go to the
1264.62 -> pin folder my mouse start working fine so let
me just fix it will take less than a minute
1276.5 -> oh it's working now go to the pin folder and from
here there are three folders and it's for Linux
1284.66 -> Mac OS and windows so if you're using Windows
then just go to the windows folder if you're
1290.66 -> using Mac just go to the Mac folder but I'm using
Linux so I will go to the Linux directory and from
1298.04 -> here we have a tell file called a batch file
called sonar.sh so we're going to execute it
1305.36 -> using the dot slash sonar dot sh and then there
are some parameters that we have to pass so let's
1311.18 -> just not pass any parameter right now so I can
show you we have four options the console shows
1318.32 -> you the output also uh also the logs and the
sort command will start it in the background
1323.9 -> and the swap command will stop the sonar Cube
and force stop command will forcefully stop it
1330.5 -> and we also have the other options like
restart sitter Center so we're gonna
1337.4 -> type console so we can also see the logs
1341.96 -> to verify if it's working or not
so as you can see it's starting
1362.18 -> so it will take a few a few
seconds to start the sonar Cube
1369.62 -> while the sonar cube is starting let's
just allow its port on the ec2 instance
1374.06 -> so let's just go back to the ec2
instance and from here go to security
1380.06 -> and click on Security Group and from here we're
gonna add a inbound rule which will be 9000 port
1390.38 -> the sonar Cube and from here we're going
to select the source which will be 0.0.0
1396.98 -> it means it will accept the traffic from all IPS
and give it a name sonar Cube and then save root
1407.12 -> so as you can see the sonar cube is started and
let's just verify the sonar Cube by going to the
1413.78 -> ec2 instance and copy the IP of the sonar
Cube paste the IP and write the port 9000
1424.58 -> so the Smart Cube is working fine
as you can see the page is opening
1428.66 -> so the default login username and password for the
sonar cube is admin and the password is also admin
1438.56 -> and now just write the old password which
is admin and replace it with the new one
1444.02 -> so I will also set the new password
to the admin and then click on update
1450.44 -> so I think we have to write some other
password so I will just change the password
1465.08 -> so now we have logged in into the sonar Cube
1468.86 -> and from here just click on the project
type is manual so we will click on manually
1476.36 -> and give it a name so I will give it the
name Onyx website and then the branch
1487.64 -> also we have to give the project display key
1494.3 -> phonics website scan and it should just give it
the same project key here and now click on setup
1506.24 -> and after clicking on setup we have to use the
CI method that we're going to use so we will
1512.6 -> be using Jenkins click on Jenkins here and from
here choose the devops platform which is GitHub
1519.86 -> and just click on configure analysis and then
it's telling us the steps that we have to use
1527.18 -> just skip it and click on continue and also click
on continue here and from here click on other
1534.98 -> so we are using the HTML project so we will
click on the other and if you're using the
1540.32 -> Maven credle or dot net project then you can
select it so I'm selecting the other and from
1547.1 -> here we have to copy two things so we have to
open a text editor and copy this project key
1555.26 -> and paste it for the later use so we will
be using it later in once you've copied the
1561.38 -> copied this just click on finish the tutorial and
from here after click on clicking on finishing
1567.8 -> go to the admin user on the top right
corner and from here click on my account
1575.36 -> and after going to my account
just click on security
1579.8 -> and from here we have to create a token so
I will just give it a name Jenkins token
1586.16 -> or we can also give it the name sonar Cube
token and then select the token type so
1594.56 -> if you select the project analysis token it
will only be specific to the specific project
1600.92 -> for example we have to select the project also
so this token will only be authenticated for the
1608.18 -> this project but if you select the global
analysis token it can scan all projects that
1614.48 -> are in your sonar Cube solution so here you have
to choose the expiry let's just select it 30 days
1621.62 -> and click on generate token and from here just
copy this token and also paste it in the Notepad
1634.82 -> and now we have created a token and what we
have to do we have to go back to the Jenkins
1642.8 -> and from the Jenkins we have to install
a plugin go to the manage Jenkins section
1649.82 -> and from here click on global tool configuration
just go to the plugins not the global tool
1656.24 -> configuration we have to install the plugin first
so just click on manage Jenkins manage plugins
1662.06 -> and from here click on available plugins here
search for sonar scanner sonar Cube scanner
1673.94 -> like the snarky installer plugin click on
install without restart and we also have
1678.8 -> to install another plugin as you can see
the sonar cube is installing so while the
1683.96 -> sonarq plugin is installing there let's just
install the other plugin which is SSH to easy
1696.44 -> so our plugins are installing right
now let's just give it a while
1703.16 -> foreign
1736.64 -> plugins are installed successfully and now
let's just add the solution of the sonar Cube
1744.8 -> to edit the solution what we have to do is we
have to go back to the many Jenkins section
1751.7 -> and from here we have to go to
the global tool configuration
1758.3 -> and from the global tool configuration just
scroll down and you will see sonar scanner
1764 -> click on ADD sonar Cube scanner
and give it any name that you want
1770.54 -> sonar scanner and check the install
automatically and then save it
1779.9 -> so after saving it what we have to do we
have to go to the configure system now
1785.6 -> and from the configure system
1792.14 -> just scroll down and you
should see sonar Cube servers
1795.74 -> so click on ADD sonar Cube
give it any name that you want
1800.96 -> let me just give it so now our server and from
here we have to give it the URL of the sonar Cube
1808.82 -> just copy this and paste it here and then save it
1816.98 -> now just go to the pipeline that we have
created earlier and go to the configure
1823.94 -> and what we're gonna do we're gonna add a build
step here which will scan execute the sonar Cube
1829.46 -> scanner and here just ignore everything and
paste the token here that not the token but uh
1839.42 -> the key also just paste the key here and save it
and now we have to go back to the many Jenkins
1850.04 -> and configure system because we also
have to add the sonar Cube token here
1854.42 -> which we haven't edited yet and from here we have
to click on ADD and from here click on Jenkins
1864.14 -> and the token type will be the secret
type will be it will be secret text
1870.62 -> and here we have to paste the token
that we have copied from the sonar Cube
1876.38 -> and give it any ID so I will get
give it sonar token and then save it
1887.06 -> then select a token from here and click on Save
1892.82 -> now go back to the pipeline
1896.6 -> go to configure and let's just see if we
have any other thing to add so we don't
1905.9 -> have to add anything else now let's just build
our pipeline to verify if it's working or not
1914.66 -> so as you can see it's currently running it
1923.72 -> now the sonar cube is scanning our code the scan
is in progress as you can see from the Jenkins
1930.68 -> uh we also got the status success so let's just
refresh the page and as you can see it scanned
1939.68 -> our code and our code passed so once our code
passed we will deploy it on the docker server
1949.34 -> and that's just
1953.54 -> go to our third ec2 instance in
which we will be installing docker
1958.64 -> from here just click on the instance
ID and copy its public IP then open the
1967.16 -> new tab for the terminal and then SSH hyphen
I and the name of the key username and IP
1980 -> so we are into the docker instance now let's
just change its hostname uh type sudo just
1988.7 -> post name CTL set hyphen hostname docker
1998.24 -> then type in slash as you can see
the host name of the server changed
2002.8 -> and now just clear the screen
and run the APD update command
2008.86 -> and while it's updating let's just install
docker go to install Docker let's just
2015.28 -> go to the docker website or just
search for Docker install Ubuntu
2024.52 -> and from here
2028.36 -> we have to start from here setting
up the repository for the docker
2032.68 -> so we're gonna be installing the tools
that are required for the talker and
2041.38 -> I think I just closed my Docker
server I just start another tab
2061.72 -> uh it's taking a while it's
2065.92 -> let me just verify if the inside is
working or not so it's in the running state
2076.9 -> let me just verify it by
pinging it let me just ping it
2084.4 -> so our instance is not working and I think the
IP is different yes so I was writing the wrong IP
2109.36 -> oh so the key is also wrong
I also wrote the wrong key
2118.24 -> now as you can see we are into the
2121.24 -> Docker instance and now just paste the command
that we have copied from the docker up website
2130.66 -> and just type yes and let's just copy
the other command to add the gpg keys
2144.82 -> just paste the keys and now what we're
gonna do we're gonna run the third command
2153.76 -> then we're gonna run the update command
2160.42 -> then we're gonna install the docker
2173.86 -> so what we have done till now is we have pushed
the gold code to the GitHub then we pulled it
2180.46 -> through the Jenkins then we scanned the code
through sonar Cube and after scanning the
2185.44 -> code we will be deploying it on the docker
and then we will access it on our browser
2192.04 -> so now we're going to deploy the code from Jenkins
to the docker server then we will access it
2200.02 -> now what we're going to do here uh uh let's
just verify if we have the keys installed
2206.74 -> so we have to do two things on the on both of
the servers the Jenkins and the docker server
2214.66 -> to first go to the Jenkins server
and switch to the Jenkins user
2224.44 -> so now we are as Jenkins user so whenever
we solve the Jenkins it creates a user
2230.56 -> named Jenkins let's just SSH the other
server from here and verify if we can SSH it
2240.04 -> dot one six three so this server is the docker
one 4.0 type yes so we got some error it says
2251.68 -> permission denied public key go to fix this error
we have to go to the docker server and from here
2257.14 -> just switch to the root user and from the root
user we have to edit the sshd config files
2268.42 -> this is set the config
2280.24 -> so we have to uncomment this and
2288.76 -> and change the password authentication to yes
2295.18 -> then save it and restart the sshd service system
CTL restart sshd now let's just verify it again
2305.92 -> and as you can see it's asking for the Ubuntu
password so we have to set a password for the
2310.42 -> Ubuntu user which we haven't already so to
change the password of the Ubuntu user type
2315.46 -> pass WT and the username which is Ubuntu and
here just to give it any password that you want
2324.94 -> and you can see the password is updated
successfully and now if we type the password
2330.1 -> Here we are into the Ubuntu machine so exit it and
then we're gonna copy we're gonna generate a key
2338.56 -> SSH key gen to generate a public
and private key hit enter enter
2344.98 -> and we have generated a
key now we have to type SSH
2349.18 -> iPhone copy hyphen ID and the name of the server
2357.16 -> so the keys are added now
let's just verify it again
2361 -> so as you can see we can get into the docker
server now let's just go to the Jenkins
2369.94 -> and from the Jenkins we have to go to the
2373.36 -> managing section and from the many Jenkins section
we have to go to the configure system and here
2379 -> we will add the docker server here so it can
execute the remote commands on the docker server
2385.3 -> and here we have to scroll down and look
for server group Center let's just add a
2393.46 -> group group name which is Docker servers and the
port and the username so the username is Ubuntu
2403.36 -> and the password is whatever password
you wrote in the possibility command
2409.66 -> then save it and go back to the
menu Jenkins and configure system
2418.12 -> and now scroll down and from here
what we're gonna do we're gonna add
2424.78 -> here we edit server group and now we have to add
the server so let's just select the group select
2433.36 -> the group is Docker servers and the server name is
Docker one and just give it the IP of the uh what
2444.16 -> was the IP of the docker server so just copy it
from the ec2 sounds hmm and paste IP then save it
2454.96 -> and now just go back to the
pipeline and go to the configure tab
2462.64 -> and from the configure tab just scroll down
and let's just verify it if we can execute
2467.38 -> the remote command uh from here just look for
remote command here you can see remote shell
2478.48 -> just select the remote shell and select the
target servers which is this and let's just
2486.82 -> run a command called touch test Dot txt
2494.86 -> let's just build the pipeline again
to verify if it's working or not
2499.36 -> so it's it seems to be working so now the
code is being scanned by the sonar Cube
2506.44 -> and once it's scanned then it will run
the remote command on the remote server
2515.44 -> so we got the success message let's just verify uh
2523 -> just type LS and as you can see we got that
test.txt file here so now what we're gonna do
2530.86 -> we're gonna go to the uh we're gonna go to the
repository and from here we're gonna add a file
2538.3 -> click on create new file and here it will be a
Docker file so just type Docker file in the name
2547.42 -> the D is capital and there's no extension of
the docker file and from here we're going to
2552.16 -> use the image uh nginx and then we're gonna
copy the current contents of the directory
2561.28 -> to the user let's just go to the nginx
Docker Hub website and from here we will see
2571.12 -> what's the default path for the nginx so the
default path should be user share nginx HTML
2580.72 -> let's just copy the path from here
2584.8 -> and go back to the GitHub and from here
just paste the path and now we're gonna
2591.52 -> save it commit new file and it should exec uh
it should trigger the pipeline automatically
2597.28 -> so let's just verify it if it it's working or
not so as you can see the status isn't pending
2603.94 -> and it will execute the pipeline in a
second so our pipeline is executing now
2612.82 -> and once the pipeline is executed what we're
gonna do we're gonna go back to the configure tab
2621.7 -> and from here we have to run a command
2624.88 -> uh uh we have to let's just remove this
remote shell and click on execute shell
2635.56 -> and from execute shells just type SCP so
basically what we're doing we're copying
2641.14 -> the current contents to the remote server so so
secure copy command and then the directory which
2651.82 -> is dot slash static so we're gonna we're going
to be copying all the contents of the current
2658.36 -> directory to the remote server which is Ubuntu
at the rate and then the IP of the Docker server
2670.6 -> then type call in and Slash uh where we we're
gonna be pasting the file so let's just create
2680.38 -> a folder here exit uh make a folder here called
website or any folder that you want mktir
2691.72 -> website so now we have a
folder called website here
2697.6 -> and what is the path of the folder let's just
get its path which is home Ubuntu website
2711.04 -> website
2714.58 -> and then just click on Save and let's just
build it again so we got a error here called
2722.86 -> field let's just verify it what caused our
website to fail so this failed because we
2731.26 -> added a Docker file and it's finding the bugs
in the docker file so let's just verify it again
2743.74 -> so as you can see it's failing because of the
docker file so there's nothing nothing to worry
2749.98 -> about and we should not put the docker file in the
Repository but just to show you we are gonna we're
2758.74 -> gonna put the docker file in the repository
but it's not recommended to put it in the
2763.54 -> same repository you can also create a different
repository for the docker file and then you can
2769 -> move it to the remote server using
the SCP command so we got a failure
2779.02 -> uh what failure we got so we have to
add hyphen R after the SCP command
2785.32 -> so it will also copy the directory
and the content inside the directory
2792.88 -> just go back to the pipeline click on configure
2796.78 -> and just scroll down and from here just type
hyphen r and then save it then click on build now
2821.74 -> so as you can see we got the success message here
our python is successful and let's just verify
2830.14 -> here you can see the contents that we created are
in the docker server now and now what we're going
2837.52 -> to do we're gonna build the image and then run the
container from it so just go back to the pipeline
2844.54 -> and go to the configure tab and from here just
go to the execute just add a remote shell execute
2857.86 -> a remote challenge in which we will be just
going to the 2.2 folder Ubuntu website folder
2865.18 -> and there we will run the docker build command so
first we have to verify if we can run the docker
2872.08 -> command from here or not as you can see we're
getting an error it says permission denied so
2878.5 -> if we run the same command with the sudo it will
work but with the current User it's not working
2884.5 -> so to fix this issue what we have to do is we have
to type a command called sudo user mode hyphen a
2891.94 -> small and the g is capital so we're gonna be
adding the current user to the docker group and
2898.06 -> here's the name of the group and the username is
Ubuntu then hit enter and then type new grp docker
2907.3 -> and now let's just type the docker PS command as
you can see it's working now so now what we're
2915.1 -> gonna do we're gonna run a command called Docker
build iPhone tag and the name of the image that
2921.52 -> we're gonna give it we're gonna give it my website
and then the path of the Docker file which is
2928.72 -> dot the current directory and then we're gonna
run a container from this image so Docker run
2938.08 -> detachable mode and uh Port so the port
will be let's just give it 8085 and
2947.02 -> 80. so this is the port of the container
and this is the port of the system
2953.62 -> in which uh it will it will be exposed on the
port 8085 and the container Port is port 80.
2961 -> and then give it a name hyphen iPhone name is
equals to uh let's just give it phonics website
2972.04 -> and then the name of the image which is my
website let's just save it and build it now
2988.66 -> so you can see it's the
pipeline is executing right now
2999.22 -> it's building the docker image and now we got
the success message let's just verify if it's
3005.82 -> if our container is working fine or not so as
you can see our container is uh working fine
3010.92 -> on the port 8085 but we cannot access it right
now because we haven't allowed the port 8085
3017.34 -> so to allow the port just go back to the
ec2 instance and here go to the security
3023.28 -> and from the security groups just add an inbound
rule which will be custom TCP and port 8085
3032.82 -> and the IP address the IDR block which will
be zero and the description will be your
3039.3 -> next website or you can give it any name that
you want now save it and let's just verify it
3047.4 -> go to the instances copy the public IP
3052.44 -> the space the IP and write the
port 8085 and as you can see
3060.42 -> uh the website is working
but the CSS is not loading so
3094.02 -> so the website is working fine but the CSS is not
loading so to fix it let's just do one more thing
3106.02 -> let's just remove the
3121.32 -> so it's using the bootstrap Library which is not
loading I don't know why what's the reason but if
3127.62 -> you try it with some other website it should work
fine and thank you for watching the video let this
3134.76 -> video helped you and let's just repeat what we
did from the start so we pushed the code to the
3141.66 -> GitHub and then we pulled it from the Jenkins then
we scanned the code through sonar Cube and then we
3146.76 -> deploy it on the docker container and then we
access it through the uh through the browser
3156.42 -> so thank you for watching the video make sure to
subscribe the channel I hope you like the video
3161.16 -> give it a thumbs up and hoping to see you
in another video take care and goodbye