部署期间Capistrano'Bundle Not Found'错误

时间:2011-04-04 16:50:56

标签: ruby-on-rails shell environment-variables capistrano

当我运行cap deploy:update时,我收到以下错误,表示找不到bundle。当我从echo $PATH运行cap shell时,缺少包含捆绑包的/var/lib/gems/1.9.1/bin路径,此路径同时位于/etc/profile~/.bashrc。有谁知道如何解决这个问题?

    [192.168.10.100] executing command
*** [err :: 192.168.10.100] sh:
*** [err :: 192.168.10.100] bundle: not found
*** [err :: 192.168.10.100]
    command finished in 25ms
failed: "sh -c 'bundle install --gemfile /data/www/apps/my_app/releases/201104
04163717/Gemfile --path /data/www/apps/my_apps/shared/bundle --deployment --qui
et --without development test'" on 192.168.10.100

4 个答案:

答案 0 :(得分:29)

要避免此类问题,您应该在两个位置安装最新版本的RVM(目前为1.13.5):本地和远程服务器。

接下来,检查您的deploy.rb是否有

require "rvm/capistrano"
require "bundler/capistrano"

不再需要此行:

$:.unshift(File.expand_path('./lib', ENV['rvm_path']))

希望这会有所帮助

答案 1 :(得分:12)

好的,我最近有过这方面的经验。看起来有几种方法可以解决这个问题。首先,您可以确定实际上远程执行(通过Capistrano)是否与主机本身相混淆。看起来你已经使用Capistrano远程shell完成了这个:

$ cap shell 
  > echo $PATH

好。我敢打赌,当你登录到机器并在那里'echo $ PATH'时,正确的东西出来......在这里也一样。

我找到了两种解决方法:一种是在远程主机的ssh守护程序中启用环境执行。理论上这可行,但我不想问系统管理员是否可以打开它。您基本上编辑ssh配置文件以将'PermitUserEnvironment'设置为'yes'并将所需的环境设置添加到部署用户的〜/ .ssh / environment文件 - 您的系统特定手册页可能比我尝试概括更好

我选择了看似相当hackish的东西,并且缺点是它为你部署应用程序的所有主机都是全局的(所以如果你的ruby / gems位置在不同的主机上不同,这将不起作用) - 但是:我将default_environment设置添加到config / deploy.rb脚本:

set :default_environment, {
    'PATH' => "/usr/local/bin:/bin:/usr/bin:/bin:/<ruby-dir>/bin",
    'GEM_HOME' => '<ruby-dir>/lib/ruby/gems/1.8',
    'GEM_PATH' => '<ruby-dir>lib/ruby/gems/1.8',
    'BUNDLE_PATH' => '<ruby-dir>/lib/ruby/gems/1.8/gems'  
}


AMMENDED: It isn't so 'hackish' if you consider the following:  
  - The environment-specific deploy scripts (deploy/foo.rb) can 
    override the default in deploy.rb  
  - PermitUserEnvironment hides the configuration deep in the 
    .ssh directory of the deploy user; :default_environment at
    least exposes it in the checked-in sources.

这也解决了无法通过Capistrano进行远程耙式任务等问题。请注意,Capistrano宝石,至少我拥有的版本以及以“标准”方式设置我的部署,将宝石安装到/ shared / bundle中 目录,由应用程序获取。我描述的方法需要在默认环境引用的系统目录中使用最小的gem子集,以便远程Capistrano命令可以执行bundle,rake等。

你没有说你是否使用RVM(我的解决方案没有);但是,此解决方案非常接近推荐的RVM解决方案之一。或者,您可以使用'rvm / capistrano'解决方案;在RVM网站上查找RVM Capistrano integration以获取更多详细信息。

答案 2 :(得分:1)

您是否在远程信箱上手动安装了bundler宝石?在此之前,您无法使用bundle命令或安装任何软件包。

答案 3 :(得分:1)

您使用的是RVM吗?

DaneS一些可能的解决方案:

地点

require "bundler/capistrano"
在你的脚本中

,因为bundler现在支持capistrano https://github.com/carlhuda/bundler/blob/1-0-stable/lib/bundler/capistrano.rb

也许

before "deploy:cold", 
    "deploy:install_bundler"

task :install_bundler, :roles => :app do
    run "type -P bundle &>/dev/null || { gem install bundler --no-rdoc --no-ri; }"
end

只有在找不到安装后,才会安装install_bundler任务。