Scott Hanselman

Deploying TWO websites to Windows Azure from one Git Repository

February 4, '14 Comments [13] Posted in Azure
Sponsored By

Deploying to Windows Azure is very easy from Git. I use the Azure Cross-Platform Command Line (open source on github, written in node) that I get from npm via "npm install azure-cli --g" to make the sites.

When you make a new site with the Azure command line, you'll usually do this:

azure site create --location "West US" MyFirstSite --git

And the tool will not only make the site, but also add a git remote for you, something like https://username@MyFirstSite.scm.azurewebsites.net:443/MyFirstSite.git. When you push to that git remote, Azure deploys the site. You can git push sites with PHP, node, ASP.NET, and Python.

Two Deployments in Azure using Git

You may have multiple remotes with your git repository, of course:

C:\MyCode>git remote show
azure
origin

When you push a folder with code to Azure via Git, unless you're pushing binaries, Azure is going to compile the whole thing for you when it gets pushed. It will restore npm modules or restore NuGet packages, and then build and deploy your app.

If your repository has a lot of .NET projects, you usually only want one project to be the actual deployed website, so you can add a .deployment file to specify which project contains website you're git deploying:

[config]
project = WebProject/MyFirstSiteWebProject.csproj

However, in lieu of a .deployment file, you can also set an application configuration setting with the Azure Portal to to the same thing.

Setting Kudu Projects with Config options

Or, of course, set the configuration values for each site using the Azure Command Line:

c:\MyCode>azure site config add Project=WebProject/MyFirstSiteWebProject.csproj [sitename]

What's nice about setting the "Project" setting via site configuration rather than via a .deployment file is that you can now push the same git repository containing two different web sites to two remote Azure web sites. Each Azure website should have a different project setting and will end up deploying the two different sites.

Git Deploying from one Repo to two separate Azure Web Sites

I do this by setting the git remotes manually like this, using the correct git remote URLs I get from the Azure Portal:

C:\MyCode> git remote add azureweb1 https://scott@website1.scm.azurewebsites.net:443/website1.git
C:\MyCode> git remote add azureweb2 https://scott@website2.scm.azurewebsites.net:443/website2.git
C:\MyCode> git remote show
azureweb1
azureweb2
origin
C:\MyCode> git push azureweb1 master

I have a number of solutions with two or more web sites, or in one case, a web site I want separate from my web api, and I deploy them just like this.

Hope this helps!


Sponsor: Big Thanks to Aspose for sponsoring the blog this week! Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and a host of other file formats in your applications. Curious? Start a free trial today.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Tuesday, February 04, 2014 10:11:52 AM UTC
Nice article...Typically a website will rely on a database of some sort behind it, is there any support for synchronising schema changes with a database project as well?

Regards
Lee
Tuesday, February 04, 2014 11:41:59 AM UTC
Does the deployment have to reference a .csproj or could it reference a directory?

Reason I'm asking: for our nodejs projects we dont have csprojs, but we do have a /deploy dir that contains all the min-ed css/js (a la yeoman).

Currently we copy the /deploy dir out of our "source git" to another dir that has an "azure-only git" and deploy from there.

Being able to just set a directory would be pretty amazing.
Micah
Tuesday, February 04, 2014 11:50:10 AM UTC
The deployment is customizable. By default it just does the build and copy and such to put your site live, but you can provide a custom deployment script to do more than that.

Good post on the topic: http://blog.amitapple.com/post/38418009331/azurewebsitecustomdeploymentpart2/

From my own experimentation, the deployment script is sandboxed and has some limits in what it can do. For instance, if you had some sort of wacky idea about using a combination of PhantomJS, Selenium, and CassiniDev, you're going to get errors when Cassini attempts to grab a port. I'm not sure if it will have network access to execute database or other resource upgrades, but now I'm curious and might have to try it myself.
Tuesday, February 04, 2014 12:07:08 PM UTC
Awesome!
Tuesday, February 04, 2014 12:47:21 PM UTC
In terms of git, are you using git hub, git on visual studio online or something else (like hosting yourself)?
Tuesday, February 04, 2014 6:21:03 PM UTC
Scott,

I was wondering if you can do some kind of SQL Azure Encryption post. I would like to encrypt some data on a SQL Database (Azure) in order to be compliant with the PCI standard. You may know of a link perhaps where I can see this information. (If you used .net 4+ MVC it would be even better).

Thanks
Wednesday, February 05, 2014 1:50:53 AM UTC
Useful, nice tip, thanks!!!
Wednesday, February 05, 2014 1:55:03 AM UTC
Thanks. I used this to answer a SO question. Also, I've been wondering the same thing so thanks for that, too.
Matthew.
Wednesday, February 05, 2014 11:17:59 AM UTC
VERY usefultip, thanks!
Friday, February 07, 2014 4:25:04 PM UTC
Great post Scott. Thanks.
Tuesday, February 11, 2014 1:38:08 PM UTC
thanks very nice
saeed shirzadian
Wednesday, February 12, 2014 5:09:42 AM UTC
Thanks Scott! Should the same apply for Git repositories on VS Online?
Wallace
Friday, April 04, 2014 8:22:15 PM UTC
Hi Scott,

Any plans to include Ruby deployments from Git? We'd like to migrate our RoR apps off Heroku at some point.
Mark Fletcher
Comments are closed.

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