Moving a website to Azure while adding Continuous Deployment from Git
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
crapsite 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.
I'll confirm the repository I'm using:
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.
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.
Back in the Azure Management Portal - about 10 minutes later - I'll click Manage Domains and enter my new CName.
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
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.
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.
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.
I didn't replace Helper within the page itself till someone tells me I didn't do something brainless in my though process.
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.
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
This post made me finally explore Git(hub) and Windows Azure. And I can say it just works! http://simplecssgrid.azurewebsite.com.
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.
Thanks for to post Scott!
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?
Comments are closed.
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).