diff --git a/Mage/Config.php b/Mage/Config.php index 9fce95a..9e4b732 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -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) diff --git a/Mage/Task/Deploy.php b/Mage/Task/Deploy.php index 6a4b230..d9d4aab 100644 --- a/Mage/Task/Deploy.php +++ b/Mage/Task/Deploy.php @@ -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 ' . $host . ' compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' 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 ' . ucfirst($type) . '-Deployment 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 ' . $task->getName() . ' ... ', 2, false); + $result = $task->run(); + + if ($result == true) { + Mage_Console::output('OK'); + $completedTasks++; + } else { + Mage_Console::output('FAIL'); + } + } + + if ($completedTasks == $tasks) { + $tasksColor = 'green'; + } else { + $tasksColor = 'red'; + } + + Mage_Console::output('Finished ' . ucfirst($type) . '-Deployment tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.' . PHP_EOL . PHP_EOL); + + } + + } \ No newline at end of file diff --git a/docs/example-config/.mage/config/environment/production.yaml b/docs/example-config/.mage/config/environment/production.yaml index 1599f2e..c5e8734 100644 --- a/docs/example-config/.mage/config/environment/production.yaml +++ b/docs/example-config/.mage/config/environment/production.yaml @@ -7,7 +7,9 @@ hosts: - s02.example.com - s03.example.com - s05.example.com -tasks: +pre-tasks: - scm/update +tasks: - deployment/rsync - - privileges \ No newline at end of file + - privileges +#post-tasks: \ No newline at end of file diff --git a/docs/example-config/.mage/config/environment/staging.yaml b/docs/example-config/.mage/config/environment/staging.yaml index a798aea..26874a5 100644 --- a/docs/example-config/.mage/config/environment/staging.yaml +++ b/docs/example-config/.mage/config/environment/staging.yaml @@ -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 \ No newline at end of file +tasks: + - deployment/rsync + - privileges \ No newline at end of file