CICD Pipeline with Azure Stack – Part 4

This is part 4 in a series.  You can find part 1 here , part 2 here, and part 3 here.

First off, let me quell your anticipation.  I got it working!  It was not as straightforward as I might like, but it will work.  If you haven’t already read post three, I would recommend doing so.  The long and short of it is that the build task Azure Resource Group deployment in TFS doesn’t understand the Azure Stack environment.  It doesn’t know how to talk to it, so any build task is going to fail.  One of the engineers at Microsoft suggested I use a PowerShell task to deploy instead, which I did.  That was not as simple as I would have liked, but here is what I had to do. Continue reading “CICD Pipeline with Azure Stack – Part 4”

CICD Pipeline with Azure Stack – Part 3

This is part 3 in a series.  You can find part 1 here and part 2 here.  Part 4 is now available here.

As I mentioned in my previous post, I was “ready” to deploy my TFS deploy template to Azure Stack.  And as predicted, the universe laughed at my funny plans.  The deployment failed due to a required Windows Update on the target image.  I didn’t run into this on Azure b/c the Windows Server 2012R2 image on Azure is more up to date than the one that ships with Azure Stack.  At this point I could have just installed TFS and Visual Studio manually, but no I refuse to give up my dreams of an automated future.  I spent the next week creating a PowerShell script that will install all available, required Windows Updates, and then reboot and repeat until there are no updates left.  Then I ran that script against a Windows Server 2012R2 VM in Azure Stack, and used that updated VM to create an updated VM Image.  You can read all about that adventure here.  Let’s just say that the yak is well and truly shorn. Continue reading “CICD Pipeline with Azure Stack – Part 3”

Updating the Azure Stack 2012R2 Image

If you’ve started playing with Azure Stack, you might notice that the Windows Server 2012R2 image is a little behind on its Windows patches.  Before you do any heavy duty testing, you’re going to want to update the image with the latest patches.  This is a multi-step process:

  1. Deploy an image to update
  2. Install all available Windows Updates (I’ve got a script for that!)
  3. Sysprep the machine to be a new image
  4. Locate the VHD file
  5. Update the image using the portal or PowerShell

I’m not going to walk you through deploying a VM in Azure Stack, but I will recommend that you use the A2 size.  Installing the update should go a little faster on a system with more horsepower.

Using PowerShell to run Windows Update

You could manually update the VM with all the Windows Updates, but why do that when there’s PowerShell?  I’m making use of the Windows Update PowerShell module available on the TechNet gallery.  All you have to do is copy this script from my Gist to the target VM.  Then run it.  The script will download and import the module, install the available Windows Updates, and then create a scheduled task to run again on startup.  It should keep running until there are no updates left.  Fire away and come back in a few hours depending on your internet connection.  It took an A2 VM about four hours to patch when I last ran this.  Glad I didn’t have to babysit it!

Now that your VM is properly patched up, it needs to be prepared for use as an image.  Fortunately, all the necessary settings and VM agent are already installed.  From an administrative command prompt run sysprep:

 

The VM will shutdown when sysprep is complete.  Make sure that you go into the portal and stop it from there, so it is deallocated properly.

The VHD location for the VM will vary depending on the storage account you used.  From within the portal, go to the VM’s Disks

Select the OS disk and then copy the blob URI by clicking on the neat little clipboard icon.  Paste that value into notepad or something similar.

Go into the storage account that was used to store the VHD.  The blob properties of the VHD need to allow anonymous access.  Select the Blob portion of the storage account, and then select the container which houses the vhd (usually vhds).  Change the Access policy to Access type to Blob.

Now we’re going to add a new version of the Windows 2012R2 image.  In the portal select Resource Providers

Select the Compute RP and then click on the VM Images on the far right

Click on the 2012-R2-Datacenter image and copy all the values to notepad

Now click on the Add button and use the previous values to fill out the fields.  Be sure to increment the Version number in.  In my case I went from 1.0.0 to 1.1.0.

Now click the Create button and wait.  Once the creation process is complete, you will have a fully patched Windows Server 2012R2 image to use for your Azure Stack deployments.  My creation time was about an hour, so don’t be surprised when it doesn’t create immediately.

You might wonder what happens with the existing Gallery Item that was using the version 1.0.0 template.  Good question!  The templates for the marketplace are unsurprisingly stored in a storage account in the System.Gallery Resource Group.  If you dig down into the storage account you will find the blob container with the marketplace item here: dev20151001-microsoft-windowsazure-gallery/MicrosoftWindowsServer.WindowsServer-2012-R2-Datacenter.1.0.0

The template that controls deployment is called CreateUIDefinition.json.  And that file doesn’t reference an actual version of the template.  So despite the fact that the Gallery Item description claims that it uses the 1.0.0 version, it should use the latest version (1.1.0 in my case).  I created a new VM to test, and as you can see, no Windows Updates were available.

PS – You can also add an image using PowerShell.  If you’d like to know more about the process, then check here and use the same values you would have in the portal.

Here’s the full PowerShell script if you’re interested:

CICD Pipeline with Azure Stack – Part 2

This is part 2 of an ongoing series on building a CICD pipeline in Azure Stack.  You can find part 1 here, part 3 here, and part 4 here.

When I last left things, I had successfully installed TFS on a virtual machine in Azure.  And I wrote the template in such a way that it could be deployed to Azure Stack as well.  After completing that process, I started working through deploying an ARM template through TFS using an automated build process.  It turns out that the server running the build agent needs to have Visual Studio installed in order to deploy resources to Azure.  I have since updated my ARM template and PowerShell script to automate the installation of Visual Studio Community 2015 and the TFS build agent.  I also updated the template to take two new parameters: FileContainerURL and FileContainerSASToken.  The former points to the blob container that holds the necessary installation files.  The latter passes a SAS Token for read and list access to the blob container.  Continue reading “CICD Pipeline with Azure Stack – Part 2”

CICD Pipeline with Azure Stack – Part 1

This is the first post in a series of getting a CICD pipeline working with Azure Stack.  You can read part 2 here, part 3 here, and part 4 here..  I will add links to additional posts as they are created.

There are a few things that have been coming up a lot lately at work that I would like to dive into some more to get a better understanding.  The first is Infrastructure as Code (IaC).  I’ve started doing my fair share of this in both Azure and AWS, but I feel like I’m just starting to truly get my head around the best practices and patterns to use when deploying IaC.  The next trend is a move towards continuous integration and continuous deployment, CICD.  How can I take the principles of a CICD pipeline and apply them to the IaC work I’ve been doing?  Finally, there is the hybrid cloud element that is coming with Azure Stack.  Unless you’ve been living under a rock, you’ve probably heard about Azure Stack.  If not, here are a couple resources to get you started.  I wanted to put all of those items together and build out a project that uses them.

Continue reading “CICD Pipeline with Azure Stack – Part 1”