我想通过rails 4.0
部署我的简单capistrano 3.0
应用程序。
我使用bundler 1.3.5
所以我添加capistrano-bundler gem来将bundler与capistrano集成。
我的配置非常简单(几乎默认):
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
当我运行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
但是,如果我复制此命令并运行ssh一切正常(所有gems安装成功)我如何修复/调试它?
答案 0 :(得分:50)
刚遇到同样的问题。对我有用的是:
1)安装capistrano-rvm
gem并添加
require 'capistrano/rvm'
到Capfile
。
2)将部署用户添加到服务器上的rvm
组:
# usermod deploy -a -G rvm
3)在部署用户的主文件夹中创建两个目录:.rvm
和.rvm/bin
4)将此行添加到我的deploy.rb
文件中:
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
唷!这花了几个小时。
答案 1 :(得分:12)
该错误听起来好像无法在bundle
中找到PATH
。当您手动SSH时,它可能会在~/.profile
或~/.bash_profile
中运行,将其添加到您的路径中。
登录并运行bundle
,找到which bundle
的路径。然后,尝试查找如何将该路径添加到PATH
环境变量中。如果您的~/.bash_profile, try moving it to
〜/ .bashrc`中有某些内容。
您还可以尝试Command Mapping指定确切的路径。
还有一些问题排查提示答案 2 :(得分:3)
简单的解决方案并适用于所有Capistrano 3版本:
gem 'rvm1-capistrano3', require: false
在Capfile中添加
require 'rvm1/capistrano3'
答案 3 :(得分:2)
在我的情况下,我将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
到
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
(注意添加的“cd”)
答案 4 :(得分:1)
我有:
set :bundle_flags, '--system --quiet'
更改为:
set :bundle_flags, '--deployment --quiet'
这解决了一个问题。
答案 5 :(得分:0)
这适用于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
将此用于rake任务:
execute :rake, 'some_rake_task'
答案 6 :(得分:0)
set :rvm_ruby_version, '2.0.0-p247'
答案 7 :(得分:0)
gem install bundler
我需要在部署用户上运行才能获得Capistrano的服务:
/usr/local/rvm/bin/rvm 2.4.0 do bundle install --path /var/www/hivebench-api/shared/bundle --without development test --deployment --quiet
通过!
答案 8 :(得分:-1)
要调试它,请尝试删除--quiet
标志:
set :bundle_flags, '--deployment'
您使用的是rbenv,rvm还是类似的东西?当bundle
运行时,Ruby版本可能尚未设置。通过删除--quite
标志,您可能会获得一些调试信息。