Mimicking the AppHarbor Deployment Experience
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
- Installing and configuring Git. (I use msysgit and Git Extensions.)
- Initialize a repository for your application.
- 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:
- Install Git on your development workstation and build server
- Install Ruby on your build server
- 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.
- Install Web Deployment Tool 2.0 on your build server and IIS web server
- Start the web deployment service on your IIS web server
* 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
- Create a folder on your web server to store the website. (e.g., c:\sites\sample)
- 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.
- Note the IIS application path. Mine is Default Web Site\sample. My url will be http://localhost/sample.
Set up the bare Git repository
- 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\)
- Right-click the folder and run the Git Bash from the context menu
- In Git Bash, type git init –bare
Configure the TeamCity build configuration
- Create a new project (e.g., Sample)
- Create a new build configuration (e.g., Deploy) and name it
- Leave all other settings on the first page of the wizard at their default
- Attach a new VCS and name it
- Select Git as the VCS type
- Set the Fetch URL to the bare repository you just created (e.g., c:\repos\sample.git)
- Leave all other settings at their default
- Add a new build task
- Select Rake as the build runner
- Select Rakefile content and copy the following into the textbox (Update the site path and project names as appropriate)
- Leave all other settings at their default
- 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
- 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
- Then type: git push teamcity master
- 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.
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).