ruby-on-rails Bundler部署有时会失败,并出现“List of sources changed”(源列表已更改)

rjjhvcjd  于 2023-10-21  发布在  Ruby
关注(0)|答案(3)|浏览(188)

在最近的ruby/gems升级后,我在部署到我们的服务器上时遇到了麻烦。尽管谷歌了几个小时,我还是不知道发生了什么。

  • bundle install在开发中像往常一样,提交Gemfile和Gemfile.lock到github
  • 从服务器运行部署脚本**获取新的github代码,运行bundle install,重启服务器,所有这些都运行得很好。新的宝石就像它应该加载。
  • 但是通过非交互式ssh运行完全相同的部署脚本失败,并返回错误:
  1. Bundler::ProductionError: You are trying to install in deployment mode after changing
  2. your Gemfile. Run `bundle install` elsewhere and add the
  3. updated Gemfile.lock to version control.
  4. If this is a development machine, remove the /srv/code/Gemfile freeze
  5. by running `bundle config unset deployment`.
  6. The list of sources changed

这让我相信rvm并没有像在非交互式shell中那样初始化。

我所尝试的

  • 将默认rvm版本重置为当前ruby版本(2.7.8)
  • 在deploy脚本的顶部运行. /etc/profile.d/rvm.sh以正确初始化rvm
    更多详情.bundle/config
  1. BUNDLE_DEPLOYMENT: "true"
  2. BUNDLE_PATH: "vendor/bundle"
  3. BUNDLE_WITHOUT: "onsite:development:test"

部署脚本

  1. git fetch --all
  2. git reset --hard origin/production
  3. . /etc/profile.d/rvm.sh
  4. /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包括:

  1. PLATFORMS
  2. ruby
  3. x86_64-darwin-20
  4. x86_64-linux

我最大的困惑是为什么它在通过bash ssh [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb运行时可以完美地工作
但在通过ssh [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) '/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb非交互式运行时失败
并供参考:Bundler version 2.4.18 RoR 4.2.11.34(Rails LTS)Ruby 2.7.8

fdbelqdn

fdbelqdn1#

你试过用rbenv代替rvm吗?我已经看到这在其他类似的问题上有所帮助。

r7xajy2e

r7xajy2e2#

如果使用非交互式ssh可以正常工作,而使用交互式ssh则失败,那么我的第一个方法是比较两个环境(PATH、gem path、其他变量),看看两个Replayer示例的调用方式是否相同。
看看你的init脚本(.profile、.bash_profile、.bashrc和/etc中的相应文件)并进行比较。也许这样:

  1. # print (non)interactive environment to file
  2. $ ssh user@host "set > noninteractive.txt"
  3. $ ssh user@host
  4. user@host$ set > interactive.txt
  5. user@host$ diff -u interactive.txt noninteractive.txt

也许这会给你一个提示,告诉你去哪里找。可能在这两种情况下RVM环境的设置不同...

klsxnrf1

klsxnrf13#

像往常一样,魔鬼在细节中。很容易修复,一旦你知道要找什么。
我提到我通过以下方式调用bundle install:/usr/share/rvm/gems/ruby-2.7.8/bin/bundler install
事实证明,当通过cron或ssh等调用femteller时,使用gem Package 器是首选方法。简单的解决方法是:/usr/share/rvm/gems/ruby-2.7.8/wrappers/bundler install
我试图找到一个很好的解释差异和什么gem Package 器实际上提供(我认为更明确的路径).但一个简单的路径改变解决了这个问题。

相关问题