如何修改symfony部署任务中rsync的顺序



我想部署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:任务没有同步任何文件

解决方案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任务首先排除而不是包含。

方案二:?

这是不可能的。

但是您可以在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语句交换

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

因为无论如何如果你modules/, app/,…目录没有改变,你不必把它们放在排除文件中,因为它们在两个服务器上保持不变。

最新更新