Friday, July 3, 2009

Getting moving with Heroku on Windows

I've been trying to get going with a new Rails app over the past couple of weeks or so, and I'd decided that I wanted to doing a few things differently from my other Rails app. One of them was to use Heroku, because I've read so many raves about it, and about how it 'just works'.

Those 'ravers' must work on *nix machines though, as there are a few hoops to jump through to get Heroku successfully talking to Windows XP.

For starters, I will assume you have the following already installed and running on your Windows box:
  1. Heroku itself
  2. Git and Putty
From the above Git/Putty post, it's not strictly necessary to be connected to Github, to work with Heroku, as Heroku hosts your repository for you as well as your application. However, the concepts for connecting to Heroku through SSH are similar.

Step 1: Store your SSH key
You can generate a new one, or you can use the same one you have generated for Git, but Heroku requires some fairly specific things for this to work. The following assumes you are using PuttyGen to generate your SSH key:
  • Your public key must be stored in a '.ssh' directory in your Windows 'home' directory (ie. something like 'C:/Documents and Settings/Username/.ssh/id_rsa.pub'
  • Note: you can't create the '.ssh' directory using Windows Explorer (explorer won't let you create any directory that begins with a '.'). You must use Git Bash for that.
  • You must cut and paste the 'Public key for pasting into OpenSSH authorized_keys file' into your id_rsa.pub file (replacing the content of the file that you created using 'Save public key'). Otherwise, you will get persistent messages when you try to interact with Heroku, to the effect that you have 'Contents Invalid public key'
Step 2: Get Windows to recognise Heroku as a host
As you may have read for Github in the post referenced above, for each server that you wish to connect your Windows box to, using SSH, you need to have a host key defined in your Windows Registry. This is true for Heroku. If you don't have the appropriate host key, you will see a message something like the following:
"The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is."

To establish Heroku's host key in your Windows Registry:
  1. Open putty
  2. Type 'heroku.com' in the hostname box and click 'Open'
  3. When you see the prompt, 'The server's host key is not cached in the registry...', click 'Yes'
  4. You do not need to log on, and can close putty at this point
After you have followed these two steps, you should have a working connection between your Windows box and Heroku. You do need to remember though, to be running 'pageant' whenever you attempt to connect to Heroku (the same is true of Github).

When you open pageant, click 'Add Key', and select the private key of the key you have stored in your home '.ssh' directory.

After that, you should find that it does 'just work'!

No comments:

Post a Comment