nologyance.net

日々のアウトプット

Herokuへのデプロイではまった

railsチュートリアルの1.5.2 Herokuにデプロイする(1)でエラーが出力

「heroku create」を実行後、「git push heroku master」でエラーが出力された。

エラーメッセージ

remote:  !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote:                         Detected buildpacks: Ruby,Node.js
remote:                         See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
remote: -----> Ruby app detected
remote:
remote:  !
remote:  !     You must use Bundler 2 or greater with this lockfile.
remote:  !
remote: /tmp/d20190122-151-1o5chpe/bundler-1.15.2/gems/bundler-1.15.2/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)

どうやらBundlerのバージョンが違うらしい。

解決策

Google先生に聞いてみるとBundlerのissueがヒット

https://github.com/bundler/bundler/issues/6784

こちらのコマンドを実行

heroku buildpacks:set https://github.com/bundler/heroku-buildpack-bundler2

Herokuが利用するBundlerのバージョンをセットしているのかな? これで解決!と思い「git push heroku master」を実行すると・・・

今度は別のエラーが出力

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.4.5
remote: -----> Installing dependencies using bundler 2.0.1
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        You are trying to install in deployment mode after changing
remote:        your Gemfile. Run `bundle install` elsewhere and add the
remote:        updated Gemfile.lock to version control.
remote:
remote:        The dependencies in your gemfile changed
remote:
remote:        You have added to the Gemfile:
remote:        * pg (= 0.20.0)
remote:        Bundler Output: You are trying to install in deployment mode after changing
remote:        your Gemfile. Run `bundle install` elsewhere and add the
remote:        updated Gemfile.lock to version control.
remote:
remote:        The dependencies in your gemfile changed
remote:
remote:        You have added to the Gemfile:
remote:        * pg (= 0.20.0)
remote:
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.

bundle installしろと言っているようなので素直に実行 しかし結果は変わらず。

もう一度エラーを読み直してみる

Gemfile.lockを更新したらバージョン管理に反映しろと言ってますね。 そこでgitでコミット&プッシュしてから、もう一度「git push heroku master」を実行するとうまくいきました。