Getting Started with AppHarbor

Rick HerrmannAppHarbor (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…

First Things

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.

clip_image002

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.

3-14-2012 11-58-46 PM

 

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.

3-15-2012 1-16-46 AM

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.

 

3-15-2012 12-50-47 AM

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).

 

3-15-2012 12-16-27 AM

 

Go to the Add-Ons page, and select SQL Server. Select the application we want to add the database for (blog_post).

3-15-2012 12-17-41 AM

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.

clip_image014

 

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.

 

3-15-2012 12-38-10 AM

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.

 

3-15-2012 1-01-51 AM

3-15-2012 1-05-29 AM

And that’s it.

Your app runs with no changes. No special worker roles or application settings – it runs as is.

3-15-2012 1-08-11 AM

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).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s