【问题标题】:Can't get bundle exec to work in production无法让 bundle exec 在生产中工作
【发布时间】:2011-11-23 05:16:02
【问题描述】:

我已经在生产环境中安装了我的 gems:

cd /app/releases/current && bundle install --gemfile /app/releases/current/Gemfile --path /app/shared/bundle --deployment --quiet --without development test

我不能 bundle exec 我的任何宝石(rakegem 除外):

$ bundle exec whenever
bundler: command not found: whenever
Install missing gem executables with `bundle install`

gem 已正确安装在 /app/shared/bundle 中:

$ cd /app/shared
$ find . -name whenever
./bundle/ruby/1.9.1/gems/whenever-0.6.8/bin/whenever
./bundle/ruby/1.9.1/gems/whenever-0.6.8/lib/whenever

我的(生成的)包配置(在 /app/current/.bundle/config 中)是:

---
BUNDLE_FROZEN: "1"
BUNDLE_PATH: /app/shared/bundle
BUNDLE_DISABLE_SHARED_GEMS: "1"
BUNDLE_WITHOUT: development:test

我正在运行 ruby​​ 1.9.2p290,手动安装到 /usr/local/bin。

我必须使用--binstubs 选项来bundle install 我的宝石吗?为什么bundle exec 不会搜索存储的BUNDLE_PATH

【问题讨论】:

  • 我遇到了类似的问题,我用bundle install --deployment 解决了这个问题。我不确定为什么会起作用,所以这就是为什么这是评论而不是答案。
  • 我的 capistrano 任务在运行 bundle install 时包含 --deployment 参数。你是这个意思吗?还是您的意思是,删除 --path 参数?
  • 您是在使用 capistrano 还是在进行手动部署?
  • 我正在使用 Capistrano 进行部署,通过要求 bundler/capistrano 使用内置的 Bundler 助手。这就是在我的问题中生成bundle install 命令的原因。
  • bundle show 是否列出了生产中的 whenever gem?

标签: ruby-on-rails rubygems bundler


【解决方案1】:

使用 Capistrano 和 Rails 并使用 deploy.rb 作为部署文件。

我意识到改变require "whenever/capistrano" 出现的顺序真的很重要。我把它放在几乎最后一行:

在 deploy.rb 中:

#first lines:
set :rvm_ruby_string, "1.9.3"
set :rvm_type, :user
set :whenever_command, "bundle exec whenever"

# others...

# last lines
require 'rvm/capistrano'
require 'bundler/capistrano'
require "whenever/capistrano"

after "deploy:update_code", "customs:config"
after "deploy:create_symlink","deploy:create_symlink"
after "deploy", "deploy:cleanup"

load 'deploy/assets'
# end

【讨论】:

  • 这个解决方案让我走上了正轨,但没有像描述的那样工作。在 deploy.rb 的第一行加上 'require "bundler/capistrano"' ,在最后一行加上 'require "whenever/capistrano"' 对我有用。
  • 看来require "bundler/capistrano"应该出现在require "whenever/capistrano之前,这样bundle:install就会出现在whenever:update_crontab之前。请参阅 javan here 的评论
  • 这不相关,但是为什么会有这行呢? after "deploy:create_symlink","deploy:create_symlink"
【解决方案2】:

我遇到了这个问题,并且按照正确的顺序提出了要求,即

require 'rvm/capistrano'
require 'bundler/capistrano'
require 'whenever/capistrano'

它仍然想在 bundle:install 之前运行 crontab 更新。解决方案是用

更新我的本地捆绑器
gem update bundler

之后它又开始工作了。不确定破坏所有这些的版本之间究竟发生了什么变化。

【讨论】:

  • 感谢您提醒您需要更新 LOCAL 捆绑程序。我的所有东西都按正确的顺序排列,并检查了生产服务器以确保它具有最新版本等,但仍然出现错误。一旦我更新了本地捆绑程序,一切正常。正如这个捆绑器问题github.com/javan/whenever/issues/275 捆绑器中所指出的那样,无论何时在处理过程中或制定要使用的正确 capistrano 挂钩。
  • bundler/capistranocapistrano/bundler 有什么区别?我的 Capfile 中有后者。
【解决方案3】:

检查您的 bundle:install 的设置位置,并尝试将其移至 deploy.rb 文件中的 require 'whenever/capistrano' 之上。

这似乎是在我进行捆绑更新时触发的,该更新增加了 Gemfile.lock 中的每当 gem 版本。

看起来每当我的部署文件运行 bundle:install 之前尝试运行它的 chrontab 更新

来自https://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb

before "deploy:finalize_update", "whenever:update_crontab"

我的 deploy.rb 有

after 'deploy:finalize_update', 'bundle:install'

像这个线程中的其他人一样,我尝试了一些事情,但我不确定这是为我解决的问题,但是将 bundle install 更改为 before deploy:finalize_update,并将其设置为上面要求的“之前”无论何时/capistrano' 似乎是我的方案中可能的解决方案。

【讨论】:

    【解决方案4】:

    我认为当 gem 不在您的 Gemfile 中,或者它在您的 Gemfile 的测试或开发部分时

    【讨论】:

    • 感谢您的建议。我的 Gemfile 的主体中有 gem 'whenever'
    【解决方案5】:

    我将--path/app/shared/bundle 更改为vendor/bundle,这样它就可以工作了。

    这对我来说似乎是错误的,所以我删除了 /app/shared/bundlevendor/bundle,并再次将 bundle install 运行到 /app/shared/bundle

    这个干净的bundle install 解决了这个问题。我不知道为什么!

    如果有人对此有解释,我很乐意将您标记为已接受的答案。但这解决了我的问题。

    【讨论】:

      【解决方案6】:

      可能不同的问题会导致相同的错误消息。对我来说,每当 gem 更新以获得角色支持后,我必须更新 capistrano gem。在我升级任何时间之前,bundle exec 一直有效。

      【讨论】:

        【解决方案7】:

        使用brightbox deployment gem,它为我处理捆绑器等(通过魔术,在其他一些食谱中)我发现这很有效:

        替换

        require "whenever/capistrano"
        

        内容为https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v2/hooks.rb 然后修改它以在 bundler:install 完成后加载(你可能有也可能没有那个任务,我不知道它是否是标准的)

        # require "whenever/capistrano"
        # hacked whenever/lib/whenever/capistrano/v2/hooks.rb below to work with brightbox bundler installation
        
        require "whenever/capistrano/v2/recipes"
        
        # Write the new cron jobs near the end.
        after "bundler:install", "whenever:update_crontab"
        # If anything goes wrong, undo.
        after "deploy:rollback", "whenever:update_crontab"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-09-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-02
          相关资源
          最近更新 更多