Deploying an Azure Project using TFS 2010#

For those few of you left that read my blog, you are probably wondering if I just quit writing.  Well I have been super busy creating Facebook apps that run in Azure.  And these kind of marketing apps that we are doing have marketing deadlines, which are hard to budge.  So that means many late nights and not much time left to write.  I am writing this on the plane now on the way to MIX 2010 where I am speaking on this topic.  I am very excited to be able to speak at MIX.  I am also tired since i am leaving SXSW.  Awesome conference by the way!  Anyway on with the post. :)

So, one of the biggest pains in any development is deployment.  And when it comes to Azure, it is easy to deploy, but still is a very manual process.  Also you need to deploy from your local Visual Studio which can be very problematic.  For instance, lets say you publish your package locally, deploy to staging only to find out that another developer had just checked in a fix and you forgot to get latest before you deployed.  Well since it can take sometimes 15 minutes to deploy to staging because of firing up multiple instances, this can become very painful to have to deploy again right after you just did because of one simple css change or any other change.

So after going through this pain more than once, actually more like 30+ times, I got off of my butt and figured out how to deploy to azure from TFS 2010.  This was a lot of work actually to get to work.  First thing you have to be able to do is build the cloud project on the server. After trying to change the registry, etc to get the Azure targets file to work, I decided just to install visual studio 2010 on the server along with the Azure SDK.  This is the only way I knew that it would actually build. 

So compiling the solution on the server is the first step.  The second step is to actually package the solution so that is can be deployed to Azure.  You have to do this by command line using cspack.  This was also a little tricky as I had to figure out where the path was for the web and worker roles for the cspack to know what to package.  Basically there is a folder called ProjectName.csx where your compiled app is placed when it is built.  Here is the entire package script that is invoked in the TfsBuild.proj file. 

"C:\Program Files\Windows Azure SDK\v1.1\bin\cspack" "C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.Cloud.csx\ServiceDefinition.csdef"


AzureFacebook.Web.dll /role:AzureFacebook.WorkerRole;"C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.Cloud.csx\roles\AzureFacebook.WorkerRole\approot";

AzureFacebook.WorkerRole.dll /out:"C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\AzureFacebook.cspkg"

After it is packed, you need to then deploy it. I took the sample script from here on the azure cmdlets project and then called out to it from the TfsBuild.proj script like this:

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -command C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Sources\AzureFacebook\TfsBuild\deploy.ps1 C:\Builds\1\AzureFacebook\AzureFacebookAzureDeploy\Binaries\Release\ azurefacebook

I wont go through the entire powershell script since it is documented here: Windows Azure Service Management CmdLets , but I will show you what I changed.  First I created some variables that i could pass in from the command line so that I could reuse this script on all of our Azure Projects.

$buildPath = $args[0] 
$servicename = $args[1]
$package = $buildPath + $servicename + ".cspkg"
$config = $buildPath + "ServiceConfiguration.cscfg"
$a = Get-Date
$buildLabel = $a.ToShortDateString() + "-" + $a.ToShortTimeString()

So now when it deploys it will create a label with the date and time it was deployed which is very useful when in Azure so you can see the last time you deployed.

You can download these scripts on our new Project on Codeplex that I worked with Microsoft on called the Facebook Azure ToolkitScott Densmore helped me create this awesome framework that makes it much easier to write apps for Azure.  There are a lot of useful libraries and scripts in that project that have nothing to do with Facebook, but more for Azure.  We are probably going to create another project on Codeplex that is just an Azure Toolkit.  This build script will be more refactored in the future, but wanted to get it out now for those looking to do this now.  More to comeā€¦

Tuesday, March 16, 2010 10:32:30 AM UTC #     |  Trackback



All content © 2014, Jim Zimmerman
New Book
Links to me
On this page
<April 2014>
Blogroll OPML
Favorite Links

Powered by: newtelligence dasBlog 1.9.6264.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail