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. 

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

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

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"
</PackageCommand>

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:

<DeployCommand>
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
</DeployCommand>

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 #    Comments [6]  |  Trackback

 

Wednesday, May 05, 2010 4:13:46 PM UTC
Every one understands that today's life is very expensive, but some people need money for different issues and not every one gets enough cash. So to get quick credit loans and just credit loan should be good way out.
Monday, May 24, 2010 1:34:11 PM UTC
Can you please provide more details on this subject?? Also your blog is fantastic. Greets
Saturday, June 05, 2010 9:42:46 AM UTC
Valid project. I can't wait for the finished project.
Friday, June 11, 2010 12:03:19 PM UTC
hey buddy,this is one of the best posts that I’ve ever seen; you may include some more ideas in the same theme. I’m still waiting for some interesting thoughts from your side in your next post.
Friday, June 11, 2010 12:03:40 PM UTC
Thanks for the nice post. I am expecting some different idea from your side. You always represent some new thought in your post.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, i, strong, u)  

Enter the code shown (prevents robots):

 

All content © 2010, Jim Zimmerman
Book
New Book
Links to me
On this page
Sponsors
Calendar
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Archives
Tags
Blogroll OPML
Technorati
Favorite Links
Disclaimer

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