20 Mar
2011

Mimicking the AppHarbor Deployment Experience

Category:UncategorizedTag: , , , , :

On Thursday night at NETDUG (the Boise .NET Developer User Group), I demonstrated how to get started with AppHarbor.? I also showed how to mimic the AppHarbor deployment experience.

And thanks to the generosity of the AppHarbor team, we were able to raffle off a Reflector license to one of our attendees!

Getting Started with AppHarbor

You can find many blog posts (and videos) detailing the process of getting started with AppHarbor (see below).? But the basic scenario comes down to these steps*:

  1. Installing and configuring Git. (I use msysgit and Git Extensions.)
  2. Initialize a repository for your application.
  3. Deploy your application to AppHarbor. (If you do not have an AppHarbor account yet, feel free to use this referral link.)

* If you prefer to use Mercurial, follow these steps instead.

If you develop .NET web applications and haven?t tried out AppHarbor yet, do so?Now! I did mention the service is free, right?!?

Mimicking AppHarbor Deployment

Disclaimer: The process I am about to describe is informational and not prescriptive. AppHarbor provides much more value than just deployment, and I do not want to detract from that in any way.

If you have read my previous posts, you know that I use TeamCity and Rake for my build server environment. So I thought I would try to mimic the AppHarbor experience using those tools.

In order to follow along you will need to:

  1. Install Git on your development workstation and build server
  2. Install Ruby on your build server
  3. Install TeamCity on your build server
    * If you need to learn how to install and use TeamCity, I posted a series on TeamCity 4.5.
  4. Install Web Deployment Tool 2.0 on your build server and IIS web server
  5. Start the web deployment service on your IIS web server
  6. * For the purposes of the user group presentation and this post, my development workstation, build server, and web server are all on the same machine.

We need to manually provision much of the infrastructure that would be provided for us automatically by AppHarbor, including:

  • Configure the web application in IIS
  • Set up a bare Git repository
  • Configure TeamCity to watch the bare repository (VCS Settings)
  • Use customize build scripts in TeamCity (Build runner/task)
  • Push your application to the TeamCity repository

Other tasks I will not be considering for this sample include database provisioning and custom configuration variables.

Remember, with AppHarbor, the initial provisioning takes a matter of seconds. With that, let?s get our environment ready.

Configure the web application in IIS
  1. Create a folder on your web server to store the website. (e.g., c:\sites\sample)
  2. In IIS, create a new virtual directory under the default site and set the path to the folder you just created. My virtual path is sample.
  3. Note the IIS application path. Mine is Default Web Site\sample. My url will be http://localhost/sample.
Set up the bare Git repository
  1. Create a folder to store your bare repository. This is the repository TeamCity will watch and use to get code to build. You can create the repository on the build server or on a remote server.? (e.g., c:\repos\sample.git\)
  2. Right-click the folder and run the Git Bash from the context menu
  3. In Git Bash, type git init –bare
Configure the TeamCity build configuration
  1. Create a new project (e.g., Sample)
  2. Create a new build configuration (e.g., Deploy) and name it
  3. Leave all other settings on the first page of the wizard at their default
  4. Attach a new VCS and name it
  5. Select Git as the VCS type
  6. Set the Fetch URL to the bare repository you just created (e.g., c:\repos\sample.git)
  7. Leave all other settings at their default
  8. Add a new build task
  9. Select Rake as the build runner
  10. Select Rakefile content and copy the following into the textbox (Update the site path and project names as appropriate)
    [gist id=878660]
  11. Leave all other settings at their default
  12. On the Build Triggering page, add a new VCS trigger to build on a VCS change.
    Whew! Now that all the infrastructure is in place, let?s do this!
Push your application to your TeamCity repository
  1. Assuming your local Git repository is set up and you?re application is ready to deploy?from Git Bash in your local repo, add your remote repository.? Given the settings described above, I would use the following command: git remote add teamcity /c/repos/sample.git
  2. Then type: git push teamcity master
  3. In less than a minute, TeamCity should start to package and deploy the website.

Using TeamCity for deployment takes markedly longer than AppHarbor. TeamCity uses a polling interval to determine if there are changes; whereas, I assume AppHarbor is using a git post-commit-hook. As an aside, if you haven?t already, start looking into the Web Deployment Tool.

Auto-provisioning and super-fast deployment on an elastic infrastructure?wish I had implemented it first. Winking smile

Update:

A bug was introduced in Visual Studio 2010 SP1 which causes an error when deploying with parameters. You may need to update your Microsoft.Web.Publishing.targets file referenced in the KB article (although I cannot confirm that this fixes the problem, yet).