From 8e603bd0d268d5bd4a0c412e4de8dc6aa20dd5db Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 00:13:19 +0400 Subject: [PATCH 1/4] fixed bug with a env-configuration containing deployment description in hosts section --- Mage/Command/BuiltIn/DeployCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 943a630..7ee5235 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -439,13 +439,22 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } else { $result = true; - foreach ($hosts as $host) { - $this->getConfig()->setHost($host); + foreach ($hosts as $hostKey => $host) { + $hostConfig = null; + if (is_array($host)) { + $hostConfig = $host; + $host = $hostKey; + } + // Set Host and Host Specific Config + $this->getConfig()->setHost($host); + $this->getConfig()->setHostConfig($hostConfig); $this->getConfig()->setReleaseId(-1); + $task = Factory::get('releases/rollback', $this->getConfig()); $task->init(); $result = $task->run() && $result; + } return $result; } From db4b4299c2abac6b09e341f10321899631b6263d Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 02:07:20 +0400 Subject: [PATCH 2/4] added rollback delete default option from yaml configs --- Mage/Task/BuiltIn/Releases/RollbackTask.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 7a437fd..2d798b1 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -60,7 +60,11 @@ class RollbackTask extends AbstractTask implements IsReleaseAware } else { rsort($releases); - $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent', false); + $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent', + $this->getConfig()->deployment('delete-on-rollback', + $this->getConfig()->general('delete-on-rollback',false) + ) + ); $releaseIsAvailable = false; if ($this->getReleaseId() == '') { From 5eb26748ab182fbd00b8efd26fa55cece4b8dbdb Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 16:40:02 +0400 Subject: [PATCH 3/4] added restriction to run the rollback. small changes at rollback output. --- Mage/Command/BuiltIn/DeployCommand.php | 34 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 7ee5235..e4e2a78 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -59,6 +59,15 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment */ const IN_PROGRESS = 'in_progress'; + /** + * Stage where possible throw Rollback Exception + * @var array + */ + public $acceptedStagesToRollback = array( + AbstractTask::STAGE_POST_RELEASE, + AbstractTask::STAGE_POST_DEPLOY + ); + /** * Time the Deployment has Started * @var integer @@ -430,11 +439,19 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } } - protected function runRollbackTask(){ + protected function runRollbackTask(AbstractTask $task){ $this->getConfig()->reload(); $hosts = $this->getConfig()->getHosts(); - if (count($hosts) == 0) { + Console::output("",1,2); + Console::output("Starting the rollback",1,1); + + if(!in_array($task->getStage(), $this->acceptedStagesToRollback ) ) { + $stagesString = implode(', ',$this->acceptedStagesToRollback); + Console::output("Warning! Rollback during deployment can be called only at the stages: $stagesString ",1); + Console::output("Rollback: ABORTING",1,3); + + } elseif (count($hosts) == 0) { Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); } else { @@ -451,7 +468,14 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $this->getConfig()->setHostConfig($hostConfig); $this->getConfig()->setReleaseId(-1); - $task = Factory::get('releases/rollback', $this->getConfig()); + $task = Factory::get(array( + 'name'=>'releases/rollback', + 'parameters' => array('inDeploy'=>true) + ), + $this->getConfig(), + false, + $task->getStage() + ); $task->init(); $result = $task->run() && $result; @@ -495,8 +519,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $result = false; } } catch (RollbackException $e) { - Console::output('FAIL, Rollback started [Message: ' . $e->getMessage() . ']', 0); - $this->runRollbackTask(); + Console::output('FAIL, Rollback catched [Message: ' . $e->getMessage() . ']', 0); + $this->runRollbackTask($task); $result = false; } catch (ErrorWithMessageException $e) { From a632dac80ae827caeb086d54811436dce03db26c Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 16:47:52 +0400 Subject: [PATCH 4/4] added in-deploy flag @ rollback task. --- Mage/Task/BuiltIn/Releases/RollbackTask.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 2d798b1..1de9831 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -55,6 +55,8 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output); $releases = ($output == '') ? array() : explode(PHP_EOL, $output); + $inDeploy = $this->getParameter('inDeploy',false); + if (count($releases) == 0) { Console::output('Release are not available for ' . $this->getConfig()->getHost() . ' ... FAIL');