如何在另一个Capistrano任务中调用Capistrano任务?

编程入门 行业动态 更新时间:2024-10-18 00:35:39
本文介绍了如何在另一个Capistrano任务中调用Capistrano任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个基本任务,用于将database.yml文件复制并链接到我的应用程序中,但我不知道为什么它无法正常工作。

I'm trying to create a basic task for copying and linking database.yml file into my app, but I can't figure out why it s not working.

我正在使用Capistrnao 3.1

I'm using Capistrnao 3.1

这是我的lib / capistrano / tasks / databases.cap文件:

This is my lib/capistrano/tasks/databases.cap file :

namespace :db_access do # Idea : github/capistrano/sshkit/blob/master/EXAMPLES.md desc 'Copy production database.yml from local workstation' task :copy_production do on roles :all do execute :mkdir, '-p', "#{shared_path}/config" upload! 'config/deploy/production.database.yml', "#{shared_path}/config/database.yml" end end # Idea : stackoverflow/questions/9684649/capistrano-cant-deploy-my-database-yml desc 'Create database.yml symlinks to current release' task :create_symlinks do on roles :all do unless test "[ -f #{shared_path}/config/database.yml ]" invoke 'db_access:copy_production' end execute :ln, "-nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" end end end

这是我得到的输出:

douglas@bilbo:/var/www/odpf$ cap production db_access:create_symlinks DEBUG [3f670dfd] Running /usr/bin/env [ -f /var/www/odpf/shared/config/database.yml ] on myserver DEBUG [3f670dfd] Command: [ -f /var/www/odpf/shared/config/database.yml ] DEBUG [3f670dfd] Finished in 0.589 seconds with exit status 1 (failed). cap aborted! **undefined method `verbosity' for "/usr/bin/env db_access:copy_production\n":String** /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/formatters/pretty.rb:10:in `write' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:14:in `block in execute' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:13:in `tap' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:13:in `execute' /var/www/odpf/lib/capistrano/tasks/databases.cap:20:in `block (3 levels) in <top (required)>' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' Tasks: TOP => db_access:create_symlinks

我不知道如何调用其他任务。我从 github/capistrano启发了myslef /capistrano/blob/master/lib/capistrano/tasks/deploy.rake

I don't know how to invoke the other task. I inspirate myslef from github/capistrano/capistrano/blob/master/lib/capistrano/tasks/deploy.rake

如果我尝试不使用'invoke'关键字并且不使用''符号:

If I try without the 'invoke' keyword and without ' ' signs :

namespace :db_access do # Idea : github/capistrano/sshkit/blob/master/EXAMPLES.md desc 'Copy production database.yml from local workstation' task :copy_production do on roles :all do execute :mkdir, '-p', "#{shared_path}/config" upload! 'config/deploy/production.database.yml', "#{shared_path}/config/database.yml" end end # Idea : stackoverflow/questions/9684649/capistrano-cant-deploy-my-database-yml desc 'Create database.yml symlinks to current release' task :create_symlinks do on roles :all do unless test "[ -f #{shared_path}/config/database.yml ]" db_access.copy_production end execute :ln, "-nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml" end end end

结果如下:

douglas@bilbo:/var/www/odpf$ cap production db_access:create_symlinks --trace ** Invoke production (first_time) ** Execute production ** Invoke load:defaults (first_time) ** Execute load:defaults ** Invoke db_access:create_symlinks (first_time) ** Execute db_access:create_symlinks cap aborted! undefined local variable or method `db_access' for #<SSHKit::Backend::Netssh:0x00000002862340> /var/www/odpf/lib/capistrano/tasks/databases.cap:20:in `block (3 levels) in <top (required)>' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run' /home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' Tasks: TOP => db_access:create_symlinks

这肯定是一个简单的语法错误,但是由于我找不到解释它的指南

This must be a simple syntaxe mistake but since I can't find a guide that explain that I don't know how to do.

感谢您的帮助

推荐答案

我的命令调用'db_access:copy_production'是正确的。

my command invoke 'db_access:copy_production' was correct.

问题来自SSH-KIT,它的错误。 问题是Capistrano 3.1使用的是ssh-kit版本1.3。 因此,我们必须使用Capistrano 3.0.1直到ssh-kit得到修复。

The problem comes from SSH-KIT which has a bug. The problem is that Capistrano 3.1 is using ssh-kit version 1.3. So we have to use Capistrano 3.0.1 until ssh-kit get fixed.

解决方法:

gem uninstall capistrano gem uninstall capistrano-rails gem uninstall sshkit rm Gemfile.lock

修改Gemfile:

gem 'capistrano', '~> 3.0.1' gem 'sshkit', '~> 1.0.0'

安装gems:

bundle install

更多推荐

如何在另一个Capistrano任务中调用Capistrano任务?

本文发布于:2023-11-12 10:41:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581264.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Capistrano

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!