在卡皮斯特拉诺食谱中放置“之前”和“之后”的位置?

时间:2011-08-08 16:42:56

标签: ruby-on-rails ruby-on-rails-3 capistrano

愚蠢的问题,但我们有一个破碎的卡皮斯特拉诺食谱,我想验证我们没有使用after& before不正确?

之前和之后做这些任务属于:deploy命名空间块或其外部?我看到了here的两个例子。

这是有问题的deploy.rb:

的摘录
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  # copy database.yml into project
  task :copy_database_config do
    production_db_config = "/Library/RoRconfig/#{application}.yml"
    run "cp #{production_db_config} #{current_release}/config/database.yml"
    `puts "replaced database.yml with live copy"` 
  end

  task :pipeline_precompile do
    run "cd #{release_path}; RAILS_ENV=production rake assets:precompile"
  end

  after "deploy:update_code", "deploy:pipeline_precompile"         ### <---
  before "deploy:finalize_update", "deploy:copy_database_config"   ### <---
end

2 个答案:

答案 0 :(得分:4)

我使用类似于以下的设置:

after :deploy, "deploy:update_code", "deploy:pipeline_precompile"
before :deploy, "deploy:finalize_update", "deploy:copy_database_config"

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  # copy database.yml into project
  task :copy_database_config do
    production_db_config = "/Library/RoRconfig/#{application}.yml"
    run "cp #{production_db_config} #{current_release}/config/database.yml"
    `puts "replaced database.yml with live copy"` 
  end

  task :pipeline_precompile do
    run "cd #{release_path}; RAILS_ENV=production rake assets:precompile"
  end
end

答案 1 :(得分:0)

根据https://capistranorb.com/documentation/getting-started/before-after/上capistrano的文档,这是它们在:deploy命名空间的内部和外部建议的方式:

# call an existing task
before :starting, :ensure_user
after :finishing, :notify

# or define in block
namespace :deploy do
  before :starting, :ensure_user do
    #
  end

  after :finishing, :notify do
    #
  end
end

但是,请注意不要将这些挂钩放在您导入的自定义capistrano rake文件中,因为加载顺序可能使其不存在。