choridonaのITスキル向上日記

ITスキル向上に向け、情報を垂れ流していきます。

Herokuへのデプロイでおきたエラー

どうも。choridonaです。

Ruby on Railsチュートリアルの初期段階で、Herokuへのデプロイがありますが、そこでつまってしまったので、つまった内容と解決方法を共有します。

まず、起こったエラー

$ git push heroku master

を実行したところ、以下のエラーが発生しました。

     $ git push heroku master
    Counting objects: 110, done.
    Compressing objects: 100% (92/92), done.
    Writing objects: 100% (110/110), 146.78 KiB | 3.58 MiB/s, done.
    Total 110 (delta 6), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Building on the Heroku-20 stack
    remote: -----> Determining which buildpack to use for this app
    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: -----> Installing bundler 2.2.33
    remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
    remote: -----> Compiling Ruby/Rails
    remote: -----> Using Ruby version: ruby-2.7.5
    remote: -----> Installing dependencies using bundler 2.2.33
    remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
    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:        If this is a development machine, remove the /tmp/build_64a86e6f/Gemfile freeze 
    remote:        by running ``.
    remote:        
    remote:        The dependencies in your gemfile changed
    remote:        
    remote:        You have added to the Gemfile:
    remote:        * pg (= 1.1.4)
    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:        If this is a development machine, remove the /tmp/build_64a86e6f/Gemfile freeze 
    remote:        by running ``.
    remote:        
    remote:        The dependencies in your gemfile changed
    remote:        
    remote:        You have added to the Gemfile:
    remote:        * pg (= 1.1.4)
    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: !       Push rejected to stormy-plateau-80193.
    remote: 
    To https://git.heroku.com/stormy-plateau-XXXXX.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'https://git.heroku.com/stormy-plateau-XXXXX.git'

 

問題となったのは以下の2点でした。

  1. 「Failed to install gems via Bundler.」
  2. 「You have added to the Gemfile: * pg (= 1.1.4)」
1.「Failed to install gems via Bundler.」について

こちらについては、以下の記事を参考にしました。
ローカルにインストールされているbundleのバージョン(2.2.17)とHerokuのbundleのバージョン(2.2.33)に差異があることで発生していたようです。
※おそらく。。。

yumishin.com

2.「You have added to the Gemfile: * pg (= 1.1.4)」

こちらについて、事前に以下のコマンドを行いました。

$ bundle _2.2.33_ config set --local without 'production'

$ bundle _2.2.33_ install

しかし、「Gemfile.lock」に正常に反映されていなかったようで、Gemの中に「pg (= 1.1.4)」が含まれていたことで発生したエラーのようです。
詳細な原因が分からず。。。
一度、Gemfileの内容から「pg (= 1.1.4)」を削除し、「bundle install」を実施し、再度上記コマンドを実行したところ、問題なく実行することができました。
まだまだ、よくわからないことが多いので、引き続き学習を進めます。。。

本日はここまでです。

 

初めまして、ということで。。。

初めまして。

choridonaと申します。

某メーカー系SE企業からITコンサルに転職することが決まりました。

ITコンサルといいつつ、開発も行うようなので、そこで利用するRuby on RailsAWSの知識を身に着けるということで、ブログやツイッターでつまったところなどを垂れ流していこうかと思います。

後で自分が何に詰まったのかを振り返るようですが、皆さんでも同様のことが起きえるかな、と思うので公開していきます。

取り急ぎ、まずはRuby on Railsチュートリアルから始めていきます。

 

railstutorial.jp


よろしくお願いします。