Deploying TWO websites to Windows Azure from one Git Repository
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.
You may have multiple remotes with your git repository, of course:
C:\MyCode>git remote show
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:
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.
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.
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://firstname.lastname@example.org:443/website1.git
C:\MyCode> git remote add azureweb2 https://email@example.com:443/website2.git
C:\MyCode> git remote show
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.
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.
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.
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.
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).
Any plans to include Ruby deployments from Git? We'd like to migrate our RoR apps off Heroku at some point.
Comments are closed.