Scott Hanselman

Moving a website to Azure while adding Continuous Deployment from Git

September 20, '12 Comments [25] Posted in ASP.NET | Azure | Open Source
Sponsored By

I've got this little one page website I wrote a few years ago that attempts to detect the version of the .NET Framework you have and give you a download for the smallest redist you need to get up to date. It's called SmallestDotNet.  It was written and thrown up while watching an hour of TV. Fortunately or unfortunately this little throwaway still gets about 10,000 page views a month. It also has a tiny JSON API that a lot of people have actually embedded into their sites and products.

Additionally, it's starting to break. IE9+ doesn't include .NET Framework details in its HTTP User-Agent. The site isn't setup for .NET 4.5, etc. You get the idea. Plus, it's a pile of if statements and prayer and it's just horrible. Worse yet, it lives in a ZIP file on my hard drive and I drag it into SmartFTP to deploy. Yes, I know, this is all thick with irony.

I took and hour over lunch today to accomplish these basic goals:

  • Get this crap site into source control so others could help fix it
  • Move the site to Azure and off my blog's server
  • Update the site's DNS
  • Setup continuous deployment with Git to Azure
  • Fix the .NET 4
  • Maybe add .NET 4.5 detection
  • Cleanse myself, possibly by reading Programming Pearls

Making a Site in Azure

I use the Azure Command Line Tools (get them with npm install azure). (I did an npm update azure --global to make sure I had the latest.)

I clone my Git Repository, create an Azure site, then make sure my Azure site is setup as a remote. (Soon the remote add will be made automatically when creating an Azure site from within a Git repro)

git clone https://github.com/shanselman/SmallestDotNet.git
azure create site SmallestDotNet

I copied my site in from elsewhere and

git add .
git commit -m "Initial Commit"

Next, I'll associate my Azure site with my GitHub (or CodePlex) repo. I could also deploy from local files, but I like the idea of an auto-deploy since I'll guessing I'll be making lots of changes and this is one less thing to worry about.

From the Deployment tab on the Azure Portal I'll use OAuth to authorize azure with GitHub.

Associate a GitHub Repository

Then...

Authorize Windows Azure?

I'll confirm the repository I'm using:

Setup Publishing and Select the Repository to Publish

This sets up a WebHook plugged into GitHub so it'll notify Azure when a push happens, Azure will deploy.

Now, I'll push my repository to origin.

git push origin master 

Within a second or so of this push, the site automatically updates and is up and running at smallestdotnet.azurewebsites.net. I'll do a custom domain in a second.

Yes, I should probably make a deployment branch. I could have two small Azure sites and then have each represent a deployment from a different branch in Git. Then I could git push staging and git push production.

Animated Gif showing a Deployment slide into the queue

To move the domain name records from my own server to azure, I'll log into my DNSimple account (referral link for a free month!) and create a CNAME that points to my new site.

Creating a CName and an A Record to point to Azure

Back in the Azure Management Portal - about 10 minutes later - I'll click Manage Domains and enter my new CName.

image

I'm also using an A record so read the instructions carefully.  After Azure verifies the CNAME, I return and add the A record. That way I can have not just www. but also the "naked" domain work as well.

I visit the site, and boom. It's there. http://www.smallestdotnet.com/ is on Azure in less than a lunch hour. About 25 minutes, actually. Whew.

Next, I have to fix the horrible code and bugs. Join me and issue a pull request.  ;)

Thanks to Calin Balauru for his help with the code a few months back.

Related Reading: ScottGu on Continuous Deployment in Azure with Git

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
Friday, September 21, 2012 12:26:27 AM UTC
Is one of horrible bugs that it can't actually detect what version of .NET I have installed when I visit the site using IE9?

On this Windows 7 system, I have .NET 4 and the site cannot detect if I have .NET installed (with IE9, FF, and Chrome).

On my Windows Vista laptop I have 3.5 SP1 and the site cannot detect that I have .NET installed (with IE9, FF, and Chrome).
EvilKiru
Friday, September 21, 2012 12:46:38 AM UTC
Despite having been a developer for years, I've only just recently started reading your blog and listening to your podcasts regularly. I'm overwhelmed by how much you manage to produce. :)
Taki
Friday, September 21, 2012 8:31:58 AM UTC
@EvilKiru For framework detection in IE, you now have to use javascript and "navigator.userAgent" which returns all framework informations.
styx31
Friday, September 21, 2012 9:05:47 AM UTC
Yes, I will need a client-side solution for this. :(
Friday, September 21, 2012 4:31:25 PM UTC
I am LOVING the ease of deployment with Azure Web Sites and Git. I have a few sites up already.

My only trouble with Azure right now is that it doesn't yet support .NET 4.5. I am about to dive into developing an API for my app, and had planned to use Web Api, but it requires .NET 4.5 (right?). Any knowledge on when this is going to be available? I know The Gu just said "coming in the weeks ahead", but there's a big difference between 3 weeks and 30 weeks. :-)

