【问题标题】:Where to place "before" and "after" in a Capistrano recipe?Capistrano 食谱中的“之前”和“之后”放在哪里?
【发布时间】:2011-08-08 16:42:55
【问题描述】:

愚蠢的问题,但我们有一个损坏的 Capistrano 配方,我想确认我们没有错误地使用 afterbefore

这些之前和之后的任务是属于 :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

【问题讨论】:

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


    【解决方案1】:

    我使用的设置类似于:

    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
    

    【讨论】:

      【解决方案2】:

      根据 capistrano 在https://capistranorb.com/documentation/getting-started/before-after/ 的文档,这是他们对 :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 文件中,因为加载顺序可能使其不存在。

      【讨论】:

        猜你喜欢
        • 2015-12-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-22
        • 1970-01-01
        • 2019-04-11
        • 2015-10-24
        相关资源
        最近更新 更多