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

时间:2022-04-11 07:25:22

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".

我有一组rake任务,我需要在某些时候调用capistrano。 Edwin Goei的博客建议通过“sh”向capistrano炮轰。

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

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

3 个解决方案

#1


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.

是的,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

#2


For capistrano 3:

对于capistrano 3:

http://capistranorb.com/documentation/advanced-features/capistrano-pure-ruby/

require 'capistrano/all'

  stages = "production"
  set :application, 'my_app_name'
  set :repo_url, 'git@github.com:capistrano/capistrano.git'
  set :deploy_to, '/var/www/'
  set :stage, :production
  role :app, %w{}

  require 'capistrano/setup'
  require 'capistrano/deploy'
  Dir.glob('capistrano/tasks/*.cap').each { |r| import r }

  Capistrano::Application.invoke("production")
  Capistrano::Application.invoke("deploy")

#3


Jonathan, your mileage may vary by doing something like set(:shell, false) to stop capistrano running tasks in a sub-sh-shell.

Jonathan,你的里程可能因set(:shell,false)之类的东西而有所不同,以阻止在sub-sh-shell中运行capistrano任务。

Just a thought, feel free to ping me if you need a hand though.

只是一个想法,如果你需要一只手,请随时给我打电话。

#1


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.

是的,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

#2


For capistrano 3:

对于capistrano 3:

http://capistranorb.com/documentation/advanced-features/capistrano-pure-ruby/

require 'capistrano/all'

  stages = "production"
  set :application, 'my_app_name'
  set :repo_url, 'git@github.com:capistrano/capistrano.git'
  set :deploy_to, '/var/www/'
  set :stage, :production
  role :app, %w{}

  require 'capistrano/setup'
  require 'capistrano/deploy'
  Dir.glob('capistrano/tasks/*.cap').each { |r| import r }

  Capistrano::Application.invoke("production")
  Capistrano::Application.invoke("deploy")

#3


Jonathan, your mileage may vary by doing something like set(:shell, false) to stop capistrano running tasks in a sub-sh-shell.

Jonathan,你的里程可能因set(:shell,false)之类的东西而有所不同,以阻止在sub-sh-shell中运行capistrano任务。

Just a thought, feel free to ping me if you need a hand though.

只是一个想法,如果你需要一只手,请随时给我打电话。