I might just use nodejs, still hosted on Azure, but would prefer Web Api.
Friday, September 21, 2012 5:18:31 PM UTC
I heard within the next few weeks.
Friday, September 21, 2012 11:41:47 PM UTC
I know this isn't a 'Git Windows for dummies' but I had the idea to improve on the 'helper' class.

If I want to fork the master branch and then submit my changes, what do I do? If someone can help me out w/ either GitHub for Windows (preferrably) or command line and I'll contribute.
Kevin Whalley
Friday, September 21, 2012 11:45:40 PM UTC
Kevin - Does this help? How to Contribute to an Open Source Project. Do be aware that "master" is moving fast currently.
Saturday, September 22, 2012 12:13:35 AM UTC
I sent a pull request! It's a little behind the curve.

I didn't replace Helper within the page itself till someone tells me I didn't do something brainless in my though process.
Kevin Whalley
Saturday, September 22, 2012 12:54:33 AM UTC
Hi Scott,
I'm try to take bits of this and come up to speed. Just researching Git lately. The most I've done with domains is buy one and point it at my host and forget it. I just read the wiki on CNAME and I get it... except for the screenshot above where you have smallestdotnet.com and www.smallestdotnet.com going to different places. One to a hardcoded IP and the other to Azure.

Whats going on here and how do they both end up in the same place?

Thanks and sorry if this is too far off topic.
Greg
Saturday, September 22, 2012 7:29:21 PM UTC
I got really excited about windows azure when i started playing with it for the first time.
Amazing speed and easy to maintain.

The only problem i had with it at the time was the lack of
support for Virtual Directories..
when i create a website i usualy create another MVC project
for the Administration part and use it as virtual directory.

Cant understand why this feature does not exist in Azure.
Its kind of a deal breaker... unless i find an alternative.

anyway.. Great article Steve
Ron
Saturday, September 22, 2012 7:35:39 PM UTC
Oops, i meant Scott.. sorry :)
Ron
Saturday, September 22, 2012 8:47:46 PM UTC
Greg - I wanted foo.com AND www.foo.com to work. First you setup the www as a CNAME, then wait until it's propagated and works. Then you go back and set up foo.com as an A record. That help?
Sunday, September 23, 2012 11:26:42 AM UTC
Nice article! One question though. In most cases you have some kind of database connection. You most likely don't want the credentials stored on your github project page, but add them during production. Using this GitHub -> Azure integration, is there some easy way to add credentials like like connection strings for example?
Martin
Sunday, September 23, 2012 5:25:09 PM UTC
Martin - Sure, you use "web.config transforms" and the production database connection string goes in web.release.config.
Sunday, September 23, 2012 10:14:39 PM UTC
Scott- Yep I got that part. What threw me was why the A record 168.62.48.183 instead of the Azure site. Reading this wiki I think I understand. Thats your Azure IP orrr, its the name server IP to www.foo.com, so that foo.com redirects to www.foo.com and it all sorts out?
Greg
Monday, September 24, 2012 6:42:53 PM UTC
Greg - foo.com points to the IP, and www.foo.com is a CNAME (alias) for foo.com so there is no redirect. They all effectively point the same IP.
Tuesday, September 25, 2012 10:13:37 AM UTC
Thans Scott,

This post made me finally explore Git(hub) and Windows Azure. And I can say it just works! http://simplecssgrid.azurewebsite.com.
Maarten van der Lee
Tuesday, September 25, 2012 2:17:06 PM UTC
Scott,

Do you have any idea if it's possible to use private repositories on Github for deployment to Azure. For the moment I only can see the public repositories in the Azure interface.
Bart
Saturday, September 29, 2012 12:16:03 PM UTC
Great new feature, Would love to get this working with private Git repository.

Thanks for to post Scott!
Awesome new feature
Monday, October 08, 2012 7:25:53 PM UTC
maybe private repos will get implemented quicker with a little help from the community, so please vote on http://www.mygreatwindowsazureidea.com/forums/34192-windows-azure-feature-voting/suggestions/3241587-add-support-for-private-repositories-for-deploymen
pedro
Wednesday, October 31, 2012 8:59:34 PM UTC
Hi Scott, in a follow-up to your answer concerning "web.config transforms", I watched your Mix 2010 talk on web deployment (which is excellent, thank you :o) in which you say the Web.Release.Config to Web.Config transform is a Publish-time activity, and also that you keep the Web.Release.Config file local [on your local PC].. (~14:40)

So, forgive me, but I think Martin's question still stands - how would one use the Git -> Azure push without having Connection Strings and secrets visible to all in the repository?

Andrew :o)
Thursday, November 01, 2012 6:11:11 AM UTC
@Martin & @Andrew: please see this page to see how you can avoid pushing secrets in your repo. Also, see this page.
David Ebbo
Tuesday, September 24, 2013 4:49:30 PM UTC
Hi Scott, I know it has been a while since you posted this, but are you aware of a way to have the continuous deployments use a non-release config transform? I am running my QA through continuous deployment and I want to use my QA transform and still have a different one for true Prod deploys.

Thanks!
Cameron
Cameron
Thursday, November 28, 2013 8:03:44 AM UTC
Are there any advantages regarding WebDeploy vs. Git Deploy?
Alex
Comments are closed.

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