From d5ebf6e6e392cb737937a1f2756a6a1ea8388557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 2 Nov 2013 17:10:16 -0200 Subject: [PATCH] Deploy Summary info. Deploy lock: only run one instance at a time. --- Mage/Command/BuiltIn/Deploy.php | 47 +++++++++++++++++++++++++++++---- Mage/Console.php | 9 +++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Mage/Command/BuiltIn/Deploy.php b/Mage/Command/BuiltIn/Deploy.php index 1a828f4..b20bed7 100644 --- a/Mage/Command/BuiltIn/Deploy.php +++ b/Mage/Command/BuiltIn/Deploy.php @@ -25,17 +25,49 @@ class Mage_Command_BuiltIn_Deploy public function run() { + // Check if Environment is not Locked + $lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock'; + if (file_exists($lockFile)) { + Mage_Console::output('This environment is locked!', 1, 2); + return; + } + + // Check for running instance and Lock + if (file_exists('.mage/~working.lock')) { + Mage_Console::output('There is already an instance of Magallanes running!', 1, 2); + return; + } else { + touch('.mage/~working.lock'); + } + + // Release ID $this->getConfig()->setReleaseId(date('YmdHis')); $failedTasks = 0; - $this->_startTime = time(); + // Deploy Summary + Mage_Console::output('Deploy summary', 1, 1); + + // Deploy Summary - Environment + Mage_Console::output('Environment: ' . $this->getConfig()->getEnvironment() . '', 2, 1); - $lockFile = '.mage/' . $this->getConfig()->getEnvironment() . '.lock'; - if (file_exists($lockFile)) { - Mage_Console::output('This environment is locked!', 1, 2); - return; + // Deploy Summary - Releases + if ($this->getConfig()->release('enabled', false)) { + Mage_Console::output('Release ID: ' . $this->getConfig()->getReleaseId() . '', 2, 1); + } + + // Deploy Summary - SCM + if ($this->getConfig()->deployment('scm', false)) { + $scmConfig = $this->getConfig()->deployment('scm'); + if (isset($scmConfig['branch'])) { + Mage_Console::output('SCM Branch: ' . $scmConfig['branch'] . '', 2, 1); + } } + // Deploy Summary - Separator Line + Mage_Console::output('', 0, 1); + + $this->_startTime = time(); + // Run Pre-Deployment Tasks $this->_runNonDeploymentTasks('pre-deploy', $this->getConfig(), 'Pre-Deployment'); @@ -168,6 +200,11 @@ class Mage_Command_BuiltIn_Deploy // Send Notifications $this->_sendNotification(); + + // Unlock + if (file_exists('.mage/~working.lock')) { + unlink('.mage/~working.lock'); + } } /** diff --git a/Mage/Console.php b/Mage/Console.php index bcebd76..63198e8 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -12,6 +12,15 @@ class Mage_Console */ public function run($arguments) { + register_shutdown_function(function() { + // Only Unlock if there was an error + if (error_get_last() !== null) { + if (file_exists('.mage/~working.lock')) { + unlink('.mage/~working.lock'); + } + } + }); + $configError = false; try { // Load Config