Scott Hanselman

Deploying TWO websites to Windows Azure from one Git Repository

February 04, 2014 Comment on this post [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
Hosting By
Hosted in an Azure App Service
February 04, 2014 14:11
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
Lee
February 04, 2014 15:41
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.
February 04, 2014 15:50
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.
February 04, 2014 16:07
Awesome!
February 04, 2014 16:47
In terms of git, are you using git hub, git on visual studio online or something else (like hosting yourself)?
February 04, 2014 22:21
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
February 05, 2014 5:50
Useful, nice tip, thanks!!!
February 05, 2014 5:55
Thanks. I used this to answer a SO question. Also, I've been wondering the same thing so thanks for that, too.
February 05, 2014 15:17
VERY usefultip, thanks!
February 07, 2014 20:25
Great post Scott. Thanks.
February 11, 2014 17:38
thanks very nice
February 12, 2014 9:09
Thanks Scott! Should the same apply for Git repositories on VS Online?
April 05, 2014 0:22
Hi Scott,

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

Comments are closed.

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