dev-master
9999999-dev https://github.com/BR0kEN-/deploy-revisionDeploy new code revision by performing operations from YAML playbooks.
MIT
The Requires
The Development Requires
php yaml deploy revision
Wallogit.com
2017 © Pedro Peláez
Deploy new code revision by performing operations from YAML playbooks.
Create a YAML playbook, define a code revision, specify upgrade path as commands for performing and distribute them between environments., (*1)
composer require deploy/deploy-revision:1.*
A view of deployment playbook., (*3)
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
Initialize the library at start., (*4)
require_once 'vendor/autoload.php'; use DeployRevision\DeployRevision; $deploy = new DeployRevision();
Use own YAML parser (if don't like Symfony)., (*5)
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);
Look for *.yml playbooks inside a directory and for tasks in particular file., (*6)
$deployment = $deploy->getWorker();
// Read particular playbook.
$deployment->read('../lush_deploy.yml');
// Read playbooks within directory.
$deployment->read('../lush_deploy');
Set an environment ID and/or path to file where revision ID should be stored (or duplicated, from DB for instance)., (*7)
$deployment = $deploy->getWorker('lush_website_at', 'private://revisions/revision');
Filter commands. Callback should return the command for deletion., (*8)
$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']);
});
Run deployment., (*9)
$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);
}
});
Save new revision ID., (*10)
$deployment->commit();
Tasks collected in order you running the ->read() method. If you are reading test1.yml and test2.yml and both files have the same revision number inside, then commands from first file will be located above ones from second., (*11)
Reading of the directory will be done in alphabetical order. If multiple playbooks have the same revision numbers, then the only way you can affect on ordering - is to set file names in correct order., (*12)
Run PHPUnit tests locally., (*13)
./bin/phpunit --coverage-text
Used for generating tests coverage., (*14)
Used for running tests on various PHP versions., (*15)
Used for verifying coding standards. Actually Scrutinizer doing this as well., (*16)
Deploy new code revision by performing operations from YAML playbooks.
MIT
php yaml deploy revision