gpt4 book ai didi

ruby-on-rails - 不正确的 deploy.rb - "NoMethodError: undefined method ` tail' for nil :NilClass"

转载 作者:行者123 更新时间:2023-12-04 18:36:53 25 4
gpt4 key购买 nike

这是我的 的样子部署.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

如果我删除命名空间 block ,错误就消失了,但我需要它。是什么导致了这个错误?我整个下午都在和它作斗争,但仍然不知道如何摆脱它。

提前谢谢你们。

最佳答案

这是因为您使用 Capistrano v2 DSL 和 Capistrano v3,这是不兼容的。

您需要替换选项 roles: :app带有一个 block ,例如:

task :my_task do    
on roles(:app) do
...
end
end

参见 this Capistrano release announcement 中的“更具表现力的命令语言” .

关于ruby-on-rails - 不正确的 deploy.rb - "NoMethodError: undefined method ` tail' for nil :NilClass",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24030568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com