Closed suzy1031 closed 3 years ago
500 internal server errorを解消するまで 公式見ずに進める
# production.rb
+config.cache_store = :redis_store, servers: ENV['REDIS_URL'], { expires_in: 90.minutes }
# デプロイしたらエラー
Precompiling assets failed.
修正
# production.rb
+Rails.application.config.session_store :redis_store, {
+servers: ENV['REDIS_URL'],
+expire_after: 1.week
+}
Caused by: remote: NameError: uninitialized constant ActionDispatch::Session::RedisStore
```diff
# gemfile
+gem 'redis-actionpack'
参考 uninitialized constant ActionDispatch::Session::RedisStore (NameError)エラーを解消する github
=>デプロイできた サインアップ internal server error
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
redisが動いていない?
initializers/session_store.rb作成
# config/initializers/session_store.rb
if Rails.env.production?
# Production では session_store に Redis を利用する
Rails.application.config.session_store :redis_store, {
servers: ENV['REDIS_URL'],
expire_after: 1.week
}
end
=>デプロイ 500 errorのまま
修正
# production.rb
+Rails.application.config.session_store = :redis_store, 'redis://:pce139369159a42747870f60b254273009a2483e8f464b055c4fb9294e81e43a4@ec2-34-205-120-58.compute-1.amazonaws.com:14259', { expires_in: 90.minutes }
=>デプロイ 500 errorのまま
公式見て進めてみる
heroku addons:create heroku-redis:hobby-dev -a still-dusk-87527
間違ってredisインスタンス2つ作成してしまった =>デプロイ 500 errorのまま
修正
# gemfile
-redis-actionpack
=>デプロイ 500 errorのまま
修正
cors.rb
-origins 'http://localhost:8080', 'http://localhost:3000', 'http://localhost:5000'
+origins 'http://localhost:8080', 'http://localhost:3000', 'http://localhost:5000', 'https://still-dusk-87527.herokuapp.com/'
=>デプロイ 500 errorのまま
そもそもusersテーブルが作成されているか疑問
$ heroku pg:psql -c "\d"
usersテーブルが存在していない リセットしてマイグレート
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
サインアップ・ログインできた!createもできた!
migrateを自動で実行したい試行錯誤
参考 HerokuにDeployしたタイミングでdb:migrateを実行したい github
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-ruby
$ heroku buildpacks:add https://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks
$ heroku config:set DEPLOY_TASKS='db:migrate cache:clear'
デプロイエラー
Don't know how to build task 'cache:clear'
config確認する
$ heroku config
~~省略~~
DEPLOY_TASKS: db:migrate cache:clear
~~省略~~
DEPLOY_TASKを編集
heroku config:set DEPLOY_TASKS="db:migrate"
=>デプロイ通った 参考 [heroku] 環境変数の操作](https://qiita.com/colorrabbit/items/18db3c97734f32ebdfde)
動いているか分からない(古くてメンテンナンスされていない可能性有り)
こっちを試してみる Herokuにデプロイした時に自動でマイグレーションを走らせる 競合しないようようにconfigから削除
heroku config:unset DEPLOY_TASKS
=>デプロイできた デプロイ時にDEPLOY_TASKが無いよって言われている
$ heroku buildpacks
=== still-dusk-87527 Buildpack URLs
1. https://github.com/heroku/heroku-buildpack-ruby
2. heroku/ruby
3. https://github.com/gunpowderlabs/buildpack-ruby-rake-deploy-tasks
bulldpackの全削除
$ heroku buildpacks:clear -a still-dusk-87527
$ heroku buildpacks
still-dusk-87527 has no Buildpack URL set.
# 消えた
ユーザー認証にてRedisを使っている為、HerokuでもRedisを導入したので手順をメモ
ちょっと待つ
アプリにRedisのaddonが追加されたか確認
公式に沿ってredis.rbを作成
変更をプッシュしてデプロイ
URLへアクセス=>動作確認完了
テーブル変更がある度にマイグレートするのは手間なので自動化
参考 rubyでの接続 Herokuにデプロイした時に自動でマイグレーションを走らせる