Skip to content

Latest commit

 

History

History
128 lines (90 loc) · 2.96 KB

cheat-sheet.md

File metadata and controls

128 lines (90 loc) · 2.96 KB

Deployment Cheat Sheet

Table of Contents

  1. Deployment Steps
  2. Debugging
  3. Pushing Changes
  4. Changing Migrations
  5. Switching Heroku Environments
  6. Deleting Heroku Apps

Deployment Steps

  1. After switching to the branch you'd like to deploy, create a new branch for deployment...
 $ git checkout -b deployment
  1. Add the following line to the bottom of your Gemfile to add the rails_12factor dependency to the production environment...
gem 'rails_12factor', group: :production
 $ bundle install
  1. Commit your changes.
 $ git add .
 $ git commit -m "added 12factor"
  1. Create a Heroku app using the Heroku CLI tools...
 $ heroku create my-sweet-app
# wait...
 $ git push heroku deployment:master
 # wait some more...

The first command will both create a new app on your Heroku account and add a remote on your repository named heroku, which points at your deployed Heroku app.

The second command will push from the local branch deployment to the remote branch master on the remote named heroku.

  1. Run migrations and seed on Heroku...
 $ heroku run rails db:migrate
 $ heroku run rails db:seed
 $ heroku open

Heroku automatically detects the database and creates it for you. It is up to you to finish building your application's database, however.

Debugging

Errors associated with deployment will appear here. To view your app's server log...

 $ heroku logs

You can also monitor the log file in your terminal session by passing the following option flag...

 $ heroku logs -t

You can also view the logs in the browser via Heroku's dashboard by visiting https://dashboard.heroku.com/apps/your-app-name/logs

Pushing Changes

 $ git add .
 $ git commit -m "your message"
 $ git push heroku master

Note that this will not update Github. If you want to push your changes to Github as well, you need to run git push origin master as usual.

Changing Migrations

Do not edit an existing migration file. Instead...

 $ rails g migration yourMigrationName
# Edit the new migration file
 $ rails db:migrate
 $ git add .
 $ git commit -m "added migration"
 $ git push heroku master
 $ heroku run rails db:migrate

Switching Heroku Environments

 $ heroku config:set RAILS_ENV=development

To change it back...

 $ heroku config:set RAILS_ENV=production

Deleting Heroku Apps

 $ heroku apps:delete --confirm my-sweet-app

You're likely to end up with a bunch of Heroku apps. To delete all of them at once, you can add this function to your .bash_profile...

function happ(){
  for app in $(heroku apps)
    do heroku apps:delete --confirm $app
  done
}

...and then in bash, run happ from anywhere on your computer; the working directory doesn't matter.