Masatoshi Nishiguchi

Deploying Rails app to Heroku

This is my memo on Deploying Rails app to Heroku.

About Heroku

Heroku Commands

Heroku config variables

Heroku setup (one time per machine)

Create a Heroku repo for the app

$ git commit -am "Add hello" # Make sure that all changes are committed.
$ heroku create

Before deployment

# Prepare the assets for production.
$ bundle exec rake tmp:cache:clear
$ RAILS_ENV=production bundle exec rake assets:precompile

# Make sure nothing is broken.
$ bundle exec rake test

# Push all the changes to remote repo.
$ git add -A
$ git commit -m "Commit message"
$ git push

Push the app to the Heroku repo

On a production site, with little traffic

$ git push heroku master     # Push up to Heroku repo
$ heroku run rake db:migrate # Inform Heroku of our db schema

On a production site, with significant traffic (maintenance mode)

$ heroku maintenance:on

$ git push heroku master     # Push up to Heroku repo
$ heroku run rake db:migrate # Inform Heroku of our db schema

$ heroku maintenance:off

Deploy the app, and populate the production database with sample users

$ git push heroku master     # Push up to Heroku repo
$ heroku pg:reset DATABASE   # reset the production database

$ heroku run rake db:migrate
$ heroku run rake db:seed

$ heroku restart

Rename the Heroku URL

$ heroku rename <new-name>

Diagnose problems at Heroku

Delete and Redeploy Rails app to heroku

# 1. Destroy the Heroku repo.
$ heroku apps:destroy --app sample_app

# 2. Create a new Heroku repo.
$ heroku create sample_app

# 3. Push the project to the new Heroku repo.
$ git push heroku -u master

Push to a specific app at Heroku

$ heroku git:remote -a falling-wind-1624

Remove build pack

$ heroku config:unset BUILDPACK_URL

Troubleshooting

Reference