这里看起来像我的 deploy.rb 。
set :application, 'myapp'
set :scm, :git
set :repo_url, 'git@bitbucket.org:me/myapp.git'
set :pty, true
set :deploy_to, "/home/deployer/apps/myapp-staging"
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
#run "/etc/init.d/unicorn_#{application} #{command}"
run "/etc/init.d/unicorn_myapp-staging #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/myapp"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_myapp-staging"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
当我部署代码时,我收到此错误:
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
cap aborted!
NoMethodError: undefined method `tail' for nil:NilClass
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task_manager.rb:212:in `ensure in in_namespace'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task_manager.rb:212:in `in_namespace'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/dsl_definition.rb:146:in `namespace'
config/deploy.rb:75:in `<top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/capistrano-3.2.1/lib/capistrano/setup.rb:14:in `load'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/capistrano-3.2.1/lib/capistrano/setup.rb:14:in `block (2 levels) in <top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/adam/.rvm/rubies/ruby-1.9.3-p385/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/capistrano-3.2.1/lib/capistrano/application.rb:15:in `run'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/gems/capistrano-3.2.1/bin/cap:3:in `<top (required)>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/cap:19:in `load'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/cap:19:in `<main>'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `eval'
/Users/adam/.rvm/gems/ruby-1.9.3-p385/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => staging
如果删除命名空间块,错误就消失了,但我需要它。导致此错误的原因是什么?我整个下午都在和它斗争,但仍然不知道如何摆脱它。
先谢谢你们。
答案 0 :(得分:3)
这是因为您使用Capistrano v2 DSL与Capistrano v3,这是不兼容的。
您需要使用以下块替换选项roles: :app
:
task :my_task do
on roles(:app) do
...
end
end
参见&#34;更具表现力的命令语言&#34;在this Capistrano release announcement。