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