Production

Setting up production
So you have access to production and want to be able to do releases. Here is the config you need to do to get started.

git remote add production git@heroku.com:growstuff-prod.git

Release process

 * Check that the dev branch is in a good state, and that everything that's been merged into that branch has been accepted by customers on dev/staging.
 * Issue a pull request on github from dev to master, or do the equivalent from the commandline.
 * Merge it or get someone to merge it (use common sense, usually we won't do this without two committers around anyway.)
 * Over in your growstuff directory:

git checkout master git pull upstream master rake


 * Then assuming that all tests pass (and they really should):

heroku maintenance:on --app=growstuff-prod git push production master # db migrations only if needed heroku run rake db:migrate --app=growstuff-prod # run any one-off tasks if needed heroku run script/deploy-tasks.sh --app=growstuff-prod heroku restart --app=growstuff-prod heroku maintenance:off --app=growstuff-prod

Original Heroku production setup
Notes on what we actually did (March 2013).

heroku create growstuff-prod git remote rename heroku production # temporarily set heroku remote to production git config heroku.remote production # this is probably the default but what the heck, let's be explicit heroku config:add RACK_ENV=production RAILS_ENV=production # basic push git push production master heroku run rake db:setup # email setup with mandrill heroku addons:add mandrill heroku addons:open mandrill # get username and API key from mandrill page, feed them into this: heroku config:add MANDRILL_USERNAME=x MANDRILL_APIKEY=x

Then we had to edit config/environments/production.rb to have the same Mandrill setup as staging does. We did this and pushed it up to the production server.

At this point we were able to create accounts on the site, though we had to manually edit the confirmation URL from growstuff.org to growstuff-prod.herokuapp.com.

Heroku addons for various things
# next up, backups! # first we provision a paid database ($9/month) which is needed # if we want automated backups heroku addons:add heroku-postgresql:basic heroku addons | grep POSTGRES # now we do a backup of our old database... heroku maintenance:on heroku addons:add pgbackups heroku pgbackups:capture --expire # and restore to our new database heroku pgbackups:restore HEROKU_POSTGRESQL_MAROON

# now we promote our new database to be the one the app uses heroku pg:promote HEROKU_POSTGRESQL_MAROON heroku maintenance:off # and get rid of the old one heroku addons:remove HEROKU_POSTGRESQL_TEAL # set up automated backups (daily, retained 1 week) heroku addons:add pgbackups:auto-week # run a backup just to test heroku pgbackups:capture --expire # list backups (we'll want to do this again tomorrow to check) heroku pgbackups # now for logging heroku addons:add logentries:tryit heroku addons:open logentries:tryit # didn't really show anything so we should try this again later

We might also want to look into https://addons.heroku.com/papertrail for logging.

Unicorn for performance
Unicorn allows concurrency within a single Heroku dyno, which means better performance. We are following the instructions at https://blog.heroku.com/archives/2013/2/27/unicorn_rails

Other links of potential interest:


 * http://blog.codeship.io/2012/05/06/Unicorn-on-Heroku.html
 * http://stackoverflow.com/questions/9792290/on-heroku-cedar-should-i-use-thin-or-unicorn

Note that unicorn is added *as well as* thin -- we moved thin into the development/test section of the Gemfile, and use unicorn for production/staging now.

And we set up NewRelic to monitor performance:

heroku addons:add newrelic:standard

We needed to make the changes mentioned here: https://devcenter.heroku.com/articles/newrelic#ruby-configuration (mostly just installing the gem and creating config/newrelic.yml -- the unicorn config didn't need tweaking at all.)

To view NR reports:

heroku addons:open newrelic:standard

Set everything back to normal
# finally, set the default heroku remote back to staging git config heroku.remote staging

Notes on performance/caching for future reference
Heroku performance docs: https://devcenter.heroku.com/articles/performance-overview

Caching strategies on Heroku: https://devcenter.heroku.com/articles/caching-strategies

Caching on Rails (Rails Guides): http://guides.rubyonrails.org/caching_with_rails.html