在最近的 ruby/gems 升级后,我在将捆绑程序部署到我们的服务器时遇到了问题。尽管用谷歌搜索了几个小时,我还是不明白发生了什么。
bundle install
像往常一样进行开发,将Gemfile和Gemfile.lock提交到githubbundle install
,然后重新启动服务器,所有操作都完美运行。新宝石按其应有的方式加载。
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 中那样初始化。
我尝试过的
. /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 运行时完美运行
/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