Monday, April 8, 2013

Windows Azure using git deployment with two different websites in the same repository

Excited about the Windows Azure git deployment feature I decided to give it a try with bitbucket. Wow, talk about dead simple invisible magic deployment, I was very surprised at how easy it was. The only hangup is that the process is only designed to handle a single site deployment, if you have more than one web project and/or solution it's time to roll up your sleeves and read some dudes blog.

The git deployment uses a project called kudu that executes when a deployment is triggered by the git repository service of your choice. The process runs a series of shell commands to script and execute the deployment. While looking for a solution I came across an article that explained how to deploy two sites one nodejs the other mvc4 using a conditional batch file. It is just as easy to use this same method for two or more sites deployments using app setting keys to negate any conditional logic, thus turning your deploy.cmd into one line of sweet deployment victory.

Try it your self using the following steps:

  1. In the windows azure portal select the website you want to include.
  2. Select the configuration tab
  3. Scroll Down to app settings
  4. Use the Key APPLICATION then enter the name of the application you will use this later
  5. Repeat steps 1-4 for the 2nd website you will be deploying
  6. On your local computer open a git prompt:
    npm install azure-cli -g
    You are running windows aren't you, that's ok the git prompt is a little bashful.
  7. This is going to install all kinds of azure magic, go get beverage and come back or stay and watch the console light show
  8. Now from your solution root:
    azure site deploymentscript --aspWAP {Relative Path To Your 1st Project}.csproj -s {Relative Path To Your Solution}.sln
    cp deploy.cmd {Application Name Used in 1st Azure App Settings}.cmd
    azure site deploymentscript --aspWAP {Relative Path To Your 2nd Project}.csproj -s {Relative Path To Your Solution}.sln
    cp deploy.cmd {Application Name Used in 2nd Azure App Settings}.cmd
    
  9. Now edit your deploy.cmd to look like this:
    @ECHO OFF
    %APPLICATION%.cmd
    
    Yes.. it's that easy!
  10. Commit your changes
  11. Check to see if they deployed in the azure portal deployments tab