Heroku部署Ruby 2.6.1:warn_for_outdated_bundler_version

时间:2019-03-21 09:44:09

标签: ruby-on-rails heroku bundler

这个问题与this one有关,但是建议的解决方案对我不起作用。

我正在尝试使用Rails 5.2部署一个Ruby 2.6.1应用程序,但是在部署阶段我仍然遇到此错误:

/app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:95:in `initialize'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:83:in `new'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:83:in `initialize'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:234:in `new'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:234:in `to_definition'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/dsl.rb:13:in `evaluate'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/definition.rb:34:in `build'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler.rb:135:in `definition'
from /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler.rb:101:in `setup'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/bundler/setup.rb:20:in `<top (required)>'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /app/vendor/ruby-2.6.1/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /app/config/boot.rb:3:in `<top (required)>'
from /app/bin/rake:2:in `require_relative'
from /app/bin/rake:2:in `<main>'

我在此错误中发现的奇怪之处是此行:

/app/vendor/bundle/ruby/2.6.0/gems/bundler-2.0.1/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)

Heroku似乎说它正在使用Ruby 2.6.0。但是在构建阶段,它说它将Ruby 2.6.1Bundler 2一起使用:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.1
-----> Installing dependencies using bundler 2.0.1

构建成功,但是部署失败。

这是我的应用程序的配置方式。

Gemfile (简化为重要内容)

ruby "2.6.1"
gem 'rails', '~> 5.2'

Gemfile.lock (简化为重要内容)

RUBY VERSION
   ruby 2.6.1p33

BUNDLED WITH
   2.0.1

在heroku上,我的buildpack是heroku/ruby。我的堆栈是heroku-18

Heroku似乎支持Bundler 2,如this post中所述。

关于部署失败的任何想法?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。问题出在部署时,而不是在构建时。部署使用的是Ruby 2.6.0,因为默认情况下,Heroku的Web dyno:

rails server -p $PORT -e $RAILS_ENV

但是,this post from bundler github告诉每个命令都以bundle exec作为前缀。但是,来自dyno的rails server命令没有前缀。

我发现一种解决方法是修改项目Procfile文件,并添加以下行:

web: bundle exec rails server -p $PORT -e $RAILS_ENV

通过这种方式,rails server命令使用预期的Ruby version,即产生错误的2.6.1的{​​{1}}指令。