Added PRE and POST Deploy tasks.

This commit is contained in:
Andrs Montaez 2011-11-23 22:25:20 -02:00
parent 49481e6a38
commit b5c8ab9c87
4 changed files with 73 additions and 6 deletions

View file

@ -32,10 +32,31 @@ class Mage_Config
return $config['hosts'];
}
public function getTasks()
public function getTasks($type = 'tasks')
{
switch ($type) {
case 'pre':
$type = 'pre-tasks';
break;
case 'post':
$type = 'post-tasks';
break;
case 'tasks':
default:
$type = 'tasks';
break;
}
$tasks = array();
$config = $this->getEnvironment();
return $config['tasks'];
if (isset($config[$type])) {
$tasks = (array) $config[$type];
}
return $tasks;
}
public function getConfig($host = false)

View file

@ -7,6 +7,10 @@ class Mage_Task_Deploy
{
$this->_config = $config;
// Run Pre-Deployment Tasks
$this->_runNonDeploymentTasks('pre', $config);
// Run Tasks for Deployment
foreach ($config->getHosts() as $host) {
$taskConfig = $config->getConfig($host);
$tasks = 0;
@ -38,6 +42,44 @@ class Mage_Task_Deploy
Mage_Console::output('Deployment to <dark_gray>' . $host . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.' . PHP_EOL . PHP_EOL);
}
// Run Post-Deployment Tasks
$this->_runNonDeploymentTasks('post', $config);
}
private function _runNonDeploymentTasks($type, Mage_Config $config)
{
Mage_Console::output('Starting <dark_gray>' . ucfirst($type) . '-Deployment</dark_gray> tasks:');
$taskConfig = $config->getConfig();
$tasks = 0;
$completedTasks = 0;
foreach ($config->getTasks($type) as $taskName) {
$tasks++;
$task = Mage_Task_Factory::get($taskName, $taskConfig);
$task->init();
Mage_Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
$result = $task->run();
if ($result == true) {
Mage_Console::output('<green>OK</green>');
$completedTasks++;
} else {
Mage_Console::output('<red>FAIL</red>');
}
}
if ($completedTasks == $tasks) {
$tasksColor = 'green';
} else {
$tasksColor = 'red';
}
Mage_Console::output('Finished <dark_gray>' . ucfirst($type) . '-Deployment</dark_gray> tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.' . PHP_EOL . PHP_EOL);
}
}

View file

@ -7,7 +7,9 @@ hosts:
- s02.example.com
- s03.example.com
- s05.example.com
tasks:
pre-tasks:
- scm/update
tasks:
- deployment/rsync
- privileges
- privileges
#post-tasks:

View file

@ -4,6 +4,8 @@ deploy-from: application
deploy-to: /var/www/vhosts/example.com/staging
hosts:
- staging.example.com
tasks:
pre-tasks:
- scm/update
- deployment/rsync
tasks:
- deployment/rsync
- privileges