Skip to content

Deploying to Heroku

mchung edited this page May 11, 2012 · 7 revisions

The following instructions document the changes required to deploy Citizenry on Heroku.

Grab the source

$ git clone git://github.com/reidab/citizenry.git

Update .gitignore

To deploy Citizenry on Heroku, both config/settings.yml and config/database.yml must be present. Delete the entries from .gitignore, rename the sample files, and commit the changes.

# Delete (or comment out) the entries for config/settings.yml and config/database.yml
$ vi .gitignore 

# Rename the sample files
$ mv config/settings-sample.yml config/settings.yml
$ mv config/database-sample.yml config/database.yml

$ git commit -am "Adding settings and database"

Create the Heroku instance

Create To run Citizenry on Heroku, specify a Heroku stack running Ruby 1.8.7

$ heroku create citizenry-demo --stack bamboo-ree-1.8.7

Database setup

Although Citizenry currently works with both MySQL and PostgreSQL, it is generally advised to keep the development and production environments as similar as possible. In other words, please don't use MySQL during development and PostgreSQL in production.

Choose your own adventure.

I want my MySQL

Congratulations, you chose wisely. Add the ClearDB addon and point DATABASE_URL to CLEARDB_DATABASE_URL

# Add the cleardb addon (free MySQL)
$ heroku addons:add cleardb:ignite

# Grab the URL in CLEARDB_DATABASE_URL
$ heroku config | grep CLEARDB_DATABASE_URL

# Update DATABASE_URL with the URL (Note, use mysql*2*)
$ heroku config:add DATABASE_URL='mysql2:/.....'

I want PostgreSQL

Congratulations, you chose wisely. Add in the pg gem, remove mysql2, and update bundler.

# Add pg, remove mysql2
$ vi Gemfile

$ bundle update

Aside: Install PostgreSQL on Mac OS X

The easiest way to install PostgreSQL is with Homebrew (http://mxcl.github.com/homebrew/)

$ brew install postgresql

Alternatively install from the binary: http://www.postgresql.org/

Configure the search engine

Setting up Thinking Sphinx on Heroku is beyond the scope of this article. Citizenry alternatively ships with an option to search with SQL (yes, I know @nz, I know). To remove Thinking Sphinx, remove thinking-sphinx from the Gemfile, and configure config/settings.yml to use SQL instead.

# Remove `thinking-sphinx` gem
$ vi Gemfile

# Set `search: sql`
$ vi config/settings.yml

$ bundle update

Configure Compass

Citizenry uses Compass to emit CSS. To configure Compass for Heroku, update the css_dir variable in config/compass.rb then add a Rack handler to config.ru

Rack handler: use Rack::Static, :urls => ['/stylesheets/compiled'], :root => 'tmp'

# Update `css_dir = "tmp/stylesheets/compiled"`
$ vi config/compass.rb

# Just before `run...` add in the Rack handler (use Rack::Static, :urls => ['/stylesheets/compiled'], :root => 'tmp')
$ vi config.ru

Ship it.

Deploy and run the setup scripts

# Deploy
$ git push heroku master

# Setup database and all that jazz
$ heroku rake db:migrate

Don't forget to update settings.yml

Open Unanswered Questions

Does the SSL certificate path need to be set to something custom?

Hoptoad? Not sure if this is optional, how to disable if so.

Paperclip files need to be stored on external fileserver (we're using S3) -- should add code to detect ENV['S3_KEY']