Skip to content

Deploying to Heroku For The First Time

Posted on:May 10, 2011

Update: Using a 3rd party gem to manage Heroku apps was premature of me. Just use the Heroku Toolbelt.

I deployed my first Heroku app few months ago. The deployment process was fairly smooth; there were only a couple hiccups. Let’s talk about it.

Got a New Blade

I used Katana to manage my Heroku app. Katana lets me deploy multiple Heroku apps for the project. For example, I want separate staging and production instances.

Adding katana to my project is easy (high-five to Bundler). I edit my Gemfile, adding katana to my :development group:

group :development do
  gem 'katana', '~> 0.1.1'
end

Remember, Katana is just a convenience wrapper around the heroku gem, so we also need to have the heroku gem installed.

After bundle installing, I can initialize the staging heroku app and katana with

$ bundle exec heroku create my-project-name-staging
$ bundle exec kat init my-project-name
$ bundle exec kat staging deploy:setup

I can deploy my new staging instance to heroku with:

$ bundle exec kat staging deploy

Sass in the cloud

After successfully deploying the staging instance of my app onto Heroku, my app’s CSS wasn’t being rendered. The problem is that heroku does not allow local filesystem writes (for the most part), so SASS couldn’t generate its CSS files into public/.

My solution is to use hassle. Hassle is a gem that “compiles the SASS for you into tmp/ and serves it up via a Rack::Static middleware.”

With hassle installed, I also replace my use of stylesheet_link_tag :all in my rails layout, with the exact css file to make hassle happy.

# views/layouts/application.html.haml

# instead of stylesheet_link_tag :all
= stylesheet_link_tag "screen.css"

Up and Running

With a deploy process in place and proper CSS generation. I can code and deploy to heroku with ease. Just commit to my local git repo and call to katana and I’m good:

$ bundle exec kat staging deploy

Cheers.