LoginSignup
7
6

Heroku - メモ

Last updated at Posted at 2015-08-22

経緯

  • いつも焦るので、落ち着いて対応できるようにメモ。

エラー発生時チェックリスト

まず落ち着いて

  • エラー内容をよく読む
  • 前回からの変更点をリストアップする
  • エラー診断し、手がかりを探す
  • 上記の情報を元にググる

エラー診断

  • heroku logs
  • heroku run console --sandbox

過去のエラー原因

  • バグに気づかず(テストをサボり)
  • モデル間の関連
  • データベース更新忘れ
  • Rubyバージョン変更後、vendor/cacheが悪さをする

過去に成功した対策

Heroku deploy fails ‘Some gems seem to be missing from your vendor/cache directory

  1. git rm -rf vendor/cache
  2. git add ...
  3. git commit ...
  4. git push heroku master

failed to push some refs to 'https://git.heroku.com/my-app.git'

  1. git rm Gemfile.lock
  2. bundle install
  3. git add ...
  4. git commit ...
  5. git push heroku master

スタイルシートがherokuappに反映されていない(devでは問題なし)

特定のgem関連エラー

  • エラー内容をコピペしてググる
  • エラーに関連するgemを更新してみる

スキーマ更新

データ流通量が少ないアプリ

  • Herokuに最新のスキーマを教える
git push heroku master
heroku run rake db:migrate

データ流通量が多いアプリ (maintenance mode)

  • maintenanceモードをonにしてから、Herokuに最新のスキーマを教える
  • 作業が終わったらmaintenanceモードをoffにする
heroku maintenance:on

git push heroku master
heroku run rake db:migrate

heroku maintenance:off

rake db:seedのサンプルデータを使用したい場合

  • 危険: 今あるデータを失うことになるので、実行する前によく考えること
git push heroku master

heroku pg:reset DATABASE

heroku run rake db:migrate && heroku run rake db:seed

herokuapp名称変更

  • heroku rename new-name

注意点: URLが変わるので、それに影響を受けるconfig等を更新するのを忘れないこと。

herokuappを一旦破壊し、作りなおす

  1. 破壊
    heroku apps:destroy --app my-app

  2. 新規作成
    heroku create my-app

  3. プッシュ
    git push heroku -u master

Herokuが対応可能なRubyバージョンを確認

configuration variables, secret keys, etc

config関連の秘密の変数は、ハードコードせず、ENV経由で渡すようにすること

  • dev: gem 'dotenv-rails'等を利用すると便利
  • prod: heroku config:set KEY=value(手作業)

Heroku config variablesについて

資料

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6