Capistrano 捆绑器:安装失败

Posted

技术标签:

【中文标题】Capistrano 捆绑器:安装失败【英文标题】:Capistrano bundler:install fails 【发布时间】:2013-10-25 14:46:25 【问题描述】:

我正在尝试使用 Capistrano 3.0 将我的 rails 应用程序部署到 EC2 实例中。我现在与运行“cap production deploy”或“cap production bundler:install”时出现的以下输出堆叠在一起。

DEBUG [5b379979] Running /usr/bin/env if test ! -d /var/www/app/current; then echo "Directory does not exist '/var/www/app/current'" 1>&2; false; fi on ec2-75-101-200-185.compute-1.amazonaws.com
DEBUG [5b379979] Command: if test ! -d /var/www/app/current; then echo "Directory does not exist '/var/www/app/current'" 1>&2; false; fi
DEBUG [5b379979] Finished in 2.285 seconds command successful.
 INFO [f15c9f08] Running /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/billtune/shared/bin --without development test on ec2-75-101-200-185.compute-1.amazonaws.com
DEBUG [f15c9f08] Command: cd /var/www/app/current && /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/app/shared/bin --without development test
DEBUG [f15c9f08]    /usr/bin/env: 
DEBUG [f15c9f08]    bundle
DEBUG [f15c9f08]    : No such file or directory
DEBUG [f15c9f08]    
cap aborted!
bundle stdout: Nothing written
bundle stderr: Nothing written
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/command.rb:94:in `exit_status='
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:147:in `block (2 levels) in _execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:149:in `block in _execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:20:in `block (4 levels) in <top (required)>'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/abstract.rb:81:in `within'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:19:in `block (3 levels) in <top (required)>'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `run'
/Users/shaimo-mbp/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.0.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => bundler:install

当 ssh-ing 进入服务器并运行相同的命令 ("cd /var/www/app/current && /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/app/shared/bin --without development test") 似乎一切正常...

对此感到非常绝望...... 谢谢!

【问题讨论】:

【参考方案1】:

线条

DEBUG [f15c9f08] Command: cd /var/www/app/current && /usr/bin/env bundle --gemfile /var/www/app/current/Gemfile --path /var/www/app/shared/bundle --deployment --verbose --binstubs /var/www/app/shared/bin --without development test
DEBUG [f15c9f08]    /usr/bin/env: 
DEBUG [f15c9f08]    bundle
DEBUG [f15c9f08]    : No such file or directory
DEBUG [f15c9f08]    

表示未找到或未安装捆绑程序。 Capistrano(如本文所述 http://www.capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/ 所述)在非登录、非交互式 shell 中运行。

我猜bundler 安装在一个特殊的路径中,或者您使用的是rvm、chruby 或rbenv。并且由于 Capistrano 使用的是非登录、非交互式会话,这些东西并没有像当你 SSH 进入盒子时那样被初始化。

解决方案是使用capistrano-rvm,chruby,rbenv gem 中的任何一个,它适合您的环境,如Capfile 中所述。

如果您没有使用这些版本管理器之一,请尝试以下操作:

ssh me@theserver 'which bundler'

您可能不会看到任何输出(更多关于为什么在上面的链接中),解决这个问题,Capistrano 就可以工作了。

【讨论】:

【参考方案2】:

问题确实出在 非交互式 shell

最终我不得不将以下行添加到.bashrc

source ~/.rvm/scripts/rvm

如果其他人遇到类似问题,我将补充一点,我还必须映射 rake 命令,以便它能够正常工作。必须将以下行添加到我的 deploy.rb 文件中:

SSHKit.config.command_map[:rake] = "bundle exec rake"

【讨论】:

【参考方案3】:

你最好使用 capistrano-rbenv gem 来管理你的 ror env

    添加gem 'capistrano-rbenv', '~&gt; 2.0' to yourgemfile 在您的 capfile 中取消注释 require 'capistrano/rbenv';如果capistrano/bundler 评论了,也取消评论 在部署文件中设置 rbenv_ruby 变量 set :rbenv_ruby, '2.0.0-p247'

然后一切就绪!

【讨论】:

【参考方案4】:

我回答这个问题有点晚了,但它可能会对像我这样的用户有所帮助。

如果您使用的是rbenv,则通过在deploy.rb 中添加以下行来设置rbenv 的默认环境

set :default_env, path: "~/.rbenv/shims:~/.rbenv/bin:$PATH"

【讨论】:

【参考方案5】:

bundle 可执行文件从系统中丢失,或者 shell 不知道它的 PATH。

检查以下测试:

系统可以找到perl可执行文件:

# /usr/bin/env perl
^C   << I did CTRL+C as perl was expecitng me to put some code

现在,我的系统找不到perlyo 可执行文件并抛出错误:

# /usr/bin/env perlyo
/usr/bin/env: perlyo: No such file or directory

上面的错误与/usr/bin/env bundle 得到的类似:

DEBUG [f15c9f08]    /usr/bin/env: 
DEBUG [f15c9f08]    bundle
DEBUG [f15c9f08]    : No such file or directory 

通过运行以下命令检查系统是否知道bundle

# which bundle
# whereis bundle

如果上面的命令找不到,则检查系统上是否存在bundle,如下所示:

# updatedb
# locate bundle

如果您找到bundle,则相应地添加其path,以便您的shell 可以识别它。

希望这会有所帮助。

【讨论】:

【参考方案6】:

我能够通过将以下代码添加到 ~/.bashrc 来解决该问题:

export RBENV_ROOT="$HOME/.rbenv"

if [ -d "$RBENV_ROOT" ]; then
  export PATH="$RBENV_ROOT/bin:$PATH"
  eval "$(rbenv init -)"
fi

【讨论】:

【参考方案7】:

正如@zpieslak 所说:

在 ~/.bashrc 中添加:

if [ -d "$RBENV_ROOT" ]; then
  export PATH="$RBENV_ROOT/bin:$PATH"
  eval "$(rbenv init -)"
fi

在这一行之前:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

【讨论】:

以上是关于Capistrano 捆绑器:安装失败的主要内容,如果未能解决你的问题,请参考以下文章

capistrano 部署 - 基本命令失败

当通过 NVM 安装 NPM 时,Capistrano 部署失败并出现 react_on_rails

捆绑安装失败并出现 SSL 证书验证错误

Capistrano 3:运行自定义 shell 命令时无法识别捆绑器

在 Rails Docker 容器中捆绑安装失败

自定义捆绑迁移在首次安装时失败,因为它们在 OroCommerce 的安装程序之前运行