- [Instructor] For the demos later in this course,
we're going to need a Jenkins installation
to set up jobs on and show how it uses Docker.
So, if you already have a Jenkins installation,
or prefer to install it using one of the other methods,
please go ahead and use the Jenkins you already have
or set it up your own way.
The only thing that's required
is that you have a Jenkins instance
that's capable of running Docker.
In this demo, we'll set up only the very most basic Jenkins.
It's just a single box that runs both the Jenkins Master
and the build nodes on the same system.
This is not a suitable setup for production.
If you're using this for real,
you're going to want something more serious.
So let's start by connecting to the EC2 Management Console,
going to EC2 Management Console
and let's begin by setting up a security group
to allow access to our new Jenkins installation.
Create Security Group, group name, Jenkins.
Description, web and SSH for Jenkins.
Choose my VPC, Add Rule, I want to allow port 8080,
the default Jenkins port.
And I want to allow port 22, so that we can SSH in.
Okay, now that we've made that security group,
let's head over to the Instances Section,
choose launch instance.
And I want the Amazon Linux 2 LTS Candidate.
By the time you see time you see this recording,
the candidate word may have been removed.
All right. T2 Micro is fine.
Now I'm going to choose the same VPC
I chose for the security group.
And make sure under Auto-Assigned Public IP
that it's enabled.
We don't need an IAM role yet,
we'll be creating one later in the course.
Okay, I'm going to want a little more
than 8 gigs of storage.
Now for security groups,
click select an existing security group
and I'll choose Jenkins,
the one we created a moment ago
and launch.
Choose my SSH key,
check the box indicating that I actually have it.
And then head on over to our instance.
Now that my instance is running,
I'm going to copy it's public domain name
and head on over to the terminal.
SSH -I and SSH into the instance as you normally would.
I put my key in .SSH/Amazon key.pem,
your key will be in a different location
or you may not need to specify this option at all,
depending on your environment.
The username is EC2 user at paste in the domain name.
I've never connected to this instance before
so I'll need to confirm its fingerprint.
Okay, now that I'm logged in, let's install Jenkins.
First, we're going to add the official Jenkins repository
to our installation.
Sudo wget -O/etc/yum.repos.d/Jenkins.repo.
And we're going to be fetching that from
http://pkg.Jenkins ci.org/redhat Jenkins.repo.
Next we want to add the Jenkins organization signing key
to the trusted organizations allowed
to install packages on this system.
Sudo rpm import HTTPS pkg Jenkins.io/redhat/jenkins.io.key.
Okay. If it doesn't print anything that means it worked.
Jenkins needs Java. So let's go ahead and install Java.
Sudo yum install Java -1.8.0.
Yes, it's okay to install 38 megabytes.
And finally we can install Jenkins.
Sudo yum install Jenkins -y.
Saves us typing Yes.
Sudo system cuddle start Jenkins.service
to start Jenkins running now
and Sudo system cuddle enable Jenkins.service
to ensure that it starts after reboots.
Heading back to the browser.
Now let's set up our Jenkins instance.
I'm going to go ahead and copy the DNS name,
open up a new tab, paste it in
and put :8080 the default Jenkins port on the end.
Okay, Jenkins by default shows up initially locked
so that no one can use it
until you've confirmed ownership of it.
This is to prevent somebody on the internet
from wandering in at just the wrong moment
and taking over your Jenkins.
So let's copy that path,
head back to the terminal,
sudo cat paste in that path and we get our password.
Copy the password, back to the browser pasted in, continue.
Okay, the suggested plugins will be just fine
for this installation.
Okay.
I'll set up the user for myself here, Arthur, password.
Okay, now that I filled in the user information,
save, and finish.
All right, now the Jenkins is installed
before it's truly useful to us.
We're also going to need Docker.
heading back to the terminal,
sudo yum install Docker,
answer yes.
Now I start the Docker service.
Sudo system cuddles start Docker.service
and Sudo system cuddle enabled Docker.service
so that it starts after reboots.
And now we want to give both ourselves,
and Jenkins permission to use Docker,
sudo usermod -a -G Docker ec2 user,
that adds the EC to user,
the one we're currently logged in as to the Docker group,
and we're also going to want to add Jenkins to the Docker group
so Jenkins can run Docker commands as well.
And in order to be sure that the Jenkins user has noticed
that it's in the new group I'm going to go ahead
and reboot the instance, sudo reboot.
And now we're waiting for it to come back.
All right, now that my system is rebooted.
I SSH back in and let's test out Docker.
Docker run hello world.
Ah, it worked.
And now let's see if Jenkins is allowed to use Docker.
Sudo -U Jenkins Docker run hello world.
The dash U says to run it as the Jenkins user.
Ah, Jenkins is allowed to use Docker as well.
All right, now returning to my Jenkins instance.
I'm going to login since we rebooted.
New item.
And I'm going to make a new job
called Docker test freestyle project.
Okay.
Docker test is going to to have only one action,
Execute shell, Docker run, hello world.
Let's go ahead and build that.
Ah, it worked.
Now we have a Jenkins instance that can run Docker commands.