Chronicling My Ruby on Rails Journey

March 8, 2010

Getting Git to work on Heroku on Windows using Putty / Plink / Pageant

Filed under: rails,ruby rails — Bob Ngu @ 8:44 pm
Tags: ,

Ok, so I have heard from several Rails developers about how much they like Heroku . One reason is that the basic version is free though you are only allowed a max of 5MB for the database. I decided to give it a try in my attempt to migrate off slicehost which I’m currently using.

Boy, I had no idea what I was in for trying to get an app uploaded (not even running yet) to Heroku. I ran into more errors that I can shake a stick at especially since I’m using Putty / Plink / Pageant to handle ssh. First off, I’m new to Git, the word in the open source community is that all the cool kids are using it and in Heroku’s case, it’s not a choice but a necessity, it’s the only way they allow you to upload code to their server.

So off I go to install Git on Windows and the first thing I suggest you do is to read this excellent post on Git on Windows install because trust me, you will be confused with what choices to accept during installation. Here are my choices

  1. Screen 1: Run Git from Windows Command Prompt
  2. Screen 2: Use [Tortoise]Plink
  3. Since I use Putty (not Tortoise), I set GIT_SSH to C:\Program Files\PuTTY\plink.exe, notice no quotes around it.

  4. Screen 3: Use Unix style line endings

Next, I installed a couple of gems

  • gem install rest-client –version 1.3.0
  • It has to be V1.3.0 (latest is V1.4.0) or else “gem install heroku” will barf on you.

  • gem install heroku

Get your Rails app ready, either create a new one or use an existing one. If you are currently using SVN with your app, I suggest you export a fresh copy to a new folder and use that instead because I have no idea if SVN and Git will play nice together in the same app.

Here’s Heroku quickstart guide on deploying an app, it’s written more for Mac / Linux developers though the basic steps are the same.

Follow these steps to get your application added to your local Git repository

  1. change folder to your app root folder
  2. git init
  3. git add .
  4. You might see a a bunch of warning messages about CRLF being replaced by LF, no biggie.

  5. git commit -m “first commit”

Next comes the tricky Putty / Plink / Pageant setup. First off, make sure you have the latest Putty version installed (V0.6), if not, you will get a nondescript error later on

Unable to read from standard input
fatal: The remote end hung up unexpectedly

Now, setup your SSH public/private keys using PuTTYgen, I used SSH-2 RSA. Once the key generation is done, click “Save private key” and save the private key to a folder of your choice, name it something like heroku_key.ppk. You can save the keys with or without a passphrase, it’s up to you, I didn’t. Next comes the public key but don’t click “Save public key”, instead open up notepad, copy and paste the public key string at the top of the PuTTYgen window and save it here

C:\documents and settings\(username)\.ssh\id_rsa.pub

Launch Pageant and add heroku_key.ppk to it. If you wish to auto launch Pageant at startup, you can add this link to Windows startup folder

“C:\Program Files\PuTTY\pageant.exe” “C:\Documents and Settings\(username)\(folder)\heroku_key.ppk” “C:\Documents and Settings\(username)\(folder)\some_other_key.ppk”

Notice that I added 2 keys to pageant upon launch, that’s because I have an existing key pair for slicehost, you only need to add the heroku_key.ppk.

To avoid getting this error when using plink,

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. The server’s rsa2 key fingerprint is: ssh-rsa 2048 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad
Connection abandoned.
fatal: The remote end hung up unexpectedly

Open PuTTY, in the hostname box, enter “heroku.com” and click Open. You’ll receive a prompt “The server’s host key is not cached in the registry”. Click Yes then close Putty (don’t bother trying to log in), Heroku’s host key will now be cached.

Now follow these steps to complete deploying your app to Heroku

  • heroku create
  • git push heroku master
  • heroku rake db:migrate

And you are done and you can thank me later. What a PITA to get it working on Windows but I hope this will save someone the same pain I went through.

About these ads

5 Comments »

  1. Thanks a lot! That solved my problem :)

    Comment by Michael Camilleri — August 27, 2010 @ 1:30 am | Reply

  2. Thank you! This all worked. I already had a Pageant public/private keypair set up, but I generated a new one with PuTTYgen, saved it in the locations equivalent to what you suggested, and it all worked. Thanks!

    Comment by chronoluminaire — September 22, 2010 @ 8:46 am | Reply

  3. Very informative post, thanks. I’m relatively new to RoR and this post clarified a few basic things for me.

    Comment by Alex @ Curve 8530 — March 14, 2011 @ 11:36 pm | Reply

  4. Thanks a lot – very familiar with pagent for PuTTY, but got caught out by the last part when Git Bash kept telling me “connection abandoned”

    Putty login and accept trick worked a treat

    Comment by Turner — April 20, 2011 @ 11:31 pm | Reply

  5. Thank you , it saved my time .

    Comment by Kushal — February 18, 2012 @ 1:23 pm | Reply


RSS feed for comments on this post. TrackBack URI

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

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: