Ruby-on-rails 捆绑安装不适用于 capistrano
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19363077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bundle install doesn't work from capistrano
提问by freemanoid
I want to deploy my simple rails 4.0application via capistrano 3.0.
我想rails 4.0通过capistrano 3.0.
I use bundler 1.3.5so I add capistrano-bundlergem to integrate bundler with capistrano.
我使用bundler 1.3.5所以我添加了capistrano-bundlergem 以将 bundler 与 capistrano 集成。
I have pretty simple configuration (almost default):
我有非常简单的配置(几乎默认):
set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_flags, ''
set :bundle_without, %w{test development}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
set :bundle_roles, :all
When I run the cap staging deploy --traceit fails:
当我运行cap staging deploy --trace它失败:
[50b524bc] Running /usr/bin/env bundle --gemfile /home/webmaster/www/api/releases/20131014144650/Gemfile --path /home/webmaster/www/api/shared/bundle --binstubs /home/webmaster/www/api/shared/bin --without test development on 125.51.3.1
DEBUG [50b144bc] Command: cd /home/webmaster/www/api/releases/20131014144650 && /usr/bin/env bundle --gemfile /home/webmaster/www/api/releases/20131014144650/Gemfile --path /home/webmaster/www/api/shared/bundle --binstubs /home/webmaster/www/api/shared/bin --without test development
cap aborted!
bundle stdout: Nothing written
bundle stderr: Nothing written
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/command.rb:94:in `exit_status='
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:147:in `block (2 levels) in _execute'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:149:in `block in _execute'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:20:in `block (4 levels) in <top (required)>'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/abstract.rb:81:in `within'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-bundler-1.0.0/lib/capistrano/tasks/bundler.cap:19:in `block (3 levels) in <top (required)>'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/backends/netssh.rb:42:in `run'
/home/omnomnom/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.0.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:updated => bundler:install
But if I copy this command and run though ssh all works fine (all gems installed successfully) How I can fix/debug it?
但是如果我复制这个命令并运行 ssh 一切正常(所有 gems 安装成功)我如何修复/调试它?
回答by Daibhi O Domhnaill
Just ran into the same issue. What worked for me was this:
刚刚遇到了同样的问题。对我有用的是:
1) Installing the capistrano-rvmgem and adding
1)安装capistrano-rvmgem并添加
require 'capistrano/rvm'
to the Capfile.
到Capfile.
2) Adding my deployment user to the rvmgroup on the server:
2)将我的部署用户添加到rvm服务器上的组:
# usermod deploy -a -G rvm
3) Creating two directories in my deployment user's home folder: .rvmand .rvm/bin
3)在我的部署用户的主文件夹中创建两个目录:.rvm和.rvm/bin
4) Adding this line to my deploy.rbfile:
4)将此行添加到我的deploy.rb文件中:
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
Phew! That took a few hours.
呼!那花了几个小时。
回答by Tim Moore
The error sounds like it can't find bundlein your PATH. It's possible that when you SSH in manually, it's running something in your ~/.profileor ~/.bash_profilethat adds it to your path.
该错误听起来像是bundle在您的PATH. 有可能当您手动 SSH 进入时,它正在您的路径中运行某些内容~/.profile或~/.bash_profile将其添加到您的路径中。
Find the path to bundleby logging in and running which bundle. Then, try to find how that path is added to your PATHenvironment variable. If there's something in your ~/.bash_profile, try moving it to~/.bashrc` instead.
bundle通过登录并运行找到路径which bundle。然后,尝试找出该路径是如何添加到您的PATH环境变量中的。如果你的~/.bash_profile, try moving it to~/.bashrc` 中有东西。
You can also try Command Mappingto specify an exact path.
您还可以尝试使用命令映射来指定确切的路径。
There are some more troubleshooting tips at http://www.capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/
在http://www.capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/上有更多故障排除技巧
回答by Nesha Zoric
Simple solution and working on all Capistrano 3 versions:
简单的解决方案并适用于所有 Capistrano 3 版本:
gem 'rvm1-capistrano3', require: false
In Capfile add
在 Capfile 添加
require 'rvm1/capistrano3'
回答by Hymanr
In my case, I changed config/deploy.rb's set :log_level, :infoto set :log_level, :debug, which showed me "Can not find GEMFILE." This suggested that bundlewas running with the wrong working directory, so I changed
就我而言,我将 config/deploy.rb 更改set :log_level, :info为set :log_level, :debug,这显示“找不到 GEMFILE”。这表明bundle使用错误的工作目录运行,所以我改变了
before "deploy:assets:precompile", "deploy:bundle_install"
desc "Bundle install for RVMs sake"
task :bundle_install do
on roles(:app) do
execute "/u0/jrepenni/.rvm/bin/rvm 2.1.0@akiary do /u0/jrepenni/.rvm/gems/ruby-2.1.0@global/bin/bundle install"
end
end
to
到
before "deploy:assets:precompile", "deploy:bundle_install"
desc "Bundle install for RVMs sake"
task :bundle_install do
on roles(:app) do
execute "cd #{release_path} && /u0/jrepenni/.rvm/bin/rvm 2.1.0@akiary do /u0/jrepenni/.rvm/gems/ruby-2.1.0@global/bin/bundle install"
end
end
(note the added "cd")
(注意添加的“cd”)
回答by Alex Fedoseev
I had:
我有:
set :bundle_flags, '--system --quiet'
Changed to:
变成:
set :bundle_flags, '--deployment --quiet'
This resolved a problem.
这解决了一个问题。
回答by Alain Beauvois
This works in capistrano 3:
这适用于 capistrano 3:
task :bundle_list do
on roles(:app) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :bundle, "list"
end
end
end
end
Use this for rake task :
将此用于 rake 任务:
execute :rake, 'some_rake_task'
回答by user1130176
in your config/deploy/production.rb file put
在您的 config/deploy/production.rb 文件中放入
set :rvm_ruby_version, '2.0.0-p247'
回答by Stéphane Bruckert
gem install bundler
is what I needed to run on my deploy user in order for Capistrano's:
是我需要在我的部署用户上运行以便 Capistrano 的:
/usr/local/rvm/bin/rvm 2.4.0 do bundle install --path /var/www/hivebench-api/shared/bundle --without development test --deployment --quiet
to pass!
通过!
回答by blat
To debug it try to remove the --quietflag:
要调试它,请尝试删除该--quiet标志:
set :bundle_flags, '--deployment'
set :bundle_flags, '--deployment'
Are you using rbenv, rvm or something similar? It might be possible that when bundleis running the Ruby version is not set yet. By removing the --quiteflag you might get some debugging information.
你在使用 rbenv、rvm 或类似的东西吗?可能bundle还没有设置运行 Ruby 版本的时间。通过删除--quite标志,您可能会获得一些调试信息。

