Monday, January 25, 2010

How to build an Azure Cloud Service package as part of your build process

I explained in a previous blog entry how important, and ultimately simple, it is to create a deployment package for SharePoint as a part of your Continuous Integration process and in this post I’d like to show you how to produce deployment packages for Windows Azure.  This article is laid out in the following sections:
  • Deploying to Windows Azure
  • The CSPack Command Line Tool
  • Automating the Creation of your deployment package
Deploying to Windows Azure
Those of you who have deployed solutions to Windows Azure in the past will know the routine.  That is, you must:
  1. Create an account and then login to the Windows Azure portal (this is done through http://azure.com but for the purposes of this article I am going to use the tech preview site).
  2. Create a cloud service project for your account – in the following image I have 3 cloud services in my PDC08 CTP account:

    image
  3. Then click on a Cloud Service project to access the user interface to upload new deployments and toggle them between staging and production:

    image
The packages that you upload into the Cloud Service project is a Cloud Service Package format and is created by an Azure SDK tool called CSPack.exe.  These Cloud Service Packages have a .cspkg file extension and are also built into the Visual Studio tooling so that creation of these packages is all done seamlessly as part of using the Visual Studio tools.  As mentioned in this article, this is as simple as right-clicking on a VS project node and choosing the Publish option.

The CSPack Command Line Tool
CSPack.exe is a tool which comes as part of the Windows Azure SDK and, when installed, it can be found at C:\Program Files\Windows Azure SDK\v1.0\bin\cspack.exe
image
As per the documentation for CSPack, the syntax for using this tool to create a package is:
CSPack <service-definition-file> [options]
And the options that we are interested in are:

Argument
Description
/out: <file | directory>
This option indicates the output format and location for the role binaries.
/role:<rolename>;<role-binaries-directory>;
This option specifies the directory where the binaries for a role reside and the DLL where the entry point of the role is defined. The command line may include one /role option for each role in the service definition file.

And actual sample usage would look something like this:

cspack \ServiceDefinition.csdef 
/role:AmbientPlacesWebRole;\CloudService.WebRole 
/out:AmbientPlaces.cspkg

In this example you can see that we are passing in the path to the .csdef file which describes the definition of our service, including what configuration items that we are specifying.  Next we pass through the directories and names for each role that is specified in our Cloud Service Defnition (.csdef) file.  Finally we can optionally be explicit in specifying the name and location of our outputted Cloud Service Package (.cspkg).

Automating the Creation of your deployment package

Building the solution as part of our automated build process is very similar to what we did when we created our SharePoint deployment package my previous article on the topic:

[SharePointBuildProcess[4].png]

Except that, instead of using WSPBuilder.exe, we would use CSPack.exe in those places.

You can refer to my previous article to see how we did it for SharePoint packages, but for building Cloud Service packages I would refer you instead to the following blog post which does an excellent job of explaining on way to do the same thing from an MS Build script:
http://blogs.msdn.com/domgreen/archive/2009/09/29/deploying-to-the-cloud-as-part-of-your-daily-build.aspx
Another option that is available is to use the Windows Azure PowerShell Cmdlets to customize your deployment process:
http://blogs.msdn.com/chabrook/archive/2009/10/26/azure-powershell-cmdlets-announced.aspx

No comments:

Post a Comment

Post a Comment