I had a great Spree E-commerce working fine on the localhost – and then I needed to get it onto heroku. Easy right? As someone who has used heroku a few times before (but not for a little while) I remembered it was pretty much a simple case of ‘git push heroku master’. Nope!!
Below is some coverage of what I needed to do. Hopefully it can be of use.
This was using spree branch ‘2-2-stable’ with a postgresql database.
Step 1: Update the web server to unicorn
Add the gem ‘unicorn’ and create a file ‘config/unicorn.rb’. The put the below into the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
- create a Procfile in the root directory
- in the Procfile write:
- create a .env file to hold environment variables and add it to .gitignore!
1 2 3 4 5
- gem install foreman
- foreman start
Now running unicorn! :)
Step 2: Rails App Config Updates
- Remove username from database.yml Production looks like:
1 2 3 4 5 6
- I entered in config/applications.rb
but i read this is outdated and isn’t used anymore
I also changed config/environments/production.rb to
not sure if it did anything
Step 3: Login to heroku
- If haven’t already setup a login to heroku. then login with heroku login
- heroku create
- add postgresql to your app. you can type: heroku addons:add heroku-postgresql but I had to add it within the heroku web interface. add-ons section.
- Then use the user-env-compile from heroku labs labs:enable user-env-compile -a my app
Step 4: Final Deploy
There is currently a known problem with spree and pushing it to heroku. https://github.com/spree/spree/issues/3749; https://github.com/spree/spree/issues/3688 This means using the user-env-compile (point 4) above and pre-compiling assets before pushing to heroku. Some info here: https://devcenter.heroku.com/articles/rails-asset-pipeline Follow the steps below.
- bundle exec rake assets:precompile RAILS_ENV=production
- git add .
- git commit -m “recompiling assets”
- git push origin master
- git push heroku master
- heroku run rake db:migrate —app my-app
- heroku restart —app my-app
Step 5: Setup the admin user
1 2 3