Bundler 部署有时会失败,并显示“源列表已更改”

问题描述 投票:0回答:1

在最近的 ruby/gems 升级后,我在将捆绑程序部署到我们的服务器时遇到了问题。尽管用谷歌搜索了几个小时,我还是不明白发生了什么。

  • bundle install
    像往常一样进行开发,将Gemfile和Gemfile.lock提交到github
  • 从服务器运行部署脚本获取新的github代码,运行bundle install
    ,然后重新启动服务器,所有操作都完美运行。新宝石按其应有的方式加载。
  • 但是通过非交互式 ssh 运行
  • 完全相同部署脚本失败并出现错误:
Bundler::ProductionError: You are trying to install in deployment mode after changing your Gemfile. Run `bundle install` elsewhere and add the updated Gemfile.lock to version control. If this is a development machine, remove the /srv/code/Gemfile freeze by running `bundle config unset deployment`. The list of sources changed
这让我相信 rvm 没有像在非交互式 shell 中那样初始化。

我尝试过的

    将默认rvm版本重置为当前的ruby版本(2.7.8)
  • 在部署脚本顶部运行
  • . /etc/profile.d/rvm.sh
    以正确初始化rvm

更多详情 .bundle/config

BUNDLE_DEPLOYMENT: "true" BUNDLE_PATH: "vendor/bundle" BUNDLE_WITHOUT: "onsite:development:test"
部署脚本

git fetch --all git reset --hard origin/production . /etc/profile.d/rvm.sh /usr/share/rvm/gems/ruby-2.7.8/bin/bundler install
这一切都是在 ruby 升级到 2.7.8 之后发生的。作为升级的一部分,nokogiri gem 也更新至 1.15.4。根据一些建议,我通过 

bundle lock --add-platform x86_64-linux

 将 linux 添加到 Gemfile 平台
我猜这一切都与此有关……也许吧。

Gemfile.lock 包括:

PLATFORMS ruby x86_64-darwin-20 x86_64-linux
我最大的困惑是为什么它在通过 bash 运行时完美运行

ssh [email protected]

/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb

但是当通过非交互方式运行时失败

ssh [email protected] '/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb


供参考: 捆绑器版本 2.4.18 RoR 4.2.11.34(Rails LTS) 红宝石 2.7.8

ruby-on-rails bundler
1个回答
0
投票
您尝试过使用 rbenv 而不是 rvm 吗?我已经看到这对解决其他类似类型的问题有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.