Autonomous Machine

Posts tagged with Heroku

Troubleshooting db:push errors on Heroku

Here is the error I was seeing today (truncated for brevity):

$ heroku db:push --app=my-app-name --confirm=my-app-name
Loaded Taps v0.3.23
Auto-detected local database: postgres://localhost/app_development?encoding=utf8

Sending schema
Schema:        100% |==========================================| Time: 00:00:29
Sending indexes
table_1:       100% |==========================================| Time: 00:00:01
schema_migrat: 100% |==========================================| Time: 00:00:00
table_2:       100% |==========================================| Time: 00:00:00
Sending data
20 tables, 2,783 records
table_3:       0% |                                          | ETA:  --:--:--
Saving session to push_201205300813.dat..
!!! Caught Server Exception
HTTP CODE: 500
Taps Server Error: LoadError: no such file to load -- sequel/adapters/
["/app/.bundle/gems/ruby/1.9.1/gems/sequel-3.20.0/lib/sequel/core.rb:249:in `require'", ...

This was caused by my app not having a DATABASE_URL config variable set. I assumed that db:push would fail much earlier if it wasn't able to connect to a database, but this turned out to not be accurate.

The simple solution was to promote the existing database:

$ heroku pg:promote HEROKU_POSTGRESQL_COPPER --app=my-app-name

To find the name of the database to use in the previous command, use heroku config --app=my-app-name. It should have a name like HEROKU_POSTGRESQL_*_URL.

  • May 30, 2012
  • Article
  • Heroku, Taps

Running Ruby 1.9.3 on Heroku Cedar

Heroku now supports specifying a Ruby version in an application's Gemfile:

# Gemfile
ruby '1.9.3'

This requires Bundler 1.2.0, which can be installed with the --pre flag:

gem install bundler --pre

You also need to move 'bin' to the beginning of your application's PATH so the correct Ruby binary is found when starting your web processes:

heroku config:add PATH=bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin --app YOU_APP_NAME

Commit the Gemfile changes and push to Heroku, and your app should be running under Ruby 1.9.3!

  • May 23, 2012
  • Article
  • Heroku, Ruby

SASS and Sinatra on Heroku

Hosting SASS (or any dynamically generated asset) on Heroku can be a challenge, as most of the libraries that generate browser-ready versions of these assets expect to have write access to the filesystem.

There are a variety of libraries that provide asset compiling and caching, and some of these offer ways to do this in a Heroku-friendly way (usually by leveraging Varnish. But sometimes you don't want to install and learn how to use a new asset packaging library just to get a 100 line Sinatra app up and running IN THE CLOUD.

Heroku provides official instructions for using SASS on their platform, but like a lot of their documentation, it is Rails-specific. So here are the official instructions, converted for use with Sinatra (or I imagine, most Rack apps):

require 'sinatra'
require 'sass/plugin/rack'

use Sass::Plugin::Rack

configure :production do
  use Rack::Static,
      urls: ['/stylesheets'],
      root: File.expand_path('../tmp', __FILE__)

  Sass::Plugin.options.merge!(template_location: 'public/stylesheets/sass',
                              css_location: 'tmp/stylesheets')
end

get '/' do
  # your app here
end
  • This assumes that the Sinatra app is in the root directory of the project, and that all SASS files live at public/stylesheets/sass.
  • Don't forget to add public/stylesheets/*.css to .gitignore to help prevent checking generated CSS files into git during development.
  • No files will be served from public/stylesheets in production, so make sure all stylesheets are in the sass directory. For CSS resets and the like, change their extensions to scss and drop them into the sass directory.
  • May 18, 2011
  • Article
  • Heroku, SASS, Sinatra