- [Instructor] Now that we've created
the application load balancer and have ECS in order,
let's have Jenkins build some stacks for us.
So heading back to my editor,
I've added a couple of files
to the project for these purposes,
and the first one, run-stack.sh,
is our stack definition file.
This defines everything about our production
in one big, long file written in the YAML format.
So it starts off at the top with a description,
and then some parameters,
these are the parts that change
from deployment to deployment.
You'll need to set many of these
in order to run it in your account.
Below the parameters, we get to the meat of it,
the resources.
Every entity here is one thing
that needs to be deployed as part of our environment.
So, the security group is defined,
the service is defined,
the task is defined,
and a few helper roles are created below that.
The Services job is to ensure
that the correct number of ECS tasks
are running at any given moment,
and a task definition defines exactly
which image should be run, and how,
at what resources it gets
in terms of memory, CPU, et cetera,
and on what ports it should be allowed to receive traffic.
For this environment, to make things simpler,
I'm going to go ahead and use the AWS Fargate feature,
which automates the process of allocating instances
to run your containers.
You pay slightly more, but you gain it in convenience.
The next file is run-stack.sh.
Now this one is just a wrapper
to help us use that service.YAML file
a little more easily from our Jenkins file,
which we'll get to next.
So the important part down here
is we have AWS CloudFormation deploy,
that deploys a Cloud formation stack,
from a YAML file in this case.
So we're going to define a few things,
and you'll probably need to edit
most of the parameters here.
Region, that'll need to be set to the region you are in.
I happen to be in us-east-1,
the stack name will be passed as a parameter,
the service file, that's fixed,
and we need to say that this thing gets
the special permission to create IM roles with names.
That's just to ensure that you don't deploy a stack
that creates permanent things by accident.
Now, the parameter overrides.
Down here, this is where we pass parameters
into the service.YAML file that we just looked at.
So the most important one is going to be the docker image.
So this one's going to be built
by passing the path to your accounts ECR registries.
So the part that will be different for you
is the account number at this part,
and the region here.
Then the registry name, example-web app,
that's where our pipeline pushes our production stuff,
and we have a little bit of a shell helper
to fill in the current get hash,
just so we don't have to look it up
or pass it in as a parameter.
This next one, the VPC, or Virtual Private Cloud,
let's show you where to look that up.
So over here in the AWS console,
if I head over to the VPC service,
and then Your VPCs,
the one I built for doing this course
is this one right here,
so I've gone ahead and pasted that there.
Then, the next parameter, Subnets,
also comes from that page.
So we need to find a subnet within that VPC.
I see that the VPC matches here,
so I'm going to grab this subnet, cut,
and paste it in here.
The cluster name I used is Default,
which is the default name,
and the listener will be passed in.
So let's look at where these are going to get passed in from.
Well, over here in our Jenkins file,
the last thing we did
was we added the ability to deploy to a fixed server
for only the release branch,
strolling down past this next section,
which we'll use shortly.
Down at the bottom we have Deploy to Production,
this is deploying to production,
but using a Cloud formation stack.
So I'm going to go ahead and un-comment that.
And let's take a look.
There's one value in here you're going to need to customize
which is the Production Listener ARN.
Let me just slide that back onto the screen.
Now let's go look that up.
Okay, so over here in the load balancer,
I'm on the load balancer we just created,
we have the Listener's tab.
And here we have the listener for port 80,
but that's not what we want.
What we actually want
is this little, tiny gray arrow right there,
you click it, and the answer is revealed.
So we're going to cut this, and paste it in here.
The next line is just a shell script invocation
that runs the script we were just looking at.
So now that we've looked at what we're deploying,
let's see it in action.
I'm going to head over to my shell and do git add,
the files we just modified,
Jenskinsfile, run-stack.sh,
then, git commit-m,
let's say, adding real deployer.
Okay, then git push origin master.
And let's go watch it run.
Over here in our our example web app project,
back in the master branch,
and Jenkins has noticed our new commit
and started the build.
All right, and Jenkins has started our production deploy.
If this doesn't work,
and it often doesn't work on the first go,
you can head over to the CloudFormation service
in the AWS console,
find our production stack,
click on the stack,
and click on events to watch it go.
Here we see that it's in the state update in process
and it is currently deploying the UC2 service.
If it goes wrong,
and it's very likely to go wrong
on the first couple of tries,
the actual reason for the failure
is the text down this column here,
next to whichever one of these first turns red,
lowest in the list.
Heading back to Jenkins,
let's wait for it to finish.
All right, our deployment finished,
let's go see if it worked.
I'm going to head back to the load balancer we created.
Back on the Description tab,
here we have the DNS name for our load balancer.
I'm going to go ahead and copy that,
open up a new browser tab,
load it in and viola!
Our example app is now running
with a fully automated deployment, end-to-end.