I have been involved in talks recently about how to automate deployment into a Windows Azure environment, after doing a number of presentations and white papers on the subject. I have decided that my personal preference is that we should not be getting our dev teams to write custom PowerShell, or MSBuild scripts to automate the deployment and instead use out of the box tools that are freely available to do the job instead.
This will get us to the desired result, an automated build process that reliably deploys applications into the cloud independent of the platform and development environment.
The up side of using existing tools / executable are:
- No development required
- Lets you focus on the application not on the deployment
- Tools are developed by SME’s for a specific purpose
- No need to maintain and update in house
- Easy to replace and update with platform changes
- Community supported
- Proven agility on projects (I have used this approach with a number of customers)
So with this in mind I have been able to use a variety of out the box tools to get my Windows Azure build to automate my deployments. The one gotcha at the moment is that there is no simple tool that I have found to upload a package to Azure Storage, this I have developed myself and can be used on multiple projects.
The tools I will be using to deploy into the public cloud for Windows Azure are:
- CSPack – Package application into cspkg to deploy into Windows Azure
- AzureUploader – Custom tool to upload packages to Windows Azure Storage
- CSManage – Call the Azure Service Management API to start / delete deployments
- CSRun – Needed for deployments against the development fabric
If using MSBuild to run your build and deployment you can also use the in built tasks for creating a package, the below code snippet shows the basic outline of the local and cloud targets. The new targets that we create will have to be kicked off “AfterBuild” and then also depend on the CorePublish or CorePacakgeComputeService for creating the deployment package based on the environment (dev fabric or public cloud).
The tokenised outline for the CloudDeployment scenario is:
This shows the process that you will need to go through in order to deploy to the public Windows Azure platform. The command PacakageUploader calls into the AzureUploader tool with the specified command line arguments giving the package we generated (from CorePublish) and the connection string for the storage account.
The next couple of commands Suspend, Delete, Create and Run all then use the CSManage command line tool to call the Service Management API enabling us to deploy and run the application in Windows Azure. You will be able to see that each of these also has the ContinueOnError flag set to true, this is due to a small bug in the tool that gives an incorrect return value when the operations return successfully.
In comparison to deploy against the local dev. fabric you only need to use CSPack (or the MSBuild target) and the CSRun command line tool that allows us to start the dev. fabric with a given package.
As you can see this whole process should be able to be run using any build engine, the only slight alteration is to take out the shortcut I used for packaging the application and use the CSPack command line tool instead.
This approach to build seems to make a lot more sense to me, there is no need to maintain or code any of your own targets to do work when there are perfectly capable tools already released and looked after by domain experts, leaving you to concentrate on your application instead of how to build and deploy it into different environments.
The full build script that I currently run from MSBuild is below, this can be updated and improved further by tokenising all variables so that you can then deploy into multiple environments and accounts.