我正在使用Capistrano 3:
➜ webapp git:(rails) ✗ cap --version
Capistrano Version: 3.1.0 (Rake Version: 10.1.1)
我的
Capfile
是:# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
我的
deploy.rb
是:set :rvm_type, :user
set :application, "my_app"
set :scm, :git
set :repo_url, '[email protected]:nanounanue/my_app.git'
set :scm_passphrase, ""
set :ssh_options, {:forward_agent => true}
set :default_run_options, {:pty => true}
set :stages, ["vagrant"]
set :default_stage, "vagrant"
namespace :deploy do
task :start do ; end
task :stop do ; end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
run "sudo touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
如您所见,我正在尝试部署到
Vagrant VM
。问题是,当我执行
Capistrano
的(任何)命令时,会发生以下情况:➜ webapp git:(rails) ✗ cap vagrant deploy --trace
** Invoke vagrant (first_time)
** Execute vagrant
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:check (first_time)
** Execute rvm:check
DEBUG [501eda1d] Running ~/.rvm/bin/rvm version on 192.168.33.10
DEBUG [501eda1d] Command: ~/.rvm/bin/rvm version
DEBUG [501eda1d]
DEBUG [501eda1d] rvm 1.25.20 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
DEBUG [501eda1d]
DEBUG [501eda1d] Finished in 0.446 seconds with exit status 0 (successful).
rvm 1.25.20 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
DEBUG [c7fc23f0] Running ~/.rvm/bin/rvm current on 192.168.33.10
DEBUG [c7fc23f0] Command: ~/.rvm/bin/rvm current
DEBUG [c7fc23f0] ruby-2.0.0-p247
DEBUG [c7fc23f0] Finished in 0.185 seconds with exit status 0 (successful).
ruby-2.0.0-p247
DEBUG [3fb3aad9] Running ~/.rvm/bin/rvm default do ruby --version on 192.168.33.10
DEBUG [3fb3aad9] Command: ~/.rvm/bin/rvm default do ruby --version
DEBUG [3fb3aad9] RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [3fb3aad9]
DEBUG [3fb3aad9] You need to change your terminal emulator preferences to allow login shell.
DEBUG [3fb3aad9] Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [3fb3aad9] Please visit https://rvm.io/integration/gnome-terminal/ for a example.
DEBUG [3fb3aad9]
DEBUG [3fb3aad9] ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
DEBUG [3fb3aad9]
DEBUG [3fb3aad9] Finished in 0.309 seconds with exit status 0 (successful).
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
这将继续,直到到达
bundle install
部分:DEBUG [184656ed] Command: cd /home/vagrant/apps/releases/20140313235436 && ~/.rvm/bin/rvm default do bundle install --binstubs /home/vagrant/apps/shared/bin --path /home/vagrant/apps/shared/bundle --without development test --deployment --quiet
DEBUG [184656ed] RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [184656ed]
DEBUG [184656ed] You need to change your terminal emulator preferences to allow login shell.
DEBUG [184656ed] Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [184656ed] Please visit https://rvm.io/integration/gnome-terminal/ for a example.
DEBUG [184656ed]
DEBUG [184656ed] You are trying to install in deployment mode after changing
DEBUG [184656ed] your Gemfile. Run `bundle install` elsewhere and add the
DEBUG [184656ed] updated Gemfile.lock to version control.
DEBUG [184656ed]
DEBUG [184656ed] You have added to the Gemfile:
DEBUG [184656ed] * crossfilter-rails
DEBUG [184656ed]
cap aborted!
bundle stdout: Nothing written
bundle stderr: Nothing written
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status='
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `call'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:164:in `block (2 levels) in _execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `call'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:166:in `block in _execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `tap'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/capistrano-bundler-1.1.2/lib/capistrano/tasks/bundler.cap:30:in `block (5 levels) in <top (required)>'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/abstract.rb:89:in `with'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/capistrano-bundler-1.1.2/lib/capistrano/tasks/bundler.cap:22:in `block (4 levels) in <top (required)>'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/abstract.rb:81:in `within'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/capistrano-bundler-1.1.2/lib/capistrano/tasks/bundler.cap:21:in `block (3 levels) in <top (required)>'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/nano/.rvm/gems/ruby-2.0.0-p247@opi-webapp/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:updated => bundler:install
The deploy has failed with an error: #<SSHKit::Command::Failed: bundle stdout: Nothing written
bundle stderr: Nothing written
>
** Invoke deploy:failed (first_time)
** Execute deploy:failed
我不知道这是怎么回事...你有 Ant 的想法吗?
编辑:
在
vagrant
虚拟机中,.bash_profile
为:vagrant@vagrant-ubuntu-saucy-64:~$ cat .bash_profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
编辑(2014年3月25日):
在@GhostGambler的建议之后,新的
Capfile
为:set :default_environment, {
'PATH' => "/usr/local/rvm/gems/ree-1.8.7-2012.02@<gemset>/bin:/usr/local/rvm/gems/ree-1.8.7-2012.02@global/bin:/usr/local/rvm/rubies/ree-1.8.7-2012.02/bin:/usr/local/rvm/bin:$PATH",
'RUBY_VERSION' => 'ree-1.8.7-2012.02',
'GEM_HOME' => '/usr/local/rvm/gems/ree-1.8.7-2012.02@<gemset>',
'GEM_PATH' => '/usr/local/rvm/gems/ree-1.8.7-2012.02@<gemset>'
#,
#'BUNDLE_PATH' => '/usr/local/rvm/gems/ree-1.8.7-2012.02' # If you are using bundler.
}
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'rvm1/capistrano3'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
我在
deploy.rb
中添加了...
before 'deploy', 'rvm1:install:gems'
namespace :deploy do
...
该错误仍然会出现(
RVM is not a function...
),但它可以安装gems,但是现在失败了,并出现另一个错误:DEBUG [29ba9d5d] Command: cd /home/vagrant/apps/releases/20140325223229 && /tmp/arquimedes/rvm-auto.sh . gem install --file Gemfile
DEBUG [29ba9d5d] RVM is not a function, selecting rubies with 'rvm use ...' will not work.
DEBUG [29ba9d5d]
DEBUG [29ba9d5d] You need to change your terminal emulator preferences to allow login shell.
DEBUG [29ba9d5d] Sometimes it is required to use `/bin/bash --login` as the command.
DEBUG [29ba9d5d] Please visit https://rvm.io/integration/gnome-terminal/ for a example.
DEBUG [29ba9d5d]
DEBUG [29ba9d5d] Using execjs (2.0.2)
DEBUG [29ba9d5d] Using json (1.8.1)
DEBUG [29ba9d5d] Using uglifier (2.4.0)
...
DEBUG [29ba9d5d] Using bootstrap-sass (3.1.1.0)
DEBUG [29ba9d5d]
INFO [29ba9d5d] Finished in 135.237 seconds with exit status 0 (successful).
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper
** Execute git:check
DEBUG [6f67db51] Running /usr/bin/env git ls-remote [email protected]:opintel/webapp.git on 192.168.33.10
DEBUG [6f67db51] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/arquimedes/
...
...
DEBUG [6f67db51] Finished in 4.179 seconds with exit status 0 (successful).
** Invoke deploy:check:directories (first_time)
** Execute deploy:check:directories
INFO [645d5072] Running /usr/bin/env mkdir -pv /home/vagrant/apps/shared /home/vagrant/apps/releases on 192.168.33.10
DEBUG [645d5072] Command: /usr/bin/env mkdir -pv /home/vagrant/apps/shared /home/vagrant/apps/releases
INFO [645d5072] Finished in 0.011 seconds with exit status 0 (successful).
** Invoke deploy:check:linked_dirs (first_time)
** Execute deploy:check:linked_dirs
** Invoke deploy:check:make_linked_dirs (first_time)
** Execute deploy:check:make_linked_dirs
** Invoke deploy:check:linked_files (first_time)
** Execute deploy:check:linked_files
** Invoke deploy:started (first_time)
** Execute deploy:started
** Invoke deploy:updating
** Invoke deploy:updated (first_time)
** Execute deploy:updated
** Invoke deploy:publishing (first_time)
** Execute deploy:publishing
** Invoke deploy:symlink:release (first_time)
** Execute deploy:symlink:release
INFO [bf5c604d] Running /usr/bin/env rm -rf /home/vagrant/apps/current on 192.168.33.10
DEBUG [bf5c604d] Command: /usr/bin/env rm -rf /home/vagrant/apps/current
INFO [bf5c604d] Finished in 0.011 seconds with exit status 0 (successful).
INFO [72cfae75] Running /usr/bin/env ln -s /home/vagrant/apps/releases/20140325223229 /home/vagrant/apps/current on 192.168.33.10
DEBUG [72cfae75] Command: /usr/bin/env ln -s /home/vagrant/apps/releases/20140325223229 /home/vagrant/apps/current
INFO [72cfae75] Finished in 0.011 seconds with exit status 0 (successful).
** Invoke deploy:restart (first_time)
** Execute deploy:restart
cap aborted!
ArgumentError: wrong number of arguments (1 for 0)
最佳答案
您听说过rvm1-capistrano3吗?
通过放入Gemfile
进行安装
gem 'rvm1-capistrano3', :require => false
(不要忘了捆绑安装)并放入
Capfile
require 'rvm1/capistrano3'
这一次解决了我所有的问题。
修改
Capfile
时,您应该删除(或注释掉)require 'capistrano/rvm'
因为这颗 gem 不需要这样做,并且可能会损坏东西。
关于ruby-on-rails-4 - RVM,Capistrano 3和捆绑软件失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22393649/