Sunday, November 21, 2010

Hobo on Heroku

Ok, so I'm toying with a Web application, code named "leapercan" because Leprechaun is not only unavailable as a domain name it is also difficult to spell.

Not that I claim to be especially proficient in Ruby or Rails, but I've been fortunate to help a really crack team of Ruby on Rails programmers for the past couple of months. I'm a dinosaur by comparison, but I'm picking up something along the way.

So I want to try something new, but RubyOnRails based. We've been using Rails 3 with all sorts of gems including RSpec, Steak, and Jasmine, and deploying with Capistrano. I'm looking for a solo app -- Hobo sounds interesting, and a free account on Heroku is an easy way to get started.

Here's what I've done and found so far.

Before anything else, note that I'm hanging back on versions so as to avoid having to deal with bugs at the bleeding-edge. My goal is to explore Hobo and Rails capabilities, not to debug them.

Debugging time is time mostly wasted.  Like an argument with your spouse once you've worked around the disagreement you generally forget why it was a problem in the first place.

First, I use RVM to manage my Ruby versions, but not the gemsets feature. So I install version 1.8.7 and set a .rvmrc up so that my work environment will default to rvm's global gemset for 1.8.7.

cd ~/workspace
mkdir leapercan
echo "rvm use 1.8.7@global" > leapercan/.rvmrc
cd leapercan

RVM now tells me that 1.8.7 is selected. Now, if I had other 1.8.7 apps on this machine, I might use a named gemset instead, to avoid polluting the global space; in that case, I would have used the gemset name instead of "global". Now that I think of it, that probably would have been a better idea...

I confirm it is using the right Ruby. As it happens, my system ruby is also 1.8.7, so I could have avoided the download. I check the version

which ruby


Next, I install the bundler, because it is just easier to list the right gems in a file than to 'member the nitty-gritty details in stream-of-consciousness mode.

gem install bundler

After that, I use my trusty MVIM to edit the Gemfile, and put in the gems we're expecting to use:

source ''

gem 'rails', '2.3.10'
gem 'hobo', '1.0.2'
gem 'heroku', '1.13.7'

I'm a freakin' idiot savant, to have come up with the version numbers, right? Wrong. I used the fact that provides a RESTful interface to look at the all kinds of information about a given gem, and just plugged and chugged until I figured out which versions I could probably use without too much more trouble.  The format I used was , where GEMNAME was one of rails, hobo, and heroku.

Write and quit the Gemfile, and run bundler:

bundle install

Gahk! It complains about

Could not find gem 'rails2.3.10 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
Well, that's not right. I had omitted a comma after the gem name and version number, and bundler just concatenated the two into one string.  I correct the mistake and continue. 

After a while of downloading and installing, you'll end up with a bunch of new gems in your rvm maintained gemset. You can list these with gem:

gem list

*** LOCAL GEMS ***

actionmailer (2.3.10)
actionpack (2.3.10)
activerecord (2.3.10)
activeresource (2.3.10)
activesupport (2.3.10)
bundler (1.0.6)
configuration (1.1.0)
heroku (1.13.7)
hobo (1.0.2)
hobofields (1.0.2)
hobosupport (1.0.2)
json_pure (1.4.6)
launchy (0.3.7)
mime-types (1.16)
rack (1.1.0)
rails (2.3.10)
rake (0.8.7)
rest-client (1.6.1)
will_paginate (2.3.15)

OK. So, by now I've also set up a free account on Heroku, gotten a link to activate the account, and logged in. Heroku says I need to add my public SSH key, so I do:

heroku keys:add

Enter your Heroku credentials.
Password: ********
Uploading ssh public key /Users/mamiano/.ssh/

(Note that I had used earlier used ssh-keygen to create my public and private keys as part of a GitHub account setup. You don't need a GitHub account to use Heroku, just git. Google it if you don't know how.)

You can use "heroku help" to list a quick reference to the commands. I won't repeat them here.

Heroku says I need to set up my working directory as a GIT repository, so I do:

git init
git add .

git commit -m "LeaperCan: gold at the end of the rainbow"
 4 files changed, 63 insertions(+), 0 deletions(-)
 create mode 100644 .bundle/config
 create mode 100644 .rvmrc
 create mode 100644 Gemfile
 create mode 100644 Gemfile.lock

Now we need to tell Heroku about the new application. A helpful blogger has already run into the problem of using a slightly newer version of Rails than is standard on Heroku, and pointed out the command line to use the "bamboo" stack instead, which has my version of Rails on it:

heroku create --stack bamboo-ree-1.8.7 --remote leapercan

Git remote leapercan added

So, at this point, I've gotten myself a live sandbox to play in... I'm ready to actually play with a Hobo application.

To Do: Play play play, edit edit edit, do stuff...

Now suppose we have played enough that we have something to deploy. According to Kiwiluv, it is as simple as doing two steps:

git push leapercan master


heroku rake db:migrate --app heroku-app-name

Unfortunately at the moment my family wants attention and I'm just about out of play time.
Sigh. Rather than forget what I've just done, I take what time I have left and dump it into my blog, along with the references.

Post a Comment