Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way to run a capistrano task from within rake?

I have a set of rake tasks where I need to invoke capistrano at some point. Edwin Goei's blog suggests shelling out to capistrano via "sh".

Is there a simpler way? It would seem you should be able to call the appropriate tasks programmatically. Thanks in advance.

like image 726
Jonathan R. Wallace Avatar asked Jan 24 '23 13:01

Jonathan R. Wallace


1 Answers

Yes, Capistrano has programmatic access to the command-line components. If you want to call them from a rake task, though, you need to do a little extra work.

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
like image 144
Sarah Mei Avatar answered Jan 30 '23 00:01

Sarah Mei