February 24, 2012

Below is a simple step by step guide on how to launch a Spree site on Heroku.

This guide assumes you’re using:

  1. OS X

  2. Homebrew for managing packages

  3. RVM for managing local versions of Ruby

  4. Ruby 1.9.3 and Rails 3.2

Ruby

Ruby 1.9.3 is what Heroku’s Cedar Stack requires so get that going:

rvm install 1.9.3

Afterwards reload RVM

rvm reload

Spree

Below are a few of needed items for Spree to run correctly

Install the current version of Spree (1.0.7)

gem install spree -v=1.0.7

Spree defaults to PostgreSQL, so we’ll be using it:

I recommend using the Postgres app from http://postgresapp.com/.

Alternatively you can get it using Homebrew.

brew install postgresql

If you’re installing PostgreSQL for the first time then read the build notes.

Now the gem:

gem install pg

If you don’t already have it, install ImageMagick

brew install imagemagick

Heroku

Install it:

gem install heroku

Also, you’ll need the spree_heroku gem, which enables the use of s3 to store images/assets.

gem install spree_heroku

Here we begin

Create a new rails app using postgreSQL as the default DB:

rails new mySpreeApp -d postgresql

Then navigate into your app directory and configure your settings in config/database.yml

Create the database:

bundle exec rake db:create:all

Install Spree:

spree install

Follow the prompts for the default options to load in the sample data, products, and run the migrations.

Now check if everything installed correctly. Run the application and you should see a sample Spree store with some products.

rails s

At this point install the spree_heroku gem to link our AWS S3 bucket.

gem 'spree_heroku', :git => 'git://github.com/joneslee85/spree-heroku.git'
bundle install

Read the info on joneslee85’s gitHub page to see the configuration options you have for the spree_heroku gem: https://github.com/joneslee85/spree-heroku

Now initiate a Git repo for the application.

git init
git add .
git commit -m "First Commit"

For this guide we’ll be connecting our app and s3 bucket to Heroku directly instead of manually creating an s3.yml in our config folder (read the docs on spree-heroku). You’ll need to create a new Bucket on S3.

Login to Heroku

heroku login

and enter your credentials…

Now create your app on Heroku:

heroku create

This will create a new app on Heroku using a randomly generated name.

Add in S3 credentials.

heroku config:add S3_KEY='YOUR_KEY'
heroku config:add S3_SECRET='YOUR_SECRET_KEY'
heroku config:add S3_BUCKET='YOUR_BUCKET_NAME'

Finally install Spree for the remote heroku instance:

heroku run rails g spree:install

and run

heroku apps:open

Your new Spree store with sample products should now be open in a browser window.

comments powered by Disqus