在最近的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)
- 在deploy脚本的顶部运行
. /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]](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
3条答案
按热度按时间fdbelqdn1#
你试过用rbenv代替rvm吗?我已经看到这在其他类似的问题上有所帮助。
r7xajy2e2#
如果使用非交互式ssh可以正常工作,而使用交互式ssh则失败,那么我的第一个方法是比较两个环境(PATH、gem path、其他变量),看看两个Replayer示例的调用方式是否相同。
看看你的init脚本(.profile、.bash_profile、.bashrc和/etc中的相应文件)并进行比较。也许这样:
也许这会给你一个提示,告诉你去哪里找。可能在这两种情况下RVM环境的设置不同...
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 器实际上提供(我认为更明确的路径).但一个简单的路径改变解决了这个问题。