【问题标题】:How to change the order of rsync in symfony deployment task如何在 symfony 部署任务中更改 rsync 的顺序
【发布时间】:2011-08-17 17:03:16
【问题描述】:

我想部署我的 symfony 应用程序的一部分,比如说,它就像一个模块。

我想先排除所有文件,然后只包含 我的新模块。

对于部署,我使用以下 symfony 任务

 php symfony project:deploy production -t

参数 -t 将包含在此 rsync 试运行中的所有文件打印到输出。

config/rsync_exclude.txt 的内容只有 *,因为我喜欢排除一切:

*

在 config/rsync_include.txt 我列出了所有包含的文件和文件夹:

config/
config/mysupermodule.yml
lib/model/doctrine/
lib/model/doctrine/MySuperclass.php
lib/model/doctrine/MySuperclassTable.php
lib/
lib/MySuperLibrary/
lib/MySuperLibrary/*

symfony 任务构建以下 rsync 命令:

rsync --dry-run -azC --force --delete --progress --exclude-from=config/rsync_exclude.txt --include-from=config/rsync_include.txt -e "ssh -p22" ./ user@www.server.com:/test_deployment/

问题一:任务没有同步任何文件。

解决方案 1:更改顺序:先包含,然后排除。

我发现,如果我改变我的需求:

我想包含我的新模块的所有文件,然后排除所有 其他。

这意味着使用以下命令:

rsync --dry-run -azC --force --delete --progress --include-from=config/rsync_include.txt --exclude-from=config/rsync_exclude.txt -e "ssh -p22" ./ user@www.server.com:/test_deployment/

rsync 有效。

问题2:使用symfony任务时如何改变rsync的顺序? symfony 任务首先排除而不是包含。

解决方案 2:?

【问题讨论】:

    标签: deployment symfony1 task rsync


    【解决方案1】:

    这是不可能的。

    但您可以在lib/task/project/sfProjectDeployTask.class.php 中编辑部署任务。

    替换这个(SF 1.4 中的第 145 到 154 行):

      if (file_exists($options['rsync-dir'].'/rsync_exclude.txt'))
      {
        $parameters .= sprintf(' --exclude-from=%s/rsync_exclude.txt', $options['rsync-dir']);
      }
    
      if (file_exists($options['rsync-dir'].'/rsync_include.txt'))
      {
        $parameters .= sprintf(' --include-from=%s/rsync_include.txt', $options['rsync-dir']);
      }
    

    用这个:

      if (file_exists($options['rsync-dir'].'/rsync_include.txt'))
      {
        $parameters .= sprintf(' --include-from=%s/rsync_include.txt', $options['rsync-dir']);
      }
    
      if (file_exists($options['rsync-dir'].'/rsync_exclude.txt'))
      {
        $parameters .= sprintf(' --exclude-from=%s/rsync_exclude.txt', $options['rsync-dir']);
      }
    

    简而言之:切换这两个 IF 语句。

    【讨论】:

    • 谢谢,我之前也做过这个,但实际上我并不想碰课堂。好答案!
    • 我不能投票,声望不够。但我认为,这是因为在框架中更改文件的提议不是正确的方法。我将扩展类 sfProjectDeployTask 并在此处实现更改。无论如何,这个想法是正确的,答案也是正确的。
    【解决方案2】:

    让我们改变你想做的方式。 您应该只使用排除文件。仅排除已更改但您不想同步的目录。

    因为无论如何,如果您的 modules/、app/、... 目录没有改变,您不必将它们放在排除文件中,因为它们在两台服务器上都将保持不变。

    【讨论】:

      猜你喜欢
      • 2011-06-20
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2013-07-17
      • 1970-01-01
      相关资源
      最近更新 更多