In the final part of this series I look at automating uploading your app into the Windows Azure Cloud, or as I like to think of it a Do It Yourself AppHarbor, hopefully with no leftover screws😉. The series so for:
- Visual Studio 2010 Workflow
- Automating Your Builds with Nant.Builder
- DIY AppHarbor – Deploying Your Builds onto Windows Azure
Update 08/08/12 – Updated Nant.Builder and links to reflect changes for Azure 1.7 and Azure Powershell Commandlets
1. You’ll hopefully not be surprised to learn you’re going to need a Windows Azure account (there’s a rather stingy 90 day free trial, if you haven’t signed up already). Within your account you’re going to need to set up one Hosted Service where we’ll deploy the app to, and one Storage Account where the package gets uploaded to prior to deployment. If you’re stuggling just Google for help on configuration and setting up Windows Azure, there’s plenty of good guides out there.
2. You’ll also need to install the .net Windows Azure SDK v1.7. Again I’ll assume you know how to add and configure an Azure project to your solution.
3. Finally, you need to download the Windows Azure Powershell Cmdlets. This will be installed automatically using Web Platform Installer. Follow the Getting Started instructions here to ensure it was successfully installed. You can get a list of available commands, here.
Getting Started – Importing your Azure Credentials
- You’re going to need to download your Azure credentials, so Nant.Builder can contact Azure on your behalf. We can do this by clicking here:
- You should now have file called <your-sub>-<date>-credentials.publishsettings
- Unhelpfully you can’t seem to rename the file on the portal to make it more meaningful
- If you open the file you’ll see it’s an XML file containing your subscription details.
- IMPORTANT– if you have multiple azure subscriptions you’ll need to edit the file so that it only includes the one subscription that you want to deploy your app into.
- With the file downloaded open powershell and run the following commands, note you’ll need to change the path and filename to your .publishsettings file:
- If the above command run successfully you should have an xml containing your subscriptionId and thumbprint in c:\dev\tools\windowsazure\subscriptions
- ** REALLY IMPORTANT** – The subscription xml file is basically the keys to your Azure account, so you DO NOT want to be casually emailing it around, take it to the pub etc. Ensure you save it behind a firewall etc etc.
- OK that’s us got our Azure credentials organised, next we can configure Nant.Builder
Configure Nant.Builder for Azure Deployment
Packaging your solution for Azure
- Install and configure Nant.Builder as described in Part 2 of this series.
- Open the Nant.build file and navigate to the Azure Settings section.
- Set the create.azure.package parameter to true, this will call CSPack to package your solution in a format suitable for deployment to Windows Azure. If you’re interested in what’s happening here I’ve talked about CSPack in depth here and here
- Set the azure.project.name parameter to the name of the Azure project in your solution.
- Set the azure.role.project.name parameter to the name of the project which contains the entrypoint to your app. This will most likely be the Web project containing your MVC views etc.
- Finally set the azure.service.config.file parameter to the name of the *.cscfg file containing the Azure config you want to deploy. The default is *.cloud.cscfg but may be different if you have a test config, live config etc.
- You can run Nant.Builder now and your solution should be packaged and output in C:\dev\releases\<your-solution-name>
Deploying your solution to Azure
- If packaging has succeeded, you can now finally automate deployment to Azure. Navigate to the Azure deployment section within Nant.Build
- Set the deploy.azure.package parameter to true
- Set the azure.subscription.credentials.file parameter to the name of the the file you created in the Import your Azure Credentials section above, ie C:\dev\tools\WindowsAzure\Subscriptions\yourSubscription.xml
- Set the azure.hosted.service.name parameter to the name of the hosted service you want to deploy your app into. IMPORTANT – be aware that this is the name listed as the DNS Prefix not the actual service name
- Set the azure.deployment.environment parameter to the environment type you wish to deploy your app into. Valid values are either staging or production
- Finally set the azure.storage.account.name parameter to the name of the storage account you set up earlier, this is where the app will be uploaded to temporarily when it’s being deployed.
- That’s it we should now be ready to test our DIY App Harbor. Your Azure Config section should look similar to this, obviously with your app details replaced:
<!--Azure Settings--> <!-- Packaging --> <!--The name of the project containing the Azure csdef, cscfg files--> <!-- This is the name of the project containing your app entry point, probably the Web project, but may be a library if using a worker role--> <!-- The name of the file containing the azure config for your app, default is .Cloud but may be custom if you have multiple configs, eg test, live etc --> <!-- Deployment --> <!-- The name of the file containing your exported subcription details - IMPORTANT keep this file safe as it contains very sensitive credentials about your Azure sub --> <!-- The name of a azure hosted service where you want to deploy your app--> <!-- The environment type either Staging or Production--> <!-- The name of a storage account that exists on your subscription, this will be used to temporarily load your app into while it's being deploed-->
One Click Deployment
So we have hopefully achieved the dream of all modern developers being able to deploy our app into the cloud with one click. If it’s successful you should see something similar to
DeployAzurePackage: [exec] 27/05/2012 22:54 - Azure Cloud App deploy script started. [exec] 27/05/2012 22:54 - Preparing deployment of ContinuousDeploy to your service [exec] or inception with Subscription ID your subid [exec] 27/05/2012 22:54 - Creating New Deployment: In progress [exec] 27/05/2012 22:56 - Creating New Deployment: Succeeded, Deployment ID [exec] 27/05/2012 22:56 - Starting Instances: In progress [exec] 27/05/2012 22:56 - Starting Instance 'Nant.Builder.Sample.Web_IN_0': Stopped [exec] 27/05/2012 22:57 - Starting Instance 'Nant.Builder.Sample.Web_IN_0': Initializing [exec] 27/05/2012 23:00 - Starting Instance 'Nant.Builder.Sample.Web_IN_0': Busy [exec] 27/05/2012 23:01 - Starting Instance 'Nant.Builder.Sample.Web_IN_0': Ready [exec] 27/05/2012 23:01 - Starting Instances: Succeeded [exec] 27/05/2012 23:01 - Created Cloud App with URL http://xxx [exec] 27/05/2012 23:01 - Azure Cloud App deploy script finished. BUILD SUCCEEDED
Note – You are better to run Nant from the command line to see the above output, as the powershell script that deploys your build echos progress to the command line, but not to Visual Studio, if you are running Nant as an external tool
I’ve created a sample project on GitHub that shows Nunit.Builder integrated into it, so it should be more obvious how it all wires up. Download Nant.Builder.Sample here
I hope you’ve found the series useful, and that you benefit from turbo-charging your workflow. Over the next month I’m going to refactor Nant.Builder to be a bit more modular, so it will be easy for other to extend the platform with different targets. Stay tuned for further exiting announcements