AppHarbor (www.appharbor.com) is a platform-as-a-service for hosting .NET applications. In the .NET space this would be an alternative to using Windows Azure. I am going to walkthrough how to get an MVC web application deployed and running with AppHarbor.
So, assuming you have an application that is ready to deploy…
Setup an account at AppHarbor. It’s free to setup an account and there are free versions of the hosting itself, plus all of the various add-ons.
Create an AppHarbor Application
From Your Applications, select create new application. We will call ours blog_post. A single account can have multiple applications.
Setup the Deployment
AppHarbor has the ability to pull your code directly from several source control services including GitHub, BitBucket, and Codeplex. We will setup the application to pull from GitHub.
On the GitHub site, we go to the Admin section of the repository of the project we are going deploy and select Service Hooks => AppHarbor.
To get the Application Slug and Token, on the AppHarbor site from the main application page, click Build URL. This will copy the URL to the clipboard. The GitHub site explains how to get the Application Slug and Token from the Build URL.
We also need to grant the apphb GitHub user access to our blog_post repository. You can either add apphb as a collaborator, or you can add apphb to a team that has Pull access to the repository. I created a new team called Build with Pull access and added the apphb user to the team.
Add-On a Database
AppHarbor has several different types of add-ons including databases (SQL Server, MongoDB, Raven), email services, and caching. All of them have a free entry level option. We are going to add-on a SQL Server instance (which is free up to 20MB).
Go to the Add-Ons page, and select SQL Server. Select the application we want to add the database for (blog_post).
Once the SQL Server is setup you can get the connection string information by selecting Configuration Variables from the main application page.
By default, AppHarbor will look for a connection string named SQL_CONNECTION_STRING. You can either change your web.config to use that connection string name, or setup an alias name on AppHarbor to use a different connection string name. I’ll setup an alias called BlogContext – which is what is already in my web.config.
Using the connection information, I can connect to the database using SQL Management Studio. There are a variety of tools that can sync the local database to the AppHarbor instance – we will not go through that here.
Deploying the Application
Once AppHarbor is setup to pull from GitHub, all you need to do is git push origin master and that will kick off a build. The configuration can be modified to trigger builds from different branches – but by default it is master. AppHarbor will pull the code from GitHub, build the application, and run all the tests. If the code compiles and the tests pass, the application is deployed. In my experience it can take less than 30 seconds from push to deployed.
And that’s it.
Your app runs with no changes. No special worker roles or application settings – it runs as is.
As your site usage and/or database needs grow you can scale out and pay for additional space. You can also use a specific hostname for $10/month (by default you get yourapp.apphb.com).