【问题标题】:remote_file capistrano 3 methodremote_file capistrano 3 方法
【发布时间】:2014-09-03 15:15:20
【问题描述】:

在 capistrano 3 文档 (http://capistranorb.com/documentation/advanced-features/remote-file/) 中提供了一个示例来说明此任务 (remote_file) 的工作原理

namespace :deploy do
    namespace :check do
        task :linked_files => 'config/newrelic.yml'
    end
end

remote_file 'config/newrelic.yml' => '/tmp/newrelic.yml', roles: :app

file '/tmp/newrelic.yml' do |t|
    sh "curl -o #{t.name} https://rpm.newrelic.com/accounts/xx/newrelic.yml"
end

他们告诉它允许将远程文件的存在设置为先决条件。 但是我仍然无法理解它是如何工作的,因为 remote_file 在任务代码之外被调用。它实际上是做什么的?谁能解释一下?

如果 config/newrelic.yml 不存在会发生什么以及 remote_file 调用如何连接 :linked_files 任务?

【问题讨论】:

    标签: capistrano capistrano3


    【解决方案1】:

    仅调用remote_file定义名为“config/newrelic.yml”的任务。它不执行该任务。线

    remote_file 'config/newrelic.yml' => '/tmp/newrelic.yml', roles: :app
    

    是说“创建一个名为 'config/newrelic.yml' 的任务,它有一个名为 '/tmp/newrelic.yml' 的先决任务”。 file '/tmp/newrelic.yml' 部分定义了这个先决任务。最后,task :linked_files => 'config/newrelic.yml' 指定了要执行的名为“config/newrelic.yml”的先决任务,我们使用remote_file 方法定义了它。

    【讨论】:

    • 似乎很清楚,除了为什么任务名称像 /tmp/newrelic.yml 并且看起来像文件路径?给定文件的内容是否包含任务代码?
    • 您需要阅读远程文件使用的 Rake 文件任务。文件任务的特殊之处在于它们希望以要工作的文件的路径命名。这是一篇很好的博客文章,解释它madewithenvy.com/ecosystem/articles/2013/rake-file-tasks
    • 感谢您的澄清!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多