Quick Hits: Gotchas while Deploying a Sinatra App to Heroku

I figured it’d nice to deploy the tutorial Backbone.js app to Heroku.  The tutorial app that we’re building, “Comment on the movies”, has a simple Sinatra backend & Heroku welcomes Rails & Rack-based apps.  Here are the 2 gotchas that I needed to deal with in order to deploy to Heroku:

Gotcha 1 – The .gems file:

The ‘.gems’ file is SUPER important.  Without it, Heroku won’t be able to install the gems that your app needs to function properly ( like…say…Sinatra :) ).  It’s mentioned as a single line in the linked page above, but it’s worth mentioning because it’s easy to miss.

Gotcha 2 – Heroku’s read-only Filesystem:

There are certain files that you shouldn’t put into source control, like an API key from the New York Times (hint, hint).  Historically, I’ve added files like these to the server directly (along with other sensitive keys/data).  While Heroku’s read-only file system doesn’t allow this, it does have a nice solution:  Define sensitive values via the Command Line Interface:

heroku config:add API_KEY=’ABC123′

… and reference them in code like this:

my_key = ENV['API_KEY']

Those are the two VERY simple gotchas I ran into which shouldn’t distract from how awesome Heroku is.  Create your free account and play with it.

In other news, Part 2 of the Backbone.js tutorial series is coming soon.  In fact, the site’s layout was changed to accomodate the code and text for the tutorial.  You can watch the unfinished product evolve on GitHubplay with it on Heroku.

Happy Coding!

Share
This entry was posted in Heroku, Sinatra and tagged , , . Bookmark the permalink.