The ramblings of Eric Seijo - Software Developer / Life Hacker

Installing Refinery CMS on Heroku

Posted by Eric Seijo Wed, 02 Dec 2009 04:16:00 GMT

I've been using Refinery CMS on some client projects and am really enjoying working with it. Every aspect of the CMS is able to be overridden and customized.

Recently I've been using Heroku as a host for my Ruby on Rails applications and let me just say that they ROCK!  The customer service is great, the performance is awesome and as of this writing they have over 40,000 apps running. There are some constraints to their service however, the biggest for me is the read only filesystem. This is easily to overcome using Amazon S3 but you have to get your clients to sign up for it first and or use your own account.

Here are the steps I take to get everything setup and working.  Most of these steps are taken from Ryan Wood's great post. I highly recommend reading it.

Setup Amazon S3:


Get set up with Amazon S3 and create a bucket for your project.

Configure the config/amazon_s3.yml file and include your bucket name, access key and secret key as follows:

production: bucket_name:
  access_key_id:
  secret_access_key:
  distribution_domain: XXXX.cloudfront.net

Override Refinery Code:


Override Refinery plugin code so that future framework updates do not break your Heroku configuration.  You have to do this because of the read only filesystem.

Run the following:

mkdir -p app/models
cp vendor/plugins/images/app/models/image.rb app/models
cp vendor/plugins/inquiries/app/models/inquiry.rb app/models
cp vendor/plugins/news/app/models/news_item.rb app/models
cp vendor/plugins/pages/app/models/page.rb app/models
cp vendor/plugins/resources/app/models/resource.rb app/models  

 

Override Images and Resources to use S3: 

Change the has_attachment section in app/models/image.rb to this:

has_attachment :content_type => :image,
                               :storage => :s3,
                               :processor => 'Rmagick',
                               :thumbnails => ((RefinerySetting.find_or_set(:image_thumbnails, Hash.new)) rescue Hash.new),
                               :max_size => 5.megabytes

 

 Change the has_attachment section in app/models/image.rb to this:

  has_attachment  :storage => :s3,
                              :size => 0.kilobytes..50.megabytes

Update the search index location options adding in the following key pair to the hash: 

 

:index_file => [RAILS_ROOT,"tmp","index"]

You will need to add this to each file in app/models for example in app/models/image.rb it should look like this:

 

acts_as_indexed :fields => [:title], :index_file => [RAILS_ROOT,"tmp","index"] 

 

Create a .gems file:


Create a .gems file in the root directory. This file is required by Heroku in order to install gems which your application needs that are not installed on their servers already.

Add the following to the .gems file:

unicode

 

Heroku Setup:


For details checkout Heroku's great documentation.

Make sure you have the Heroku gem installed on your system and you have an account set up. More info here.

Make sure you have git installed on your system and a git repository set up for your Refinery CMS project.

To initialize git run:

$ git init

 

Create your application on Heroku:

$ heroku create 

 

Push your application to Heroku:

$ git push heroku master

 

Create your Refinery CMS database schema on Heroku:

$ heroku rake db:schema:load

 

Run any migrations:

$ heroku rake db:migrate 

 

 Seed the database:

$ heroku rake db:seed

 

Go to your created site on Heroku and get started!