Scott Hanselman

Moving a website to Azure while adding Continuous Deployment from Git

September 21, 2012 Comment on this post [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
Hosting By
Hosted in an Azure App Service
September 21, 2012 4:26
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).
September 21, 2012 4:46
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. :)
September 21, 2012 12:31
@EvilKiru For framework detection in IE, you now have to use javascript and "navigator.userAgent" which returns all framework informations.
September 21, 2012 13:05
Yes, I will need a client-side solution for this. :(
September 21, 2012 20:31
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.
September 21, 2012 21:18
I heard within the next few weeks.
September 22, 2012 3:41
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.
September 22, 2012 3:45
Kevin - Does this help? How to Contribute to an Open Source Project. Do be aware that "master" is moving fast currently.
September 22, 2012 4:13
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.
September 22, 2012 4:54
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.
September 22, 2012 23:29
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
September 22, 2012 23:35
Oops, i meant Scott.. sorry :)
Ron
September 23, 2012 0:47
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?
September 23, 2012 15:26
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?
September 23, 2012 21:25
Martin - Sure, you use "web.config transforms" and the production database connection string goes in web.release.config.
September 24, 2012 2:14
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?
September 24, 2012 22:42
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.
September 25, 2012 14:13
Thans Scott,

This post made me finally explore Git(hub) and Windows Azure. And I can say it just works! http://simplecssgrid.azurewebsite.com.
September 25, 2012 18:17
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.
September 29, 2012 16:16
Great new feature, Would love to get this working with private Git repository.

Thanks for to post Scott!
October 08, 2012 23:25
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
November 01, 2012 0:59
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)
November 01, 2012 10:11
@Martin & @Andrew: please see this page to see how you can avoid pushing secrets in your repo. Also, see this page.
September 24, 2013 20:49
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
November 28, 2013 12:03
Are there any advantages regarding WebDeploy vs. Git Deploy?

Comments are closed.

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