what if i told you in just four simple steps you could create a
fully automated imaging process for your windows or linux images or even
something more specific like windows virtual desktop
sounded good to be true well you've never seen an image pipeline like this
one
i'm Dean Cefola and this is The Azure Academy if you want to master the azure
cloud you can start right now by clicking the subscribe button and the
notification bell so you don't miss anything
today we want to talk about the azure image builder which is your tool to help
you develop an imaging pipeline process to fully automate
everything now the way all image creation processes
work is we start off with a image of some kind that could be
anything from a iso of a linux image or a linux or
azure gallery image or even your own custom
source image we're going to bring that into the
azure image builder process and then create a pipeline that's going
to let us do customizations and then get that image distributed out
as a virtual hard drive file which could be used in things like azure stack
or you could do that as a azure managed image and use that in the cloud or put
it in the azure shared image gallery which is going to allow us to use it in
things like windows virtual desktop to keep our images up to date or
scale that image to be replicated anywhere in the world
even across multiple azure subscriptions or azure ad
tenants so once we have our image we're gonna build some vms and do
testing and then this becomes an iterative process where we're going to
take all of those learnings and cycle right back through our pipeline continue
to make updates to our source customizations
testing process and keep on distributing and improving
everything so here's the plan for today we're gonna create
three windows images we're gonna get them distributed
out to at least three azure regions and then
we're going to create a pipeline for our wvd image
so that we can fully set up and deploy windows virtual desktop with
our optimizations fs logics everything over in github you can find the repo
where all of this code comes from and i'll have this linked in the video
description we're going to do this in two parts we're first going to do a
quick start just to get everything up and running
and then show you how to integrate this with azure devops to do
a full customized pipeline yourself so in the quick starts here we're gonna do
this with a windows image and we're gonna use number
one here to create a custom windows image and the shared image
gallery so all of the code that we have for this is pulled directly
from here and i'm also going to go to
shell.azure.com and sign in so over on the right this is
the powershell ise that i've got all the code set up so
i've grouped this into two sections the top being the prereqs
and then the second section which is the actual
code execution to do everything and we're gonna just
run all of this code at once so the very first thing is the prereq so
let's register to use the image builder and it will
come back in a few minutes and tell you that it is registering or that you're
already registered then they have the next command which
shows whether or not you register so you can check on your progress
and then after that you just want to make sure that you're registered for
these four providers so that everything is good to
go now we're gonna run everything here except for the very last
commands because that has to do with the shared image gallery you could run that
right now but it'll just throw an error because we don't have an image in
the gallery to replicate so we'll just copy all that code into the azure cloud
shell the code has finished executing by now
so it just takes a few minutes and over here in the powershell if you
notice on the right we've got this build json status command and that's
what you're seeing over here in the cloud shell right now so the job has
provisioned successfully its current state is
running and the sub state is at the job is queued
back in the resource group where our shared image gallery
is we've got our new image definition that is completed
being set up and replicated out to our primary and secondary regions so the
process is done and all you had to do is just
sit there and let it run now what can we do with it from here if
you don't have an instance of azure devops it's real easy to create one at
the search bar at the top we'll just type in devops
and we'll go to our devops organizations which gives us a link
down here in the bottom left for my devops organizations
and if you don't have one then it'll ask you to create one
and i'm going to spin up a new organization here for myself then you
can give it a name and select whatever region you like
i'll pick central us and hit continue and now we need to create a project
and i'll call my new project azure image builder i'll make this a private
project and we'll hit create and in devops at the top
right we'll click the little marketplace icon and then we'll browse the
marketplace for an extension and we'll search for the image builder
to go with the preview version today and click get it free
and then click to install this into your project and then we'll click proceed to
our organization and we'll click on our project to get
right back to where we were under our repos
we want to click initialize down here at the bottom we're going to create a new
folder and we'll call it web app because we're
going to add iis to this server and we'll create a new file here
called default.html as the first page back in the github repo under the web
app folder we've got a default html file here
and we'll just go to raw and copy the contents and we'll paste that into our
repository and additionally i'll just add in one
more line of html code here saying welcome to my web server we'll
give the name of the server azure academy rocks and there's the
preview of what it should all look like and once you're happy with it hit commit
and with all good coding practices we should add some comments and then
we'll hit the commit button now you want to click next to the web
app folder and create a new file and we'll call it webconfig.ps1 and hit
create back in the repo we'll do the same thing
go to the raw of that particular file copy the
contents and paste it into the web config add our
comments and commit now when this process goes
through the pipeline it's going to take this web app
folder drop it onto the virtual machine process
the powershell that's going to add iis to the system
set the firewall rules and add our default htm
for our web page and then in the end it should
look like this all right with the prep work completed now we're ready to go to
pipelines and create a new release and this is how we're going to get the magic
to happen create a new pipeline and at the top
here we want to select an empty job and i'll name the stage here
image build since we're creating our image with this pipeline
and at the top here we'll click save then over here on the left we'll click
to add an artifact this will be an azure repo and we'll
select the drop down for our particular project
and then we'll select our source repo our master branch since that's the only
one we have at this point and that should also default to the latest branch
for our version and we'll click add for that artifact
now we want to click on the build stage task and this is where
the extension from the marketplace is going to come in
so we'll click on our agent job and we want to add
here and search for the image builder and we'll select that and hit add
and now you see that some settings here need attention that's because we have to
fill all this out now we have to select which subscription we're going to build
this in so we want this to be the same
subscription resource group etc where we've got our
shared image gallery when you first select your subscription
you do need to authorize this this gives devops permission to do stuff in
your subscription and once that's complete you'll be able
to select your resource group as well as your
region now we have to paste in the resource id
from the managed identity that we gave rights into our shared image gallery so
we'll click on that go to properties and copy the
resource id and we'll paste that now the pipeline
needs to know what type of image we're working with
managed image would refer to a image that's in azure
shared image gallery is what we're going to use today but you could
also do an azure marketplace image if so you get a drop down here where you can
select one of several images from the marketplace that you want to work with
and customize but because we already have a shared
image gallery set up with a base image we'll use that we need
the id from the image version that we created in our previous
task so back in the azure portal we'll go to our image
version go to properties on the left and then copy the resource id
and we'll paste that here scrolling down a bit more to the customize section
now we've got to select our provisioner type shell would refer to
bash and powershell is what we're going to do for windows
and it is generally recommended to check the box for running windows
update that way it's something you don't have to do manually you don't need
another tool to be able to do that like configuration manager
it'll just happen right as part of the process now for as far as the build path
goes this is where we add in our customization files so we'll click the
three dots and we'll go to our linked artifacts
this is pulling directly from our repo we'll go and click on that web app
folder and there we see our default htm and our web config and we'll just hit ok
on the web app folder that way we capture both of those files
so for the inline customization script this is where we tell it to kick off our
powershell and again i just pulled this command
right out of the github repo documentation for this process and now
we have to select a storage account we created this as part of our shared image
gallery step originally and this is where we're going
to set our distribution type so this is going to go again to the
shared image gallery and this image id is for the definition back in the azure
portal we'll click on our definition file go to properties and copy the
resource id and we'll paste that and now we have to
tell which regions we want to replicate the image into and they should be
separated by a comma and now we'll also scale this
out from going just from east and west us to include central us
as well so now for our target vm that we're going to provision
as part of this process by default it's a d1 v2 but you can do whatever size you
like so i'm going to make this a b2 ms so
with that complete we'll hit save add any comments if you need to and at
the top we'll click to create a release i've added a release
note here of this is our first try and we'll hit create
and now it's pretty much just wait and watch
we've got our image version here and if we go to update replication it has
successfully made it to all three regions if we go back to the overview
we'll spin up another test vm and once your vm is built just copy your
public ip address and open a new browser tab
and if we go to port 8080 there's our custom web page that we had set up in
our devops repo all right image number three windows
virtual desktop pipeline here we go so in the azure portal i've got a
different shared image gallery that's here called shared image gallery zero
zero i've currently got a definition here for
windows 10 and a version of that image and i do have a managed id
and i've given it permissions appropriately
so it can control the shared image gallery over in azure devops we're going
to create a new folder in our repo we'll call that wbd and we'll create a
new file in here called new wbd session host.ps1
and over in my github repository i'll go into my wbd
repo into the powershell folder and we'll take a look at that
same file we'll go to the raw and just copy it all
and we'll put it right into our repo now we do have
three input parameters in this script for our profile path for fslogix our
registration token for the host pool we're going to join
and our default for optimizations here are true
so hit commit on that and i'll add my comments and hit commit
so back on the left under pipelines we'll go to release and we'll create
ourselves a new release here and we'll start with that empty
job again and rename our stage as wvd and over on the left we'll click add for
our artifact and pull from an azure repo and you could have just as
easily pulled from github but just for the sake of consistency we'll keep it as
an azure repo we'll select our azure image builder
project and our source repository pick our master branch and again our
latest branch as our default and at the bottom we'll click add now
let's click on our job here then we'll click our agent job again
where we have the plus to add a task and we'll search for the image builder
job and add that and then click on it to add our settings
we need to add the resource id for our managed identity once again
so we'll go back to the portal grab the managed id go to properties
copy that resource id back into the portal and our image type
will again be pulled from a shared image gallery
back in the portal we'll pull the version id
under properties we'll copy that our provider will once again
be powershell and we will choose to run windows update again here
we'll select our build path and browse to our wbd folder
and select that where we'll pull in our new host powershell file
now we need to add the inline customization so we're going to need our
input parameters and we'll execute the code from c build
artifacts slash wbd then we need our parameters
that'll be dash profile path and i'm putting in where my fslogix
is stored and then we need our registration token for our host pool
and i put that here as well and then of course we select a storage account we'll
again choose the shared image gallery and from
the azure portal we'll grab our image definition properties and then resource
id and then what regions we want this to replicate to
and we are ready to go at the top we'll click save
then click to create our release and hit create
our job is queued and now all we have to do is wait
and our image pipeline has completed and we've got everything successful so going
back to the azure portal our image version has been deployed into
the shared image gallery replication into the east u.s region is
complete and i want to show you how we're going
to integrate this into an arm template so you can do a fully
customized deployment and add some extra things if you like
i'll copy the resource id of my image version
and up in my github i'll go to my wvd repository
to wbd templates new host and we'll scroll down
and deploy a new host now before i fill out the entire template i'm going to go
to edit this template on the left we'll go to
our virtual machine scroll down just a little bit and we
have our image reference now this is pointing at the microsoft
gallery image and i actually want to replace that
and i can point it at the image version in the shared image gallery by using an
id so we're good with that now i'll click
on the last item on the left here this is the custom
script extension that was doing the work to add this to
wvd set up fslogix etc before we had the azure image builder so
i don't need this anymore so i can just delete it
and since it was the last step in my process there won't be any dependencies
that i need to clean up hit save then we just fill out the
template here as normal and with that we're ready to build
all right with that complete we've got our new resource group set up with our
new vms and if we go to the boost pool that we
were joining them to and now if we hit the refresh button
there we've got our new vms from our pipeline
and let's launch our personal desktop but keep in mind this is the first time
black adam is logging in so we'll see if our optimizations
work so everything has worked as expected and this is of course just
the beginning you can take this process in any direction you want
you can add applications into your pipeline or other scripts functionality
and then of course repackage everything and continue to
iterate and improve this process so hope you've enjoyed looking
at the azure image builder a way to completely automate
your image pipeline so that you don't ever have to log on to a machine to set
it up again so if you learned something new today go ahead and smash that thumbs
up and let me know that you appreciated our content as well as give me some
comments down below about any questions that you
have or things that you'd like to see us create
for videos going forward we've got plenty more
that we could do around azure devops if you're interested in that or something
else that we haven't covered yet say something like azure synapse or more
on containers you just let me know what you want and i'll get it created
i'm just here to help you learn more about azure and speaking of learning
check out our video at the top right which is our latest video or the
one at the bottom that our youtube machine learning
overlords have picked out just for you thanks very much for joining us today
and we will catch you next time happy learning