diff --git a/Mage/Config.php b/Mage/Config.php index 454d681..2260e1a 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -40,28 +40,36 @@ class Mage_Config return $hosts; } - public function getTasks($type = 'tasks') + public function getTasks($stage = 'on-deploy') { - switch ($type) { - case 'pre': - $type = 'pre-tasks'; + switch ($stage) { + case 'pre-deploy': + $type = 'tasks'; + $stage = 'pre-deploy'; break; - case 'post': - $type = 'post-tasks'; + case 'post-deploy': + $type = 'tasks'; + $stage = 'post-deploy'; break; - case 'tasks': + case 'post-release': + $type = 'releases'; + $stage = 'post-release'; + break; + + case 'on-deploy': default: $type = 'tasks'; + $stage = 'on-deploy'; break; } $tasks = array(); $config = $this->getEnvironment(); - if (isset($config[$type])) { - $tasks = (array) $config[$type]; + if (isset($config[$type]) && isset($config[$type][$stage])) { + $tasks = (array) $config[$type][$stage]; } return $tasks; diff --git a/Mage/Task/Add.php b/Mage/Task/Add.php index c5d73db..c0a3469 100644 --- a/Mage/Task/Add.php +++ b/Mage/Task/Add.php @@ -13,15 +13,17 @@ class Mage_Task_Add Mage_Console::output('Error!! Already exists an environment called ' . $environmentName . '', 1, 2); } else { $baseConfig = '#' . $environmentName . PHP_EOL - . 'user: dummy' . PHP_EOL - . 'deploy-from: ./' . PHP_EOL - . 'deploy-to: /var/www/vhosts/example.com/www' . PHP_EOL - . 'rsync-excludes:' . PHP_EOL + . 'deployment:' + . ' user: dummy' . PHP_EOL + . ' from: ./' . PHP_EOL + . ' to: /var/www/vhosts/example.com/www' . PHP_EOL + . ' excludes:' . PHP_EOL . 'hosts:' . PHP_EOL - . 'pre-tasks:' . PHP_EOL - . 'tasks:' . PHP_EOL - . ' - deployment/rsync' . PHP_EOL - . 'post-tasks:' . PHP_EOL; + . 'tasks:' + . ' pre-deploy:' . PHP_EOL + . ' on-deploy:' . PHP_EOL + . ' - deployment/rsync' . PHP_EOL + . ' post-deploy:' . PHP_EOL; $result = file_put_contents($environmentConfigFile, $baseConfig); if ($result) { diff --git a/Mage/Task/BuiltIn/Deployment/Rsync.php b/Mage/Task/BuiltIn/Deployment/Rsync.php index 4eeaa0f..bbc5359 100644 --- a/Mage/Task/BuiltIn/Deployment/Rsync.php +++ b/Mage/Task/BuiltIn/Deployment/Rsync.php @@ -25,14 +25,14 @@ class Mage_Task_BuiltIn_Deployment_Rsync ); // Look for User Excludes - if (isset($this->_config['deploy']['rsync-excludes'])) { - $userExcludes = (array) $this->_config['deploy']['rsync-excludes']; + if (isset($this->_config['deploy']['deployment']['excludes'])) { + $userExcludes = (array) $this->_config['deploy']['deployment']['excludes']; } else { $userExcludes = array(); } // If we are working with releases - $deployToDirectory = $this->_config['deploy']['deploy-to']; + $deployToDirectory = $this->_config['deploy']['deployment']['to']; if (isset($this->_config['deploy']['releases']['enabled'])) { if ($this->_config['deploy']['releases']['enabled'] == 'true') { if (isset($this->_config['deploy']['releases']['directory'])) { @@ -41,7 +41,7 @@ class Mage_Task_BuiltIn_Deployment_Rsync $releasesDirectory = 'releases'; } - $deployToDirectory = rtrim($this->_config['deploy']['deploy-to'], '/') + $deployToDirectory = rtrim($this->_config['deploy']['deployment']['to'], '/') . '/' . $releasesDirectory . '/' . $this->_config['deploy']['releases']['_id']; $this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config['deploy']['releases']['_id']); @@ -50,8 +50,8 @@ class Mage_Task_BuiltIn_Deployment_Rsync $command = 'rsync -avz ' . $this->_excludes(array_merge($excludes, $userExcludes)) . ' ' - . $this->_config['deploy']['deploy-from'] . ' ' - . $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $deployToDirectory; + . $this->_config['deploy']['deployment']['from'] . ' ' + . $this->_config['deploy']['deployment']['user'] . '@' . $this->_config['deploy']['host'] . ':' . $deployToDirectory; $result = $this->_runLocalCommand($command); diff --git a/Mage/Task/Deploy.php b/Mage/Task/Deploy.php index 43c409a..83b39f2 100644 --- a/Mage/Task/Deploy.php +++ b/Mage/Task/Deploy.php @@ -14,7 +14,7 @@ class Mage_Task_Deploy $this->_config = $config; // Run Pre-Deployment Tasks - $this->_runNonDeploymentTasks('pre', $config); + $this->_runNonDeploymentTasks('pre-deploy', $config, 'Pre-Deployment'); // Run Tasks for Deployment $hosts = $config->getHosts(); @@ -60,6 +60,8 @@ class Mage_Task_Deploy } } + // Run Post-Deployment Tasks + if ($completedTasks == $tasks) { $tasksColor = 'green'; } else { @@ -72,18 +74,18 @@ class Mage_Task_Deploy } // Run Post-Deployment Tasks - $this->_runNonDeploymentTasks('post', $config); + $this->_runNonDeploymentTasks('post-deploy', $config, 'Post-Deployment'); } - private function _runNonDeploymentTasks($type, Mage_Config $config) + private function _runNonDeploymentTasks($stage, Mage_Config $config, $title) { - $tasksToRun = $config->getTasks($type); + $tasksToRun = $config->getTasks($stage); if (count($tasksToRun) == 0) { - Mage_Console::output('No ' . ucfirst($type) . '-Deployment tasks defined.', 1, 3); + Mage_Console::output('No ' . $title . ' tasks defined.', 1, 3); } else { - Mage_Console::output('Starting ' . ucfirst($type) . '-Deployment tasks:'); + Mage_Console::output('Starting ' . $title . ' tasks:'); $taskConfig = $config->getConfig(); $tasks = 0; @@ -94,7 +96,7 @@ class Mage_Task_Deploy $task = Mage_Task_Factory::get($taskName, $taskConfig); $task->init(); - Mage_Console::output('Running ' . $task->getName() . ' ... ', 2, false); + Mage_Console::output('Running ' . $task->getName() . ' ... ', 2, 0); $result = $task->run(); if ($result == true) { @@ -111,7 +113,7 @@ class Mage_Task_Deploy $tasksColor = 'red'; } - Mage_Console::output('Finished ' . ucfirst($type) . '-Deployment tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); + Mage_Console::output('Finished ' . $title . ' tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); } diff --git a/Mage/Task/TaskAbstract.php b/Mage/Task/TaskAbstract.php index 14a66ac..80bb478 100644 --- a/Mage/Task/TaskAbstract.php +++ b/Mage/Task/TaskAbstract.php @@ -24,8 +24,8 @@ abstract class Mage_Task_TaskAbstract protected final function _runRemoteCommand($command) { $localCommand = 'ssh ' - . $this->_config['deploy']['user'] . '@' . $this->_config['deploy']['host'] . ' ' - . '"cd ' . $this->_config['deploy']['deploy-to'] . ' && ' + . $this->_config['deploy']['deployment']['user'] . '@' . $this->_config['deploy']['host'] . ' ' + . '"cd ' . $this->_config['deploy']['deployment']['to'] . ' && ' . $command . '"'; return $this->_runLocalCommand($localCommand); diff --git a/docs/example-config/.mage/config/environment/production.yaml b/docs/example-config/.mage/config/environment/production.yaml index b014783..f50bb40 100644 --- a/docs/example-config/.mage/config/environment/production.yaml +++ b/docs/example-config/.mage/config/environment/production.yaml @@ -1,21 +1,24 @@ #production -user: root -deploy-from: ./ -deploy-to: /var/www/vhosts/example.com/www +deployment: + user: root + from: ./ + to: /var/www/vhosts/example.com/www + excludes: + - application/data/cache/twig/* releases: enabled: true symlink: current directory: releases + tasks: hosts: - s01.example.com - s02.example.com - s03.example.com - s05.example.com -rsync-excludes: - - application/data/cache/twig/* -pre-tasks: - - scm/update tasks: - - deployment/rsync - - privileges -#post-tasks: \ No newline at end of file + pre-deploy: + - scm/update + on-deploy: + - deployment/rsync + - privileges + #post-deploy: \ 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 26874a5..7fb44e0 100644 --- a/docs/example-config/.mage/config/environment/staging.yaml +++ b/docs/example-config/.mage/config/environment/staging.yaml @@ -1,11 +1,14 @@ #staging -user: stg_example -deploy-from: application -deploy-to: /var/www/vhosts/example.com/staging +deployment: + user: stg_user + from: ./ + to: /var/www/vhosts/example.com/staging hosts: - staging.example.com -pre-tasks: - - scm/update tasks: - - deployment/rsync - - privileges \ No newline at end of file + pre-deploy: + - scm/update + on-deploy: + - deployment/rsync + - privileges + #post-deploy: \ No newline at end of file