Continuous Windows AMI Builds

Has anyone had any luck building out AMIs for .NET platforms at AWS?

Let’s simplify my question:

  1. We have a linux platform. Jenkins sees a change to the code, runs tests, builds an RPM, uploads it to Pulp. That package is managed by Puppet+Foreman. AWS Instances look for a change to that Pulp repo. New package seen, installed, good to go.
  2. We have a .NET platform. Teamcity sees changes, runs tests, etc and builds nuget packages. When we want to release, we create an Windows AWS instance, install octopus deploy tentacle on it, then create a release and deploy it out, then create an AMI from that as version x.y.z.

So now, we want to deploy an ‘environment’ of these 2 nodes. I use cloudformation. Spins up a Linux AMI with some pre-requisites, installs Puppet, gets Foreman/the master to sign it and applies it, good to go. Completely automated.

I’m looking for something as good as that for Windows that requires no intervention. My Idea would be to create a ‘release’ in Teamcity that loads up a Windows AMI, does the octopus thing, then builds the AMI without me having to.

Anyone done anything similar? Anyone done anything not similar that might be useful?


Related discussions:

Interesting, I’d like to know about this too.

ec2Config will execute PowerShell scripts if you put them in UserData surrounded by . You can use that to get things installed/updated, but then it could be a matter of timing to figure out when the instance is ready.

I have UserData set up right now, I was just hoping to do it with as little intervention as possible (was hoping there was a windows container such as Docker).

My thoughts on how to do it when I approach it:

  1. Hit the ‘release’ button on teamcity
  2. Teamcity uses its EC2 setup to launch a windows instance with a known elastic IP.
  3. The tricky part I’m hoping to get some thoughts on: How can Teamcity at this point, get into the AMI instance that was spun up in 2. Possibly something that launches a cloudformation template with parameters.
  4. The Cloudformation template from 3 + UserData would install the tentacle and:
  5. Also unsure about this step: the tentacle needs to be auto-accepted from the Octopus master.
  6. TeamCity/Octopus pushes the NuGet packages into the master
  7. The remaining Powershell is run to do final configurations
  8. Teamcity sees a success, possibly runs some smoke tests
  9. Teamcity builds and AMI (no clue on how to do this with current software)

For 3, I use WinRM - it takes a bit of configuration but once working you can simply use powershell’s Invoke-Command (or any other WinRM client) to have the instance execute any script you would like.

The AWS cmdlets make it easy to spin an instance up, get its address and password, run a script via WinRM (using Invoke-Command + address + password), then stop the instance and take an image.

For automated AMI creation, Packer is your best bet. Creation of Linux AMIs is a snap, though I haven’t done it with windows, I have no reason to expect it would be any more difficult.

Packer supports a number of CFM systems; you can use Puppet Powershell, ETC to build your configs.

I’ll look into this next I think

Definitely, packer ftw

Packer is the best I’ve come up with as well. Here’ a link.
http://www.packer.io/docs/builders/amazon.html

What I’ve got right now:

  • Teamcity runs a Rakefile, which uses the aws-sdk to spin up a windows AMI
    • The windows AMI has a userdata section that gets octopus to accept it with some roles, etc
    • Teamcity then runs an “Octopus Release” step which deploys a version to the windows AMI

What I’m working on for the next few days is the next few steps:

  • Either packer or my own thing will use EC2Config.exe and create an AMI of the box that was bootstrapped via octopus.
    • ???
    • Profit.

After some discovery, turns out Packer won’t work quite yet for me. I’d like to avoid SSH to windows hosts, which is the only way in the latest stable. There’s a PR right now to add WinRM support, but it currently only supports certain builders. Once it’s approved I might look at mimicking the work for the Amazon builder, but until then Packer isn’t quite what I’ll be able to use.

PR: https://github.com/mitchellh/packer/pull/1175