deploy / deploy-revision
通过执行 YAML 操演本执行操作来部署新的代码版本。
dev-master
2017-02-11 11:07 UTC
Requires
- php: >=5.5.9
- symfony/config: 2.*
- symfony/dependency-injection: 2.*
- symfony/yaml: 2.*
Requires (Dev)
- mustangostang/spyc: 0.*
- phpunit/phpunit: 4 - 5
This package is auto-updated.
Last update: 2024-09-10 21:26:27 UTC
README
创建 YAML 操演本,定义代码版本,指定升级路径为执行命令,并在不同环境中分发。
安装
composer require deploy/deploy-revision:1.*
用法
部署操演本视图。
commands: # Commands below will be executed only if environment ID will match. lush_website_at: 140: - "drush updb" # It's predefined namespace for commands which should be run everywhere. global: 89: - "drush cc all" 121: - "drush cc drush" - "print bla bla" # The order of commands for execution will looks like (only in case if current code version is lower than defined): # - For "lush_website_at" environment: # - drush cc all - will be removed because we have "drush updb" (if logic like in "filter()" below will be implemented). # - drush cc drush # - print bla bla # - drush updb # # - For "global" environment: # - drush cc all # - drush cc drush # - print bla bla
启动时初始化库。
require_once 'vendor/autoload.php'; use DeployRevision\DeployRevision; $deploy = new DeployRevision();
使用自有的 YAML 解析器(如果不喜欢 Symfony)。
class SpycYaml implements YamlInterface { /** * {@inheritdoc} */ public function isAvailable() { return class_exists('Spyc'); } /** * {@inheritdoc} */ public function parse($content) { return \Spyc::YAMLLoadString($content); } /** * {@inheritdoc} */ public function dump(array $content) { return \Spyc::YAMLDump($content); } } $deploy ->getContainer() ->getDefinition('deploy_revision.yaml') ->setClass(SpycYaml::class);
在目录内查找 *.yml
操演本,并查找特定文件中的任务。
$deployment = $deploy->getWorker(); // Read particular playbook. $deployment->read('../lush_deploy.yml'); // Read playbooks within directory. $deployment->read('../lush_deploy');
设置环境 ID 和/或存储修订 ID 的文件路径(或从数据库等处复制)。
$deployment = $deploy->getWorker('lush_website_at', 'private://revisions/revision');
过滤命令。回调应返回要删除的命令。
$deployment->filter(function ($command, array $commands, callable $resolver) { // Remove "drush cc css-js" since "drush updb" will do the job for it. if ('drush cc css-js' === $command && isset($commands['drush updb'])) { return $command; } // Remove all previously added "drush cc all" from the list if "drush updb" exists. return $resolver(true, ['drush updb'], ['drush cc all']) // Remove newly added "drush cc all" if "drush updb" in the list. ?: $resolver(false, ['drush cc all'], ['drush updb']); });
运行部署。
$deployment->deploy(function ($command) { $arguments = explode(' ', $command); $program = array_shift($arguments); switch ($program) { case 'drush': drush_invoke($program, $arguments); break; default: printf('No handler found for the "%s" command.', $command); } });
保存新的修订 ID。
$deployment->commit();
注意
-
所有来自操演本的任务必须在部署回调中处理。这意味着必须完成识别命令和执行它们的实现。否则,将无法在操演本中放置命令并产生任何效果。
-
按照您运行
->read()
方法时的顺序收集任务。如果您正在读取test1.yml
和test2.yml
,并且两个文件中都有相同的修订号,则来自第一个文件的命令将位于第二个文件的命令之上。目录的读取将按照字母顺序进行。如果有多个操演本具有相同的修订号,那么唯一可以影响排序的方式是设置文件名的正确顺序。
测试
本地运行 PHPUnit 测试。
./bin/phpunit --coverage-text
Scrutinizer CI
用于生成 测试覆盖率。
Travis CI
用于在不同的 PHP 版本 上运行测试。
Style CI
用于验证 编码标准。实际上 Scrutinizer 也做这件事。