Sinatra 0.9 on Dreamhost

Published: February 22, 2009

There is lots of good information out there on how to deploy Sinatra apps to Dreamhost but they don’t really cover off the Sinatara 0.9 release which unfortunately depends on a newer version of the Rack gem that dreamhost does not yet have installed. The missing piece of the puzzle was that you can actually override the Rack that Passenger loads by vendoring Rack and requiring it in your file.

require 'rubygems'
require 'vendor/rack/lib/rack'
require 'vendor/sinatra/lib/sinatra'

disable :run

set :app_file, 'yourapp.rb'
set :views,    '/full/path/views'

require 'yourapp'
run Sinatra::Application

Now just to tidy things up and prevent me from having junk in my repository I updated my Capistrano script to gem install Sinatra/Rack and unpack them to /vendor on deploy:setup.

after 'deploy:setup',       'vendor_gems:install_and_unpack'
after 'deploy:update_code', 'vendor_gems:symlink'

namespace :vendor_gems do
  task :install_and_unpack do
    run 'gem install sinatra -v' # Also installs rack 0.9.1
    run "cd #{shared_path}/system && gem unpack rack && mv rack-* rack"
    run "cd #{shared_path}/system && gem unpack sinatra && mv sinatra-* sinatra"

  task :symlink do
    run "mkdir -p #{release_path}/vendor/"
    run "ln -nfs #{shared_path}/system/rack #{release_path}/vendor/rack"
    run "ln -nfs #{shared_path}/system/sinatra #{release_path}/vendor/sinatra"

Now I am a pretty happy camper as my move back to shared hosting seems to be going quite well so far. Thanks Passenger!

PS. If you’re interested in trying Dreamhost you should know that they have a pretty generous affiliate program. You can use my affiliate link or a friends, but either way you should make sure someone benefits from it when you signup.