You kids and your applications today. Back in my day, we published our applications like real men! We didn’t have these fancy, cloud-based services like Heroku and AppHarbor. We couldn’t just type ‘git push origin’ and have our application magically show up online, ready to rock and roll. We used to dread deploying our code because of all the hoops we would have to jump through. Oh, how times have changed!
[more]
In The Old Days…
Back when developers were developers, we worked for our application deployments. We used these horrid web-based “Control Panel” applets to create a virtual directory and application pool for our app, then we used FTP to upload our files. Then we had to scramble and upload a new web.config because we’d inevitably forget to swap out something like a connection string or an SMTP server setting. And because all we could afford was shared hosting, there was no telling when our apps would randomly go offline because of a server glitch or some other mishap. But no more.
Fast-Forward to Today
Things are quite different today. All those tedious, manual (or at best, crudely-scripted) steps I used to do? Gone. How do I deploy an application today? I simply run this command:
git push bitbucket
That’s it. Through technology so awesome it might as well be magic, a few seconds later my code is pulled and compiled, my unit tests are executed, my connection strings are replaced, my SMTP settings are updated, and my app is pushed to production. And all it took from me was a single command. “How is this possible??” you ask? AppHarbor.
AppHarbor in 60 Seconds
AppHarbor is a “Platform as a Service” solution for .NET. It is the bees’ knees.
It really doesn’t take much more than 60 seconds to start taking advantage of AppHarbor for free. Sure, you’ll need to pony up some money if your app grows, but the free service is great for small sites and apps. For example, SpecsFor.com is hosted for free on AppHarbor, as is a new mobile application I’m working on. They have free versions of everything in their extensive add-on library as well, something that Heroku does not have.
Getting an app running on AppHarbor is very simple. Unlike Windows Azure, AppHarbor accepts normal ASP.NET and WebMatrix applications. The only difference between running an app on AppHarbor and a regular instance of IIS is that the file system, like Azure, is not durable. As long as your app is ok with that limitation, you don’t need to take any special steps.
To begin, sign up for an AppHarbor account. This is free and only takes a couple of seconds.
With your account created, you can start creating applications. Create an app, and name it whatever you like. Choose carefully, because your application’s URL will be something like http://[YourAppsName].apphb.com. AppHarbor makes it easy to add your own .com name later if you’d prefer, though.
Next, create your repository at either CodePlex, GitHub, or Bitbucket. If you aren’t using one of those, you can push directly to AppHarbor over git. There are directions for each option on your application’s Getting Started page.
Just follow the straight-forward guides, then push your code to your chosen repository (or directly to AppHarbor if you’re going that route). If you’ve configured everything correctly, you’ll see a build queue up in AppHarbor almost immediately after you commit your code. AppHarbor will compile your code, run your tests, and if all is well, deploy your code.
That’s all there is to it. Well, unless you want to do things like persist data, send E-mails, etc. If you want to do those things, keep reading!
BONUS: Databases and E-mail with AppHarbor
The procedures I’ve covered so far are great for simple things. That’s all there was to setting up SpecsFor.com. For real applications though, you’ll probably want to go further. If you click the “Add-ons” link from your application’s dashboard in AppHarbor, you’ll see a number of services you can easily take advantage of.
At the moment, my yet-to-be-announced mobile app is leveraging SQL Server (Yocto) for storage and Mailgun for sending E-mails.
To take advantage of SQL Server, install the free Yocto add-on, then go to its settings. Here you’ll see connection details for your database, including your connection string. Set an alias for your database add-on’s connection string. This should be the same as the name of the connection string in your web.config file’s connectionStrings section. When AppHarbor is packaging up your code, it will automatically replace that connection string with your add-on’s connection string.
Leveraging Mailgun is even easier. After you install the add-on, the appropriate SMTP settings will be injected into your web.config file automagically. All you have to do is send E-mail using the BCL’s SmtpClient. The Mailgun control panel allows you to monitor messages that are sent, handle responses, and a whole lot more that I still haven’t dug into.
BONUS BONUS: Advanced Build Scenarios
Not every solution is as simple as “MSBuild [solution], run all tests, deploy web app.” What if you have integration tests that you don’t want (or even cannot) run on AppHarbor’s build server? What if you need to perform complex transforms to your web.config file before pushing your app to production? AppHarbor supports both of these scenarios.
By convention, AppHarbor assumes that your repository will contain a single solution file. If it sees more than one solution file, it checks first for a file named AppHarbor.sln. If that doesn’t exist, then it checks for [YourAppName].sln. If it finds either of these, it will use them to build your app. This means you can create an AppHarbor-specific solution file that excludes things like integration tests or projects you don’t want AppHarbor to build.
AppHarbor also fully supports Web.config transformations. Simply add a “Release” transform, and AppHarbor will automatically apply it when it builds your application.
What are you waiting for??
In the old days, if you had an idea for an app, you had to invest at least some money to put it online, and you had to invest the energy to actually deploy your app. That’s not true anymore though. With services like AppHarbor, you can get online with a single commit and no investment. Sure, if the app is popular, you’ll quickly outgrow the free services, but isn’t that a good problem to have? Go try it out today. What do you have to lose?