LoginSignup
1
2

More than 3 years have passed since last update.

【初学者向け】Ruby3.0、Rails6.1.3、MySQLでHerokuデプロイと格闘した話

Last updated at Posted at 2021-03-10

本記事は筆者初投稿でお見苦しい点あると思います!ご了承ください:bow_tone1:
ポートフォリオの基礎機能完成後、herokuデプロイに躓いたため備忘録で記します。

開発環境

  • macOS Mojave 10.14.6
  • Ruby3.0→後に2.7.2にバージョンダウン
  • Rails6.1.3
  • DB MySQL8.0

結論

Rubyのバージョンを3.0→2.7.2に下げ、エラーを解消しながらデプロイ

起こっていたこと

ポートフォリオをherokuデプロイ時にエラーが、、、

terminal

remote: -----> Installing bundler 2.2.11
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.0.0
remote: -----> Installing dependencies using bundler 2.2.11
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Your bundle only supports platforms ["x86_64-darwin-20"] but your local platform
remote:        is x86_64-linux. Add the current platform to the lockfile with `bundle lock
remote:        --add-platform x86_64-linux` and try again.
remote:        Bundler Output: Your bundle only supports platforms ["x86_64-darwin-20"] but your local platform
remote:        is x86_64-linux. Add the current platform to the lockfile with `bundle lock
remote:        --add-platform x86_64-linux` and try again.
remote: 
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
 ---- 以下省略 ----

上記のremote: ! Failed to install gems via Bundler.で調べるとHeroku側とlocalで使用しているBundlerのバージョンにおいてlocal側のバージョンが高いとエラーを吐くという記事を見つけた。そのためBundlerのバージョン確認。

terminal
$ bundle -v
Bundler version 2.2.11

特にバージョンの相違もなくエラー解消には至らない。
$ gem list bundleを見ても他のバージョンは見当たらない。
他記事で成功していたように、Bundlerのバージョンを2.1.4に下げても同じエラーを吐く、、、ここから約1日ググっても有効な情報を見つけられず。

解決へ

Google先生でエラー文をそのまま貼り付け、検索期間を1ヶ月以内に絞り込み記事を漁っていたところstackoverflowに同様のエラーで悩む方が。回答を見ると、、、

Seem you have error in your ruby versions, please check by changing ruby version to 2.7.2 in your Gemfile and install localy same version.

3.0はサポートされていないことが判明。ローカルのバージョン変更、gemを再度bundleし$ git push heroku masterを実行。
※事前に下記の記事を参考にherokuへのアプリ作成とDB設定済。
https://qiita.com/murakami-mm/items/9587e21fc0ed57c803d0

途中でエラーを吐きましたがここも先人の方達の力を借りてクリア。
https://qiita.com/suzy1031/items/64598d44b428ccd7abc5

terminal
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
remote:        /tmp/build_f57de2e7/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3/lib/active_support/message_encryptor.rb:203:in `rescue in _decrypt'
remote:        /tmp/build_f57de2e7/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3/lib/active_support/message_encryptor.rb:180:in `_decrypt'
remote:        /tmp/build_f57de2e7/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3/lib/active_support/message_encryptor.rb:154:in `decrypt_and_verify'
remote:        /tmp/build_f57de2e7/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
remote:        /tmp/build_f57de2e7/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3/lib/active_support/encrypted_file.rb:92:in `decrypt'
remote:        /tmp/build_f57de2e7/vendor/bundle/ruby/2.7.0/gems/activesupport-6.1.3/lib/active_support/encrypted_file.rb:54:in `read'
remote:        /tmp/build_f57de2e
---- 以下省略 ----

上記のエラーをクリアし無事プッシュ完了。
最後に$ heroku run rails db:migrateで無事herokuへデプロイできました!

最後に

Rubyのバージョン自体がエラーの要因だったことから、gemやツールの依存関係、公式のガイドを今まで以上に調べる、「そもそも」を疑うリサーチ能力をより磨いていきたいと感じました!本記事が誰かのお役に立てれば幸いです。ここまで閲覧いただきありがとうございました。

1
2
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
1
2