by Ryan Walker

Moving Rails 3 and MongoDB app to Heroku

It seemed on the surface so easy—I figured it’d take 20-30 minutes. Ended up taking 1.5 hrs, not too horrible.

Add Heroku

First I cd to the project, which is already using git & github.

heroku create --stack bamboo-mri-1.9.2
heroku addons:add mongohq:free

Cleanup gems from beta to release

Cleaned up my Gemfile:

source "http://rubygems.org"
source "http://gems.github.com"

gem "rails"
gem "bson_ext"
gem "mongo_mapper"

gem "haml", "~> 3.0.2"
gem "compass", " ~> 0.10.0", :require => false

App errored because of Heroku read only file system

Googled around, found this post which had a straightforward workaround. I had a static stylesheet related to jquery-ui in my /stylesheets directory, so after some trial and error, I ended up modifying /config/compass.rb:

css_dir = "tmp/stylesheets/compiled"

and added this file: config/initializers/stylesheets.rb

require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))

Sass::Plugin.on_updating_stylesheet do |template, css|
  puts "Compiling #{template} to #{css}"
end

Rails.configuration.middleware.insert_before(
  'Rack::Sendfile', 'Rack::Static',
  :urls => ['/stylesheets/compiled'],
  :root => "#{Rails.root}/tmp")

I also had some cleanup due to a change in format of box-shadow in Compass.

Add custom domain

Finally I just needed to switchover the DNS, and add custom domain to heroku:

heroku addons:add custom_domains
heroku domains:add incentimove.com

All done, and I get to shut down what was supposed to be a short-lived $30/mo. Linode VPS :)

Thanks Lincoln for your helpful blog post and to Heroku and MongoHQ for your kick ass products.


Filed under Heroku MongoDB Rails 3