有没有更好的方法从rake中运行capistrano任务?

Jon*_*ace 4 ruby rake capistrano

我有一套rake任务,我需要在某些时候调用capistrano.埃德温·戈伊(Edwin Goei)的博客建议通过"sh"向capistrano 猛烈抨击.

有更简单的方法吗?看起来你应该能够以编程方式调用适当的任务.提前致谢.

Sar*_*Mei 7

是的,Capistrano可以通过编程方式访问命令行组件.但是,如果你想从rake任务中调用它们,你需要做一些额外的工作.

task :deploy
  require 'rubygems'
  require 'capistrano'
  require 'capistrano/cli'

  parameters = ["deploy"] # this is an array of the strings that come after
                          # cap on the command line. e.g., 
                          # ["deploy", "-S", "revision=1024"] gives you local var
                          # revision in your deploy.rb.

  # The following is required ONLY when you run Capistrano 2+ from Rake, 
  # because Rake adds the methods from FileUtils to Object. FileUtils includes 
  # a method called symlink which interferes with Capistrano's symlink task.
  Capistrano::Configuration::Namespaces::Namespace.class_eval { undef :symlink }

  Capistrano::CLI.parse(parameters).execute!
end
Run Code Online (Sandbox Code Playgroud)