LoginSignup
1
0

More than 3 years have passed since last update.

railsアプリをherokuにデプロイするとき割とつまづいたのでメモ

Last updated at Posted at 2019-02-16

自分用のメモです。

  • macOS
  • brewインストール済み
  • rbenvインストール済み
  • Heroku CLIインストール済み

の前提ですのでご注意ください。


新しいrubyをインストールしてrailsアプリを作成

$ brew update && brew upgrade ruby-build
$ rbenv install 2.6.1
$ gem install bundler
$ gem install rails
(2019/2/16現在、bundler 2.0.1 と rails 5.2.2 がインストールされました)
$ rails new hoge
$ cd hoge
(この後、いろいろ作り込む)

ある程度出来上がったので、デプロイしようとする

$ heroku login
$ heroku git:remote -a heroku側のアプリ名
$ git push heroku master

bundler関係のエラーが出て、デプロイに失敗する

remote: -----> Ruby app detected
remote: 
remote:  !
remote:  !     You must use Bundler 2 or greater with this lockfile.
remote:  !

ローカルのbundlerは2.0.1だが、herokuは対応していないらしい。
↓の記事が非常に参考になった。
https://qiita.com/yoshijbbsk1121/items/87250501b32c6433943e

公式の情報が欲しくて探してみたが、 この記事執筆時点(2019/2/16)ではハッキリした情報は得られなかった。

[追記] 2019/2/19 に bundler2.0.1 に対応したようです。公式にも情報が追加されてました。

仕方がないのでbundlerをダウングレードすることにした。

$ gem install bundler -v 1.17.2
$ gem uninstall bundler -v 2.0.1
$ rm Gemfile.lock
$ bundle install

注)今回は作りたてのアプリだったので、Gemfile.lockを丸ごと消すという荒技を行ったが、本当は BUNDLED WITH の行だけを消すのが良いと思う。

再度デプロイにトライ。しかし、別のエラーがでる。

$ git push heroku master
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        rake aborted!
remote:        Uglifier::Error: Unexpected character '`'
...中略...
remote: 
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.

ES6の機能を使うとプリコンパイルが通らないらしい。
↓の記事が非常に参考になった。
https://qiita.com/Thort/items/18c44604aba65303c221

再度デプロイにトライ。今度は成功!

  • Active Storageの設定がlocalになってるよ、と警告されたけど、とりあえずファイルアップロードする予定ないので無視
  • なんかProcfile作っとけって警告されたけど、今日は疲れたので無視

↓ また今度、元気なときに読みます
https://devcenter.heroku.com/articles/active-storage-on-heroku
https://devcenter.heroku.com/articles/ruby-default-web-server

migrateしてseed投入して終わり!

$ heroku run rake db:migrate
$ heroku run rake db:seed

疲れました。

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