[MUSIC PLAYING]
KELSEY HIGHTOWER: Hi, I'm Kelsey Hightower, a staff developer
advocate for Google Cloud Platform.
MATT HOOKER: And hi, I'm Matt Hooker,
an engineer at HashiCorp, working on Packer.
KELSEY HIGHTOWER: All right.
This is the third video in a series covering open
source tools from HashiCorp and how we can use them
with Google Cloud Platform.
In the last video, you learned how
developers can create repeatable development environments
with Vagrant.
In this video, Matt and I are going to cover Packer.
Matt, can give us an overview of Packer?
MATT HOOKER: Yeah.
Thanks, Kelsey.
I'd be happy to.
Packer may at first seem a lot like Vagrant in the sense
that it can be used to define the software
and configuration for a VM.
But unlike Vagrant, the artifact it produces
is a machine image, as opposed to a running VM.
The machine image can be used to create VM's preconfigured
exactly how you want them all through a simple Packer config
file.
This is where it gets cool.
With a single configuration and common specification,
Packer can produce almost any machine image
like Google Compute Engine, other cloud providers,
and even Docker images.
KELSEY HIGHTOWER: Yeah.
Packer is pretty dope.
I've used it in quite a few of my projects,
and know a few people using Packer.
In fact, I'm the original author of the GCE builder for Packer,
going back many years now.
MATT HOOKER: Nice, I didn't know that.
OK.
Then you might have some kind of demo or something
you could show us.
Right?
KELSEY HIGHTOWER: That's why we're here.
Continuing the story from last time,
we're going to create a GCE image based on a similar config
you saw in the Vagrant video.
You'll recall from that video that Vagrant
was to be used by developers, but the main goal of creating
their application and sharing across a Vagrant VM on Google.
Now we're going to start sliding the perspective
from our developer view over to our operations
view where you want to deploy these images on GCE
for the running the app for our users.
So the image we're going to create
will have our '80s style arcade game,
and its dependencies installed and configured
to start at boot time.
Matt, how do we get started?
MATT HOOKER: Let's do it.
You want to start by going to Packer.io
and downloading the version appropriate for your platform.
In the last video, you saw how to set up your GCP project,
so we'll skip that part this time,
but I think this time we're going to use a GC instance.
Right, Kelsey?
KELSEY HIGHTOWER: Right.
I have a machine called DEV that we're going to use.
We're going to be using Packer to create a new GCE operating
system image.
I'll first show you what we currently only have,
the standard GCE images available to us.
MATT HOOKER: Great.
Now let's flip over to our terminal on the DEV instance
where I already have Packer installed,
and my Packer config file ready to go.
Let's kick off the image field process
now with the Packard build command.
OK.
Now that we've got that going, let's
take a look at the hyperspace JSON config file we're using.
Packer config files have two primary parts.
A section that specifies builders
and another for provisioners.
In our builder section, you can see that I'm not only
defining the variables needed to produce the Google Compute
Engine image, I'm specifying attributes
such as the base operating system
and the name of the new image.
Let's take a quick look at the provisioner section.
Packer allows you to customize the image
with any number of provisioner types,
like basic shell scripts, which is what you see here,
or even using other configuration management
tools such as Chef, Puppet, Ansible, et cetera.
But back to the topic of builders.
Kelsey, do you want to describe how Packer
builds an image for a GCP?
KELSEY HIGHTOWER: You bet.
First, Packer spins up a new instance
with the base image that was described.
Then, Packer will SSH into the new VM,
and apply any configuration defined
in the provisionary section of the Packer config.
Here, we're basically reusing the shell script
you saw on the Vagrant video, but split it out
into its own file.
Let's see how the build process is doing.
OK.
Looks like it's running through those provisionary steps
and our shell scripts.
We'll skip ahead here a little bit,
even though I know we all love watching
deadman packages install.
Once the provision and customizations have finished,
Packer will terminate the running GCE instance,
but will leave behind the Persistent Disk,
or PD as we like to call it.
The PD contains the base operating system,
and our customizations, and is used in a template
to create the new GCE image.
Once the image is created, Packer deletes the PD,
so there aren't any leftover resources in your GCP project.
MATT HOOKER: It's finished.
Let's take a look at the list of images now.
And sure enough, there's our new hyperspace image.
We can even quickly spin up a new GC instance
with our brand new image.
I'll click the checkbox next to the image,
and click the Create Instance button.
I'll keep all the defaults, but since hyperspace is a web app,
I'll enable the HTTP firewall rule for the instance,
and then click Create.
KELSEY HIGHTOWER: Hey, Matt.
While we're waiting for this new instance to come up,
let's take a look at the console output as it's booting.
You can hit Refresh and see the new console output show up.
OK.
The instance is up.
Let's click on the IP address to see what happens.
Bam!
Now, that's dope.
MATT HOOKER: Great demo, Kelsey.
Obviously one of the biggest strengths of Packer
is the ability to produce equivalent images
across multiple cloud providers.
We definitely hear of customers that want multi-cloud support.
So it's been great to see Google contributing to the project.
KELSEY HIGHTOWER: All right.
Thanks, Matt, for joining us today.
MATT HOOKER: My pleasure.
It's been a lot of fun.
KELSEY HIGHTOWER: All right.
Thanks everyone for watching.
Don't forget to subscribe to the channel
to keep up with more of the videos in the series.
We've got more coming for how you can use other HashiCorp
tools with GCP.
Also take a look at the description
to see some of the work our colleague has done on creating
an automated image builder using Jenkins, Packer,
and Kubernetes.
All
Right.
Thanks for watching.
Make sure to check out our last video in the series as well
as the playlist, and don't forget to subscribe.
[MUSIC PLAYING]