LoginSignup
15
17

More than 5 years have passed since last update.

Herokuエラーメッセージへの対処

Last updated at Posted at 2018-07-24

Herokuにプロジェクト載せてサービス公開で作成したアプリケーションに対して、デプロイ時にエラーメッセージが表示されるので、エラーが消えるように対処してみた。

エラーメッセージ

エラーメッセージ1
remote: ###### WARNING:
remote: 
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.4.4'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
エラーメッセージ2
remote: ###### WARNING:
remote: 
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server

GemにはRubyのバージョン記載をする

エラーメッセージ1への対応だが、これは単純にGemfileに、使用しているRubyのバージョンが記載されてないため表示される。
なので、Gemfileにバージョンを記述してbundle後に再デプロイした。

Gemfile
source "https://rubygems.org"

ruby "2.5.1"
Gem設定→コミット→デプロイまで
bundle

git add Gemfile Gemfile.lock
git commit -m "Write Ruby Version in Gemfile"
git push
git push heroku master

ちなみに、デプロイ時のHerokuではruby 2.4.4で構成されていたようだが
2.5.0で指定してデプロイしても特に問題なかった。
Rubyバージョンが異なる場合はHeroku側でデプロイ時に自動で設定再構築してくれる様子。

https://devcenter.heroku.com/articles/ruby-versions

サーバーの並列処理について

エラーメッセージ2への対応。
Procfileが無いけど?使った方がええんちゃう?」といった感じのメッセージ。Procfileにはサーバーの起動設定や、起動時に実行したいコマンドを記述する。

サーバー初期設定では並列処理できないWEBrickが使用されているので
並列処理を可能にするためには別のWebサーバを利用する必要がある
(下記はpumaを使うための設定例。)

Gemfile
# gemの記載があるか確認。バージョンは任意で
gem 'puma', '~> 3.7'
Procfileをプロジェクトディレクトリ配下に作成
vim Procfile
Procfile
web: bundle exec puma -C config/puma.rb

並列処理に対応するために、下記のファイルを編集(作成)。
rails5系であれば、設定ファイル自体は最初から存在している。
設定しなくても[初期状態でも]一応、動く。

config/puma.rb
# -- 下記コード文の各行を探してそれぞれコメントアウトを外す

 workers ENV.fetch("WEB_CONCURRENCY") { 2 }

 preload_app!


 on_worker_boot do
   ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
 end

あとは、コミット&デプロイしてみて確認。
デプロイ時にエラーメッセージが表示されなくなっているか

Herokuのアプリケーション管理画面からもpumaが有効になっているか確認できる。

スクリーンショット 2018-07-24 23.13.45.png

Deploying Rails Applications with the Puma Web Server | Heroku Dev Center
HerokuのデプロイしたRailsアプリにPumaを導入してみる
Procfile ってどこにある?Procfile の作成からpumaの設定まで
Postgresqlの設定からRailsアプリケーションをherokuで動かすまで⑤
Rails+Herokuで5分でWebアプリ作るおっ( ^ω^)

15
17
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
15
17