From a4548cb04cafb8eb721479da9456982154d0fac2 Mon Sep 17 00:00:00 2001 From: Denis Denisov Date: Wed, 1 Oct 2014 07:49:46 +0300 Subject: [PATCH 01/34] Add a box.json file to build PHAR --- .gitignore | 1 + box.json | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 box.json diff --git a/.gitignore b/.gitignore index 5dc363a..ba0c30d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .buildpath .idea vendor +mage.phar # OS generated files # // GitHub Recommendation ###################### diff --git a/box.json b/box.json new file mode 100644 index 0000000..cc32edb --- /dev/null +++ b/box.json @@ -0,0 +1,16 @@ +{ + "files": ["LICENSE"], + "finder": [ + { + "name": "*.php", + "exclude": [ + "docs" + ], + "in": "Mage" + } + ], + "git-version": "git_tag", + "main": "bin/mage", + "output": "mage.phar", + "stub": true +} From e0430cfb68e2f28577b39bad9145022b3c170847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Dronga?= Date: Wed, 8 Oct 2014 15:22:08 +0300 Subject: [PATCH 02/34] built-in task for doctrine migrations --- .../Task/BuiltIn/Symfony2/DoctrineMigrate.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php diff --git a/Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php b/Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php new file mode 100644 index 0000000..b76633d --- /dev/null +++ b/Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php @@ -0,0 +1,40 @@ + +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ + +namespace Mage\Task\BuiltIn\Symfony2; + +use Mage\Task\BuiltIn\Symfony2\SymfonyAbstractTask; + +/** + * Task for Doctrine migrations + */ +class DoctrineMigrate extends SymfonyAbstractTask +{ + /** + * (non-PHPdoc) + * @see \Mage\Task\AbstractTask::getName() + */ + public function getName() + { + return 'Symfony v2 - Migrate doctrine entities [built-in]'; + } + + /** + * Migrates Doctrine entities + * + * @see \Mage\Task\AbstractTask::run() + */ + public function run() + { + $env = $this->getParameter('env', 'dev'); + $command = $this->getAppPath() . ' doctrine:migrations:migrate -n --env=' . $env; + return $this->runCommand($command); + } +} From dfbe67622d56fba1d5a3d9182e48d09a97bf9c96 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Fri, 10 Oct 2014 21:04:47 +0200 Subject: [PATCH 03/34] Throw an error in case when command returns code other than 0 --- Mage/Console.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Mage/Console.php b/Mage/Console.php index 1173354..4ba4b3a 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -120,7 +120,7 @@ class Console } } - + $exceptionOccured = false; // Run Command - Check if there is a Configuration Error if ($configError !== false) { self::output('' . $configError . '', 1, 2); @@ -136,7 +136,12 @@ class Console } } $exitCode = $command->run(); - + if (is_int($exitCode) && $exitCode !== 0) { + throw new Exception("Command execution failed with following exit code: $exitCode.", $exitCode); + } elseif (is_bool($exitCode) && !$exitCode) { + $exitCode = 1000; + throw new Exception("Command execution failed.", $exitCode); + } } catch (Exception $exception) { self::output('' . $exception->getMessage() . '', 1, 2); } From 0375a80dcf4759a8bcbbe8751056482fa8fb6870 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Fri, 10 Oct 2014 21:20:21 +0200 Subject: [PATCH 04/34] Fix exit code to 1 due to php exit code that cannot be greater than 254 --- Mage/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Console.php b/Mage/Console.php index 4ba4b3a..83ce6cb 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -139,7 +139,7 @@ class Console if (is_int($exitCode) && $exitCode !== 0) { throw new Exception("Command execution failed with following exit code: $exitCode.", $exitCode); } elseif (is_bool($exitCode) && !$exitCode) { - $exitCode = 1000; + $exitCode = 1; throw new Exception("Command execution failed.", $exitCode); } } catch (Exception $exception) { From 7a9495cf44d02f281b06dcfba8b611b27397d737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 12:10:07 -0200 Subject: [PATCH 05/34] Issue #130 --- Mage/Console.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Mage/Console.php b/Mage/Console.php index 83ce6cb..6f55e8b 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -135,12 +135,16 @@ class Console throw new Exception('You must specify an environment for this command.'); } } + + // Run the Command $exitCode = $command->run(); + + // Check for errors if (is_int($exitCode) && $exitCode !== 0) { - throw new Exception("Command execution failed with following exit code: $exitCode.", $exitCode); + throw new Exception('Command execution failed with following exit code: ' . $exitCode, $exitCode); } elseif (is_bool($exitCode) && !$exitCode) { $exitCode = 1; - throw new Exception("Command execution failed.", $exitCode); + throw new Exception('Command execution failed.', $exitCode); } } catch (Exception $exception) { self::output('' . $exception->getMessage() . '', 1, 2); From b61e7149d0c15d72b654d84c9bca46e92c14f1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:30:29 -0200 Subject: [PATCH 06/34] Yaml tweaks. --- docs/example-config/.mage/config/environment/ioncube.yml | 4 ++-- .../example-config/.mage/config/environment/production.yml | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/example-config/.mage/config/environment/ioncube.yml b/docs/example-config/.mage/config/environment/ioncube.yml index da001d8..e2a0848 100644 --- a/docs/example-config/.mage/config/environment/ioncube.yml +++ b/docs/example-config/.mage/config/environment/ioncube.yml @@ -27,8 +27,8 @@ ioncube: encoder: ioncube_encoder54 checkencoding: true checkignorepaths: - -/public/js/* - -/public/css/* + - /public/js/* + - /public/css/* projfile: project.prj project: diff --git a/docs/example-config/.mage/config/environment/production.yml b/docs/example-config/.mage/config/environment/production.yml index e785fe0..e1cbe81 100644 --- a/docs/example-config/.mage/config/environment/production.yml +++ b/docs/example-config/.mage/config/environment/production.yml @@ -16,9 +16,7 @@ releases: symlink: current directory: releases hosts: - s01.example.com:22: - deployment: - user: nobody + - s01.example.com s02.example.com: deployment: user: toor @@ -28,12 +26,11 @@ hosts: tasks: on-deploy: - privileges - - s03.example.com tasks: pre-deploy: - scm/update on-deploy: -# - symfony2/cache-warmup: {env: prod} + - symfony2/cache-warmup: { env: prod } - privileges - sampleTask - sampleTaskRollbackAware From 5d39e46d9e957600b381da2082d7d817d6228449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:36:22 -0200 Subject: [PATCH 07/34] Code should not be duplicated --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 2 +- .../Strategy/GitRemoteCacheTask.php | 35 ++----------------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index bf42643..e44c5d8 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -133,7 +133,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; if ($directoryToDelete != '/') { $command = 'rm -rf ' . $directoryToDelete; - $this->runCommandRemote($command); + $result = $result && $this->runCommandRemote($command); } } } diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php index 43296c3..fd0869f 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php @@ -97,39 +97,8 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware $command = 'cd ' . $remoteCacheFolder . ' && /usr/bin/env git archive ' . $branch . ' | tar -x -C ' . $deployToDirectory . ' ' . $excludeCmd; $result = $this->runCommandRemote($command) && $result; - // Count Releases - if ($this->getConfig()->release('enabled', false) == true) { - $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - $symlink = $this->getConfig()->release('symlink', 'current'); - - if (substr($symlink, 0, 1) == '/') { - $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; - } - - $maxReleases = $this->getConfig()->release('max', false); - if (($maxReleases !== false) && ($maxReleases > 0)) { - $releasesList = ''; - $countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList); - $releasesList = trim($releasesList); - - if ($countReleasesFetch && $releasesList != '') { - $releasesList = explode(PHP_EOL, $releasesList); - if (count($releasesList) > $maxReleases) { - $releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId())); - sort($releasesToDelete); - $releasesToDeleteCount = count($releasesToDelete) - $maxReleases; - $releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1); - - foreach ($releasesToDelete as $releaseIdToDelete) { - $directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; - if ($directoryToDelete != '/') { - $command = 'rm -rf ' . $directoryToDelete; - $result = $result && $this->runCommandRemote($command); - } - } - } - } - } + if ($result) { + $this->cleanUpReleases(); } return $result; From f20091afc6ef42fad883d7ca07f674dcc6dc22dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:43:57 -0200 Subject: [PATCH 08/34] Boolean and Null should be compared strictly. --- Mage/Command/BuiltIn/DeployCommand.php | 10 +++++----- Mage/Command/BuiltIn/UpdateCommand.php | 2 +- Mage/Console.php | 4 ++-- Mage/Task/AbstractTask.php | 4 ++-- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 4 ++-- .../Deployment/Strategy/BaseStrategyTaskAbstract.php | 2 +- .../BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php | 4 ++-- Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php | 6 +++--- Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 6 +++--- Mage/Task/BuiltIn/Releases/ListTask.php | 2 +- Mage/Task/BuiltIn/Releases/RollbackTask.php | 6 +++--- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index d1888b3..3719c49 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -356,7 +356,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } // Releasing - if (self::$deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) == true) { + if (self::$deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) === true) { // Execute the Releases Console::output('Starting the Releasing'); $completedTasks = 0; @@ -439,7 +439,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment { $task->init(); - if ($title == null) { + if ($title === null) { $title = 'Running ' . $task->getName() . ' ... '; } Console::output($title, 2, 0); @@ -449,11 +449,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $runTask = false; } - if ($runTask == true) { + if ($runTask === true) { try { $result = $task->run(); - if ($result == true) { + if ($result === true) { Console::output('OK', 0); $result = true; @@ -564,7 +564,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment case self::DEPLOY_STRATEGY_GUESS: default: - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $deployStrategy = 'deployment/strategy/tar-gz'; } else { $deployStrategy = 'deployment/strategy/rsync'; diff --git a/Mage/Command/BuiltIn/UpdateCommand.php b/Mage/Command/BuiltIn/UpdateCommand.php index 9cba1cb..7fa6461 100644 --- a/Mage/Command/BuiltIn/UpdateCommand.php +++ b/Mage/Command/BuiltIn/UpdateCommand.php @@ -35,7 +35,7 @@ class UpdateCommand extends AbstractCommand Console::output('Updating application via ' . $task->getName() . ' ... ', 1, 0); $result = $task->run(); - if ($result == true) { + if ($result === true) { Console::output('OK' . PHP_EOL, 0); $exitCode = 0; diff --git a/Mage/Console.php b/Mage/Console.php index 6f55e8b..f1d7609 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -131,7 +131,7 @@ class Console $command = Factory::get($commandName, $config); if ($command instanceOf RequiresEnvironment) { - if ($config->getEnvironment() == false) { + if ($config->getEnvironment() === false) { throw new Exception('You must specify an environment for this command.'); } } @@ -222,7 +222,7 @@ class Console public static function log($message) { if (self::$logEnabled) { - if (self::$log == null) { + if (self::$log === null) { self::$logFile = realpath(getcwd() . '/.mage/logs') . '/log-' . date('Ymd-His') . '.log'; self::$log = fopen(self::$logFile, 'w'); } diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index c61f87d..bc12f5f 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -181,7 +181,7 @@ abstract class AbstractTask */ protected final function runCommandRemote($command, &$output = null, $cdToDirectoryFirst = true) { - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { if ($this instanceOf IsReleaseAware) { $releasesDirectory = ''; @@ -238,7 +238,7 @@ abstract class AbstractTask */ protected function getReleasesAwareCommand($command) { - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index e44c5d8..ceeab5f 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -37,7 +37,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride public function run() { $resultFetch = false; - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $symlink = $this->getConfig()->release('symlink', 'current'); @@ -107,7 +107,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride protected function cleanUpReleases() { // Count Releases - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $symlink = $this->getConfig()->release('symlink', 'current'); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php b/Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php index 5affe97..9e787c7 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php @@ -30,7 +30,7 @@ abstract class BaseStrategyTaskAbstract extends AbstractTask implements IsReleas $overrideRelease = $this->getParameter('overrideRelease', false); $symlink = $this->getConfig()->release('symlink', 'current'); - if ($overrideRelease == true) { + if ($overrideRelease === true) { $releaseToOverride = false; $resultFetch = $this->runCommandRemote('ls -ld ' . $symlink . ' | cut -d"/" -f2', $releaseToOverride); if ($resultFetch && is_numeric($releaseToOverride)) { diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php index fd0869f..3934e48 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/GitRemoteCacheTask.php @@ -42,7 +42,7 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware { $overrideRelease = $this->getParameter('overrideRelease', false); - if ($overrideRelease == true) { + if ($overrideRelease === true) { $releaseToOverride = false; $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride); if ($resultFetch && is_numeric($releaseToOverride)) { @@ -63,7 +63,7 @@ class GitRemoteCacheTask extends AbstractTask implements IsReleaseAware $userExcludes = $this->getConfig()->deployment('excludes', array()); $deployToDirectory = $this->getConfig()->deployment('to'); - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/') diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index c4c92ad..b7ee1b5 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -27,8 +27,8 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware */ public function getName() { - if ($this->getConfig()->release('enabled', false) == true) { - if ($this->getConfig()->getParameter('overrideRelease', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { + if ($this->getConfig()->getParameter('overrideRelease', false) === true) { return 'Deploy via Rsync (with Releases override) [built-in]'; } else { $rsync_copy = $this->getConfig()->deployment("rsync"); @@ -55,7 +55,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $symlink = $this->getConfig()->release('symlink', 'current'); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index 2077eb7..5607a5d 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -27,8 +27,8 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware */ public function getName() { - if ($this->getConfig()->release('enabled', false) == true) { - if ($this->getConfig()->getParameter('overrideRelease', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { + if ($this->getConfig()->getParameter('overrideRelease', false) === true) { return 'Deploy via TarGz (with Releases override) [built-in]'; } else { return 'Deploy via TarGz (with Releases) [built-in]'; @@ -50,7 +50,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory diff --git a/Mage/Task/BuiltIn/Releases/ListTask.php b/Mage/Task/BuiltIn/Releases/ListTask.php index ef88004..3d76327 100644 --- a/Mage/Task/BuiltIn/Releases/ListTask.php +++ b/Mage/Task/BuiltIn/Releases/ListTask.php @@ -34,7 +34,7 @@ class ListTask extends AbstractTask implements IsReleaseAware */ public function run() { - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $symlink = $this->getConfig()->release('symlink', 'current'); diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 759c042..eee33c3 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -47,7 +47,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware */ public function run() { - if ($this->getConfig()->release('enabled', false) == true) { + if ($this->getConfig()->release('enabled', false) === true) { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $symlink = $this->getConfig()->release('symlink', 'current'); @@ -111,7 +111,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $tasks++; $result = $task->run(); - if ($result == true) { + if ($result === true) { Console::output('OK', 0); $completedTasks++; } else { @@ -161,7 +161,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $tasks++; $result = $task->run(); - if ($result == true) { + if ($result === true) { Console::output('OK', 0); $completedTasks++; } else { From dbcbcb78ed91a7a78166acd77535bc7fb0b1d488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:44:48 -0200 Subject: [PATCH 09/34] Remove error suppression. --- Mage/Mailer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Mailer.php b/Mage/Mailer.php index e0b3443..fadf48a 100644 --- a/Mage/Mailer.php +++ b/Mage/Mailer.php @@ -84,6 +84,6 @@ class Mailer . $attachment . self::EOL . '--Mage-mixed-' . $boundary . '--' . self::EOL; - @mail($this->address, $subject, $message, $headers); + mail($this->address, $subject, $message, $headers); } } \ No newline at end of file From b8c23747f07ca5310ed1f21c12f93af95c160881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:53:38 -0200 Subject: [PATCH 10/34] User specific files should not appear in .gitignore --- .gitignore | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.gitignore b/.gitignore index ba0c30d..6964198 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,3 @@ -.settings -.settings/* -.project -.buildpath -.idea vendor mage.phar From aaf92d5001888dd125f2706ca0861bbd8bb91f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 14:54:45 -0200 Subject: [PATCH 11/34] Commented code should not be commited. --- docs/example-config/.mage/tasks/TaskWithParameters.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/example-config/.mage/tasks/TaskWithParameters.php b/docs/example-config/.mage/tasks/TaskWithParameters.php index bf99deb..967fcfb 100644 --- a/docs/example-config/.mage/tasks/TaskWithParameters.php +++ b/docs/example-config/.mage/tasks/TaskWithParameters.php @@ -18,8 +18,10 @@ class TaskWithParameters extends AbstractTask public function run() { - //throw new Mage_Task_SkipException; - //return false; - return true; + if ($this->getParameter('booleanOption', false)) { + return true; + } else { + return false; + } } } \ No newline at end of file From 9653552be76ae4df215f0901d4089c25da2efb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 15:07:36 -0200 Subject: [PATCH 12/34] Text files should end with a newline character. --- .gitignore | 2 +- LICENSE | 2 +- LICENSE_YAML | 2 +- Mage/Command/AbstractCommand.php | 2 +- Mage/Command/BuiltIn/InstallCommand.php | 2 +- Mage/Command/BuiltIn/UpdateCommand.php | 3 +-- Mage/Command/BuiltIn/VersionCommand.php | 3 +-- Mage/Command/Factory.php | 2 +- Mage/Command/RequiresEnvironment.php | 2 +- Mage/Mailer.php | 2 +- Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php | 3 +-- Mage/Task/BuiltIn/Magento/ClearCacheTask.php | 2 +- Mage/Task/BuiltIn/Magento/ClearFullPageCacheTask.php | 2 +- Mage/Task/BuiltIn/Releases/ListTask.php | 3 +-- Mage/Task/BuiltIn/Releases/RollbackTask.php | 3 +-- Mage/Task/BuiltIn/Scm/ChangeBranchTask.php | 2 +- Mage/Task/BuiltIn/Scm/CloneTask.php | 2 +- Mage/Task/BuiltIn/Scm/RemoveCloneTask.php | 2 +- Mage/Task/BuiltIn/Scm/UpdateTask.php | 2 +- Mage/Task/BuiltIn/Symfony2/AsseticDumpTask.php | 2 +- Mage/Task/BuiltIn/Symfony2/AssetsInstallTask.php | 2 +- Mage/Task/BuiltIn/Symfony2/CacheClearTask.php | 2 +- Mage/Task/BuiltIn/Symfony2/SymfonyAbstractTask.php | 2 +- Mage/Task/SkipException.php | 2 +- Mage/Yaml/Dumper.php | 2 +- Mage/Yaml/Escaper.php | 2 +- Mage/Yaml/Exception/DumpException.php | 2 +- Mage/Yaml/Exception/ExceptionInterface.php | 2 +- Mage/Yaml/Exception/ParseException.php | 2 +- Mage/Yaml/Exception/RuntimeException.php | 2 +- Mage/Yaml/Inline.php | 2 +- Mage/Yaml/Parser.php | 3 +-- Mage/Yaml/Unescaper.php | 2 +- Mage/Yaml/Yaml.php | 2 +- docs/example-config/.mage/config/environment/production.yml | 2 +- docs/example-config/.mage/config/general.yml | 2 +- docs/example-config/.mage/logs/.gitignore | 2 +- docs/example-config/.mage/tasks/FailTask.php | 2 +- docs/example-config/.mage/tasks/Privileges.php | 2 +- docs/example-config/.mage/tasks/SampleTaskRollbackAware.php | 2 +- docs/example-config/.mage/tasks/TaskWithParameters.php | 2 +- 41 files changed, 41 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 6964198..a147ed3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ mage.phar .DS_Store* ehthumbs.db Icon? -Thumbs.db \ No newline at end of file +Thumbs.db diff --git a/LICENSE b/LICENSE index ccdd780..78cd384 100644 --- a/LICENSE +++ b/LICENSE @@ -24,4 +24,4 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------- The Yaml Library Parser is (c) by Fabien Potencier, and belongs to the Symfony Proyect --------- \ No newline at end of file +-------- diff --git a/LICENSE_YAML b/LICENSE_YAML index 4acdf9d..0b3292c 100644 --- a/LICENSE_YAML +++ b/LICENSE_YAML @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index b513517..3ed5a9d 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -52,4 +52,4 @@ abstract class AbstractCommand { return $this->config; } -} \ No newline at end of file +} diff --git a/Mage/Command/BuiltIn/InstallCommand.php b/Mage/Command/BuiltIn/InstallCommand.php index 47a8411..932b3c0 100644 --- a/Mage/Command/BuiltIn/InstallCommand.php +++ b/Mage/Command/BuiltIn/InstallCommand.php @@ -122,4 +122,4 @@ class InstallCommand extends AbstractCommand return false; } } -} \ No newline at end of file +} diff --git a/Mage/Command/BuiltIn/UpdateCommand.php b/Mage/Command/BuiltIn/UpdateCommand.php index 7fa6461..14dc75a 100644 --- a/Mage/Command/BuiltIn/UpdateCommand.php +++ b/Mage/Command/BuiltIn/UpdateCommand.php @@ -45,5 +45,4 @@ class UpdateCommand extends AbstractCommand return $exitCode; } - -} \ No newline at end of file +} diff --git a/Mage/Command/BuiltIn/VersionCommand.php b/Mage/Command/BuiltIn/VersionCommand.php index ca591d7..8437242 100644 --- a/Mage/Command/BuiltIn/VersionCommand.php +++ b/Mage/Command/BuiltIn/VersionCommand.php @@ -30,5 +30,4 @@ class VersionCommand extends AbstractCommand return 0; } - -} \ No newline at end of file +} diff --git a/Mage/Command/Factory.php b/Mage/Command/Factory.php index 0584046..83b669b 100644 --- a/Mage/Command/Factory.php +++ b/Mage/Command/Factory.php @@ -59,4 +59,4 @@ class Factory return $instance; } -} \ No newline at end of file +} diff --git a/Mage/Command/RequiresEnvironment.php b/Mage/Command/RequiresEnvironment.php index 5ee0771..9a0a56c 100644 --- a/Mage/Command/RequiresEnvironment.php +++ b/Mage/Command/RequiresEnvironment.php @@ -17,4 +17,4 @@ namespace Mage\Command; */ interface RequiresEnvironment { -} \ No newline at end of file +} diff --git a/Mage/Mailer.php b/Mage/Mailer.php index fadf48a..f2fb33d 100644 --- a/Mage/Mailer.php +++ b/Mage/Mailer.php @@ -86,4 +86,4 @@ class Mailer mail($this->address, $subject, $message, $headers); } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php index 958faef..e3255b5 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/DisabledTask.php @@ -38,5 +38,4 @@ class DisabledTask extends AbstractTask implements IsReleaseAware { throw new SkipException; } - -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Magento/ClearCacheTask.php b/Mage/Task/BuiltIn/Magento/ClearCacheTask.php index 8a8cf55..7db7780 100644 --- a/Mage/Task/BuiltIn/Magento/ClearCacheTask.php +++ b/Mage/Task/BuiltIn/Magento/ClearCacheTask.php @@ -39,4 +39,4 @@ class ClearCacheTask extends AbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Magento/ClearFullPageCacheTask.php b/Mage/Task/BuiltIn/Magento/ClearFullPageCacheTask.php index 8dd0b49..17c3d66 100644 --- a/Mage/Task/BuiltIn/Magento/ClearFullPageCacheTask.php +++ b/Mage/Task/BuiltIn/Magento/ClearFullPageCacheTask.php @@ -39,4 +39,4 @@ class ClearFullPageCacheTask extends AbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Releases/ListTask.php b/Mage/Task/BuiltIn/Releases/ListTask.php index 3d76327..0774351 100644 --- a/Mage/Task/BuiltIn/Releases/ListTask.php +++ b/Mage/Task/BuiltIn/Releases/ListTask.php @@ -146,5 +146,4 @@ class ListTask extends AbstractTask implements IsReleaseAware return $textDiff; } - -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index eee33c3..a8ebb9c 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -188,5 +188,4 @@ class RollbackTask extends AbstractTask implements IsReleaseAware return false; } } - -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php b/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php index dfb6127..8c5e33f 100644 --- a/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php +++ b/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php @@ -105,4 +105,4 @@ class ChangeBranchTask extends AbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Scm/CloneTask.php b/Mage/Task/BuiltIn/Scm/CloneTask.php index 7c50b4a..f30085f 100644 --- a/Mage/Task/BuiltIn/Scm/CloneTask.php +++ b/Mage/Task/BuiltIn/Scm/CloneTask.php @@ -84,4 +84,4 @@ class CloneTask extends AbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Scm/RemoveCloneTask.php b/Mage/Task/BuiltIn/Scm/RemoveCloneTask.php index 5084622..e0c102d 100644 --- a/Mage/Task/BuiltIn/Scm/RemoveCloneTask.php +++ b/Mage/Task/BuiltIn/Scm/RemoveCloneTask.php @@ -58,4 +58,4 @@ class RemoveCloneTask extends AbstractTask { return $this->runCommandLocal('rm -rf ' . $this->source['temporal']); } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Scm/UpdateTask.php b/Mage/Task/BuiltIn/Scm/UpdateTask.php index e883a2c..22c496e 100644 --- a/Mage/Task/BuiltIn/Scm/UpdateTask.php +++ b/Mage/Task/BuiltIn/Scm/UpdateTask.php @@ -69,4 +69,4 @@ class UpdateTask extends AbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Symfony2/AsseticDumpTask.php b/Mage/Task/BuiltIn/Symfony2/AsseticDumpTask.php index 7b08660..7b1c69c 100644 --- a/Mage/Task/BuiltIn/Symfony2/AsseticDumpTask.php +++ b/Mage/Task/BuiltIn/Symfony2/AsseticDumpTask.php @@ -42,4 +42,4 @@ class AsseticDumpTask extends SymfonyAbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Symfony2/AssetsInstallTask.php b/Mage/Task/BuiltIn/Symfony2/AssetsInstallTask.php index c53292c..f7ca981 100644 --- a/Mage/Task/BuiltIn/Symfony2/AssetsInstallTask.php +++ b/Mage/Task/BuiltIn/Symfony2/AssetsInstallTask.php @@ -49,4 +49,4 @@ class AssetsInstallTask extends SymfonyAbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php b/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php index fff5c24..44acc46 100644 --- a/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php +++ b/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php @@ -42,4 +42,4 @@ class CacheClearTask extends SymfonyAbstractTask return $result; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Symfony2/SymfonyAbstractTask.php b/Mage/Task/BuiltIn/Symfony2/SymfonyAbstractTask.php index 4fae2e2..7ac246c 100644 --- a/Mage/Task/BuiltIn/Symfony2/SymfonyAbstractTask.php +++ b/Mage/Task/BuiltIn/Symfony2/SymfonyAbstractTask.php @@ -29,4 +29,4 @@ abstract class SymfonyAbstractTask extends AbstractTask return $this->getConfig()->general('symfony_app_path', $defaultAppPath); } -} \ No newline at end of file +} diff --git a/Mage/Task/SkipException.php b/Mage/Task/SkipException.php index e26684a..66bf4a8 100644 --- a/Mage/Task/SkipException.php +++ b/Mage/Task/SkipException.php @@ -19,4 +19,4 @@ use Exception; */ class SkipException extends Exception { -} \ No newline at end of file +} diff --git a/Mage/Yaml/Dumper.php b/Mage/Yaml/Dumper.php index 5090513..1a594df 100644 --- a/Mage/Yaml/Dumper.php +++ b/Mage/Yaml/Dumper.php @@ -72,4 +72,4 @@ class Dumper return $output; } -} \ No newline at end of file +} diff --git a/Mage/Yaml/Escaper.php b/Mage/Yaml/Escaper.php index 021b7ea..ad75520 100644 --- a/Mage/Yaml/Escaper.php +++ b/Mage/Yaml/Escaper.php @@ -86,4 +86,4 @@ class Escaper { return sprintf("'%s'", str_replace('\'', '\'\'', $value)); } -} \ No newline at end of file +} diff --git a/Mage/Yaml/Exception/DumpException.php b/Mage/Yaml/Exception/DumpException.php index bc3581b..20ac47c 100644 --- a/Mage/Yaml/Exception/DumpException.php +++ b/Mage/Yaml/Exception/DumpException.php @@ -22,4 +22,4 @@ use Mage\Yaml\Exception\RuntimeException; */ class DumpException extends RuntimeException { -} \ No newline at end of file +} diff --git a/Mage/Yaml/Exception/ExceptionInterface.php b/Mage/Yaml/Exception/ExceptionInterface.php index fa12000..cc55042 100644 --- a/Mage/Yaml/Exception/ExceptionInterface.php +++ b/Mage/Yaml/Exception/ExceptionInterface.php @@ -20,4 +20,4 @@ namespace Mage\Yaml\Exception; */ interface ExceptionInterface { -} \ No newline at end of file +} diff --git a/Mage/Yaml/Exception/ParseException.php b/Mage/Yaml/Exception/ParseException.php index 3c4465b..6064ce4 100644 --- a/Mage/Yaml/Exception/ParseException.php +++ b/Mage/Yaml/Exception/ParseException.php @@ -147,4 +147,4 @@ class ParseException extends RuntimeException $this->message .= '.'; } } -} \ No newline at end of file +} diff --git a/Mage/Yaml/Exception/RuntimeException.php b/Mage/Yaml/Exception/RuntimeException.php index 51245bd..5bbe8a3 100644 --- a/Mage/Yaml/Exception/RuntimeException.php +++ b/Mage/Yaml/Exception/RuntimeException.php @@ -22,4 +22,4 @@ use Mage\Yaml\Exception\ExceptionInterface; */ class RuntimeException extends \RuntimeException implements ExceptionInterface { -} \ No newline at end of file +} diff --git a/Mage/Yaml/Inline.php b/Mage/Yaml/Inline.php index 2586dde..0341f78 100644 --- a/Mage/Yaml/Inline.php +++ b/Mage/Yaml/Inline.php @@ -502,4 +502,4 @@ class Inline $~x EOF; } -} \ No newline at end of file +} diff --git a/Mage/Yaml/Parser.php b/Mage/Yaml/Parser.php index fa7007d..4237dc5 100644 --- a/Mage/Yaml/Parser.php +++ b/Mage/Yaml/Parser.php @@ -655,5 +655,4 @@ class Parser { return (0 === strpos($this->currentLine, '- ')); } - -} \ No newline at end of file +} diff --git a/Mage/Yaml/Unescaper.php b/Mage/Yaml/Unescaper.php index fc3bbcf..e7a25b3 100644 --- a/Mage/Yaml/Unescaper.php +++ b/Mage/Yaml/Unescaper.php @@ -139,4 +139,4 @@ class Unescaper return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F); } -} \ No newline at end of file +} diff --git a/Mage/Yaml/Yaml.php b/Mage/Yaml/Yaml.php index a476c60..3845c80 100644 --- a/Mage/Yaml/Yaml.php +++ b/Mage/Yaml/Yaml.php @@ -99,4 +99,4 @@ class Yaml return $yaml->dump($array, $inline, 0, $exceptionOnInvalidType, $objectSupport); } -} \ No newline at end of file +} diff --git a/docs/example-config/.mage/config/environment/production.yml b/docs/example-config/.mage/config/environment/production.yml index e1cbe81..3a668f4 100644 --- a/docs/example-config/.mage/config/environment/production.yml +++ b/docs/example-config/.mage/config/environment/production.yml @@ -34,4 +34,4 @@ tasks: - privileges - sampleTask - sampleTaskRollbackAware - #post-deploy: \ No newline at end of file + #post-deploy: diff --git a/docs/example-config/.mage/config/general.yml b/docs/example-config/.mage/config/general.yml index f601999..3834ff3 100644 --- a/docs/example-config/.mage/config/general.yml +++ b/docs/example-config/.mage/config/general.yml @@ -5,4 +5,4 @@ notifications: true logging: true scm: type: git - url: git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git \ No newline at end of file + url: git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git diff --git a/docs/example-config/.mage/logs/.gitignore b/docs/example-config/.mage/logs/.gitignore index 6976a48..5592679 100644 --- a/docs/example-config/.mage/logs/.gitignore +++ b/docs/example-config/.mage/logs/.gitignore @@ -1 +1 @@ -log-* \ No newline at end of file +log-* diff --git a/docs/example-config/.mage/tasks/FailTask.php b/docs/example-config/.mage/tasks/FailTask.php index 91e9c52..641e887 100644 --- a/docs/example-config/.mage/tasks/FailTask.php +++ b/docs/example-config/.mage/tasks/FailTask.php @@ -14,4 +14,4 @@ class FailTask extends AbstractTask { return false; } -} \ No newline at end of file +} diff --git a/docs/example-config/.mage/tasks/Privileges.php b/docs/example-config/.mage/tasks/Privileges.php index f5d88bd..1092533 100644 --- a/docs/example-config/.mage/tasks/Privileges.php +++ b/docs/example-config/.mage/tasks/Privileges.php @@ -17,4 +17,4 @@ class Privileges extends AbstractTask return $result; } -} \ No newline at end of file +} diff --git a/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php b/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php index ef02d13..f990e2c 100644 --- a/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php +++ b/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php @@ -19,4 +19,4 @@ class SampleTaskRollbackAware extends AbstractTask implements RollbackAware { return true; } -} \ No newline at end of file +} diff --git a/docs/example-config/.mage/tasks/TaskWithParameters.php b/docs/example-config/.mage/tasks/TaskWithParameters.php index 967fcfb..003ffef 100644 --- a/docs/example-config/.mage/tasks/TaskWithParameters.php +++ b/docs/example-config/.mage/tasks/TaskWithParameters.php @@ -24,4 +24,4 @@ class TaskWithParameters extends AbstractTask return false; } } -} \ No newline at end of file +} From c630b31bf9dcf73feb7872067bdd6f2bb9d23e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 16:25:36 -0200 Subject: [PATCH 13/34] Yaml tweaks. --- .../.mage/config/environment/production.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/example-config/.mage/config/environment/production.yml b/docs/example-config/.mage/config/environment/production.yml index 3a668f4..538e517 100644 --- a/docs/example-config/.mage/config/environment/production.yml +++ b/docs/example-config/.mage/config/environment/production.yml @@ -17,15 +17,16 @@ releases: directory: releases hosts: - s01.example.com - s02.example.com: - deployment: - user: toor - to: /home/web/public - releases: - max: 10 - tasks: - on-deploy: - - privileges + - s02.example.com +# s02.example.com: +# deployment: +# user: toor +# to: /home/web/public +# releases: +# max: 10 +# tasks: +# on-deploy: +# - privileges tasks: pre-deploy: - scm/update From 94234cf6d8d526b452f050353702bdf599554b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 17:11:34 -0200 Subject: [PATCH 14/34] Tests --- .../environment/{ioncube.yml => ioncube.yml_} | 0 .../.mage/config/environment/production.yml | 15 -------- .../.mage/config/environment/production.yml_ | 38 +++++++++++++++++++ 3 files changed, 38 insertions(+), 15 deletions(-) rename docs/example-config/.mage/config/environment/{ioncube.yml => ioncube.yml_} (100%) create mode 100644 docs/example-config/.mage/config/environment/production.yml_ diff --git a/docs/example-config/.mage/config/environment/ioncube.yml b/docs/example-config/.mage/config/environment/ioncube.yml_ similarity index 100% rename from docs/example-config/.mage/config/environment/ioncube.yml rename to docs/example-config/.mage/config/environment/ioncube.yml_ diff --git a/docs/example-config/.mage/config/environment/production.yml b/docs/example-config/.mage/config/environment/production.yml index 538e517..5122d7d 100644 --- a/docs/example-config/.mage/config/environment/production.yml +++ b/docs/example-config/.mage/config/environment/production.yml @@ -2,11 +2,6 @@ deployment: user: root from: ./ -# source: -# type: git -# repository: git://github.com/andres-montanez/Magallanes.git -# from: master -# temporal: /tmp/myAppClone to: /var/www/vhosts/example.com/www excludes: - application/data/cache/twig/* @@ -18,15 +13,6 @@ releases: hosts: - s01.example.com - s02.example.com -# s02.example.com: -# deployment: -# user: toor -# to: /home/web/public -# releases: -# max: 10 -# tasks: -# on-deploy: -# - privileges tasks: pre-deploy: - scm/update @@ -35,4 +21,3 @@ tasks: - privileges - sampleTask - sampleTaskRollbackAware - #post-deploy: diff --git a/docs/example-config/.mage/config/environment/production.yml_ b/docs/example-config/.mage/config/environment/production.yml_ new file mode 100644 index 0000000..538e517 --- /dev/null +++ b/docs/example-config/.mage/config/environment/production.yml_ @@ -0,0 +1,38 @@ +#production +deployment: + user: root + from: ./ +# source: +# type: git +# repository: git://github.com/andres-montanez/Magallanes.git +# from: master +# temporal: /tmp/myAppClone + to: /var/www/vhosts/example.com/www + excludes: + - application/data/cache/twig/* +releases: + enabled: true + max: 5 + symlink: current + directory: releases +hosts: + - s01.example.com + - s02.example.com +# s02.example.com: +# deployment: +# user: toor +# to: /home/web/public +# releases: +# max: 10 +# tasks: +# on-deploy: +# - privileges +tasks: + pre-deploy: + - scm/update + on-deploy: + - symfony2/cache-warmup: { env: prod } + - privileges + - sampleTask + - sampleTaskRollbackAware + #post-deploy: From d1fbb9c7db2618bb3eb945447ed42a028cc5c3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 17:14:40 -0200 Subject: [PATCH 15/34] Ioncube Yaml --- .../config/environment/{ioncube.yml_ => ioncube.yml} | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) rename docs/example-config/.mage/config/environment/{ioncube.yml_ => ioncube.yml} (94%) diff --git a/docs/example-config/.mage/config/environment/ioncube.yml_ b/docs/example-config/.mage/config/environment/ioncube.yml similarity index 94% rename from docs/example-config/.mage/config/environment/ioncube.yml_ rename to docs/example-config/.mage/config/environment/ioncube.yml index e2a0848..9a6037b 100644 --- a/docs/example-config/.mage/config/environment/ioncube.yml_ +++ b/docs/example-config/.mage/config/environment/ioncube.yml @@ -10,11 +10,11 @@ deployment: ioncube: test releases: - enabled: true - symlink: current - directory: releases + enabled: true + symlink: current + directory: releases hosts: - - localhost + - localhost tasks: pre-deploy: - ioncube/encrypt @@ -29,7 +29,6 @@ ioncube: checkignorepaths: - /public/js/* - /public/css/* - projfile: project.prj project: replace-target: @@ -57,7 +56,6 @@ ioncube: - 'Comment 2' - "(c) ACTweb 2013" - "Draft Version" - loader-event: - corrupt-file=Corupted files - expired-file=System needs updated From e40b7d21c9dc069aafacb50a59a9e1451095698f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 17:17:01 -0200 Subject: [PATCH 16/34] Yamls --- .../.mage/config/environment/{ioncube.yml => ioncube.yml.txt} | 0 .../environment/{production.yml_ => production.yml.advanced.txt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename docs/example-config/.mage/config/environment/{ioncube.yml => ioncube.yml.txt} (100%) rename docs/example-config/.mage/config/environment/{production.yml_ => production.yml.advanced.txt} (100%) diff --git a/docs/example-config/.mage/config/environment/ioncube.yml b/docs/example-config/.mage/config/environment/ioncube.yml.txt similarity index 100% rename from docs/example-config/.mage/config/environment/ioncube.yml rename to docs/example-config/.mage/config/environment/ioncube.yml.txt diff --git a/docs/example-config/.mage/config/environment/production.yml_ b/docs/example-config/.mage/config/environment/production.yml.advanced.txt similarity index 100% rename from docs/example-config/.mage/config/environment/production.yml_ rename to docs/example-config/.mage/config/environment/production.yml.advanced.txt From 2deaa27a2ad433720b2ee2132babd484ddb1ad8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 17:47:07 -0200 Subject: [PATCH 17/34] Tweak clones. --- Mage/Config.php | 31 ++++---------------- Mage/Console.php | 1 - Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 2 +- Mage/Task/BuiltIn/Scm/CloneTask.php | 9 ++++++ 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/Mage/Config.php b/Mage/Config.php index 2991acd..da1223c 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -121,29 +121,6 @@ class Config return $this->parseConfigFile($filePath); } - - /** - * Obviously this method is a HACK. It was refactored from ::loadEnvironment() - * TODO Please put it to SCM functionality. - * - * @param array $settings - * - * @return array - */ - protected function updateSCMTempDir(array $settings) - { - // Create temporal directory for clone - if (isset($settings['deployment']['source']) && is_array($settings['deployment']['source'])) { - if (trim($settings['deployment']['source']['temporal']) == '') { - $settings['deployment']['source']['temporal'] = sys_get_temp_dir(); - } - $settings['deployment']['source']['temporal'] - = rtrim($settings['deployment']['source']['temporal'], '/') . '/' . md5(microtime()) . '/'; - } - - return $settings; - } - /** * Loads the Environment configuration * @param $filePath string @@ -156,9 +133,6 @@ class Config $settings = $this->parseConfigFile($filePath); - //this is a HACK in the old code - no time to remove it now, so I factored it out in own method - $settings = $this->updateSCMTempDir($settings); - return $settings; } @@ -490,6 +464,11 @@ class Config } } + public function setSourceTemporal($directory) + { + $this->environmentConfig['deployment']['source']['temporal'] = $directory; + } + /** * Returns Releasing Options * diff --git a/Mage/Console.php b/Mage/Console.php index f1d7609..ea578cc 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -26,7 +26,6 @@ use SplFileInfo; class Console { /** - * TODO refactor into own static class * @var array */ public static $paramsNotRequiringEnvironment = array('install' => 'install', 'upgrade' => 'upgrade', 'version' => 'version'); diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index ceeab5f..02eeb49 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -133,7 +133,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; if ($directoryToDelete != '/') { $command = 'rm -rf ' . $directoryToDelete; - $result = $result && $this->runCommandRemote($command); + $result = $this->runCommandRemote($command); } } } diff --git a/Mage/Task/BuiltIn/Scm/CloneTask.php b/Mage/Task/BuiltIn/Scm/CloneTask.php index f30085f..c55dd87 100644 --- a/Mage/Task/BuiltIn/Scm/CloneTask.php +++ b/Mage/Task/BuiltIn/Scm/CloneTask.php @@ -53,6 +53,15 @@ class CloneTask extends AbstractTask $this->name = 'SCM Clone (GIT) [built-in]'; break; } + + // Create temporal directory for clone + if (is_array($this->source)) { + if (trim($this->source['temporal']) == '') { + $this->source['temporal'] = sys_get_temp_dir(); + } + $this->source['temporal'] = rtrim($this->source['temporal'], '/') . '/' . md5(microtime()) . '/'; + $this->getConfig()->setSourceTemporal($this->source['temporal']); + } } /** From 92b22d52a3603b2b7c8f22b3baadc470ecb3bc36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 17:55:08 -0200 Subject: [PATCH 18/34] Tweak GitRebase and Insight suggestions. --- Mage/Command/Factory.php | 1 - Mage/Config.php | 1 - Mage/Console.php | 1 - .../BuiltIn/Deployment/Strategy/GitRebaseTask.php | 15 --------------- .../BuiltIn/Deployment/Strategy/TarGzTask.php | 1 - Mage/Task/Factory.php | 1 - 6 files changed, 20 deletions(-) diff --git a/Mage/Command/Factory.php b/Mage/Command/Factory.php index 83b669b..4088239 100644 --- a/Mage/Command/Factory.php +++ b/Mage/Command/Factory.php @@ -12,7 +12,6 @@ namespace Mage\Command; use Mage\Command\AbstractCommand; use Mage\Config; -use Mage\Autoload; use Exception; diff --git a/Mage/Config.php b/Mage/Config.php index da1223c..e839c22 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -13,7 +13,6 @@ namespace Mage; use Mage\Config\ConfigNotFoundException; use Mage\Config\RequiredConfigNotFoundException; use Mage\Console; -use Mage\Yaml\Exception\RuntimeException; use Mage\Yaml\Yaml; use Exception; diff --git a/Mage/Console.php b/Mage/Console.php index ea578cc..9cb04a0 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -119,7 +119,6 @@ class Console } } - $exceptionOccured = false; // Run Command - Check if there is a Configuration Error if ($configError !== false) { self::output('' . $configError . '', 1, 2); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php index a7e4774..b19e06e 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php @@ -10,7 +10,6 @@ namespace Mage\Task\BuiltIn\Deployment\Strategy; -use Mage\Task\AbstractTask; use Mage\Task\Releases\IsReleaseAware; /** @@ -35,20 +34,6 @@ class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware */ public function run() { - $this->checkOverrideRelease(); - $excludes = $this->getExcludes(); - - // If we are working with releases - $deployToDirectory = $this->getConfig()->deployment('to'); - if ($this->getConfig()->release('enabled', false) == true) { - $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - - $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/') - . '/' . $releasesDirectory - . '/' . $this->getConfig()->getReleaseId(); - $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId()); - } - $branch = $this->getParameter('branch', 'master'); $remote = $this->getParameter('remote', 'origin'); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index 5607a5d..bea390f 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -10,7 +10,6 @@ namespace Mage\Task\BuiltIn\Deployment\Strategy; -use Mage\Console; use Mage\Task\BuiltIn\Deployment\Strategy\BaseStrategyTaskAbstract; use Mage\Task\Releases\IsReleaseAware; diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index fce6050..912026f 100644 --- a/Mage/Task/Factory.php +++ b/Mage/Task/Factory.php @@ -11,7 +11,6 @@ namespace Mage\Task; use Mage\Config; -use Mage\Autoload; use Exception; From dceb3292119e1d1b440c67ce9d431dbd3afa18e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 17:57:30 -0200 Subject: [PATCH 19/34] Insight tweaks. --- docs/example-config/.mage/tasks/SampleTask.php | 2 +- docs/example-config/.mage/tasks/SampleTaskRollbackAware.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/example-config/.mage/tasks/SampleTask.php b/docs/example-config/.mage/tasks/SampleTask.php index fc9f9a1..380a4ec 100644 --- a/docs/example-config/.mage/tasks/SampleTask.php +++ b/docs/example-config/.mage/tasks/SampleTask.php @@ -14,4 +14,4 @@ class SampleTask extends AbstractTask { return true; } -} \ No newline at end of file +} diff --git a/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php b/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php index f990e2c..d9213f4 100644 --- a/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php +++ b/docs/example-config/.mage/tasks/SampleTaskRollbackAware.php @@ -20,3 +20,4 @@ class SampleTaskRollbackAware extends AbstractTask implements RollbackAware return true; } } + From 74087c9dd98ef7c46924e4525dd5f69f306da4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 18:02:16 -0200 Subject: [PATCH 20/34] Tweak --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 02eeb49..84187ad 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -133,7 +133,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; if ($directoryToDelete != '/') { $command = 'rm -rf ' . $directoryToDelete; - $result = $this->runCommandRemote($command); + $this->runCommandRemote($command); } } } From 861a823f7ea7b3183b7a7acb8bddabf8944c0d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 11 Oct 2014 21:16:42 -0200 Subject: [PATCH 21/34] Update AbstractTask.php --- Mage/Task/AbstractTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index bc12f5f..663b387 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -223,7 +223,7 @@ abstract class AbstractTask */ protected final function runCommand($command, &$output = null) { - if ($this->getStage() == self::STAGE_DEPLOY) { + if ($this->getStage() == self::STAGE_DEPLOY || $this->getStage() == self::STAGE_POST_RELEASE) { return $this->runCommandRemote($command, $output); } else { return $this->runCommandLocal($command, $output); From 308a67359ce675636b88090a78cdbeb8fae19723 Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Wed, 29 Oct 2014 04:59:58 +0200 Subject: [PATCH 22/34] Add task for force updating a working copy Downloads the latest from remote without trying to merge or rebase anything. Resets the master branch to what you just fetched. Changes all the files in your working tree to match the files in origin/master, so if you have any local changes, they will be lost. --- Mage/Task/BuiltIn/Scm/ForceUpdateTask.php | 87 +++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Mage/Task/BuiltIn/Scm/ForceUpdateTask.php diff --git a/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php b/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php new file mode 100644 index 0000000..9d68e09 --- /dev/null +++ b/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php @@ -0,0 +1,87 @@ + +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ + +namespace Mage\Task\BuiltIn\Scm; + +use Mage\Task\AbstractTask; +use Mage\Task\SkipException; + +/** + * Task for Force Updating a Working Copy + * + * 'git fetch' downloads the latest from remote without trying to merge or rebase anything. + * 'git reset' resets the master branch to what you just fetched. + * The '--hard' option changes all the files in your working tree to match the files in origin/master, + * so if you have any local changes, they will be lost. + * + * @author Samuel Chiriluta + */ +class ForceUpdateTask extends AbstractTask +{ + /** + * Name of the Task + * @var string + */ + private $name = 'SCM Force Update [built-in]'; + + /** + * (non-PHPdoc) + * @see \Mage\Task\AbstractTask::getName() + */ + public function getName() + { + return $this->name; + } + + /** + * (non-PHPdoc) + * @see \Mage\Task\AbstractTask::init() + */ + public function init() + { + switch ($this->getConfig()->general('scm')) { + case 'git': + $this->name = 'SCM Force Update (GIT) [built-in]'; + break; + } + } + + /** + * Force Updates the Working Copy + * @see \Mage\Task\AbstractTask::run() + */ + public function run() + { + switch ($this->getConfig()->general('scm')) { + case 'git': + $branch = $this->getParameter('branch', 'master'); + $remote = $this->getParameter('remote', 'origin'); + + $command = 'git fetch ' . $remote . ' ' . $branch; + $result = $this->runCommandRemote($command); + + $command = 'git reset --hard ' . $remote . '/' . $branch; + $result = $result && $this->runCommandRemote($command); + + $command = 'git pull ' . $remote . ' ' . $branch; + $result = $result && $this->runCommandRemote($command); + break; + + default: + throw new SkipException; + break; + } + + $result = $this->runCommandLocal($command); + $this->getConfig()->reload(); + + return $result; + } +} From a66478b3abc0463e14c288332cdb3d27ca7bd289 Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Wed, 29 Oct 2014 23:16:52 +0400 Subject: [PATCH 23/34] exclude from file added. rebased by upstream --- .../BuiltIn/Deployment/Strategy/RsyncTask.php | 16 ++++++++++++++++ .../BuiltIn/Deployment/Strategy/TarGzTask.php | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index b7ee1b5..f01d243 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -52,6 +52,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware $this->checkOverrideRelease(); $excludes = $this->getExcludes(); + $excludesListFilePath = $this->getExcludesListFile(); // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); @@ -95,6 +96,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware . $strategyFlags . ' ' . '--rsh="ssh ' . $this->getConfig()->getHostIdentityFileOption() . '-p' . $this->getConfig()->getHostPort() . '" ' . $this->excludes($excludes) . ' ' + . $this->excludesListFile($excludesListFilePath) . ' ' . $this->getConfig()->deployment('from') . ' ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory; $result = $this->runCommandLocal($command); @@ -117,4 +119,18 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware $excludesRsync = trim($excludesRsync); return $excludesRsync; } + + /** + * Generates the Exclude from file for rsync + * @param string $excludesFilePath + * @return string + */ + protected function excludesListFile($excludesFilePath) + { + $excludesListFileRsync = ''; + if(!empty($excludesFilePath)) { + $excludesListFileRsync = ' --exclude-from=' . $excludesFilePath; + } + return $excludesListFileRsync; + } } diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index bea390f..f5c0031 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -46,6 +46,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $this->checkOverrideRelease(); $excludes = $this->getExcludes(); + $excludesListFilePath = $this->getExcludesListFile(); // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); @@ -66,6 +67,8 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $excludeCmd .= ' --exclude=' . $excludeFile; } + $excludeFromFileCmd = $this->excludesListFile($excludesListFilePath); + // Strategy Flags $strategyFlags = $this->getConfig()->deployment('strategy_flags', $this->getConfig()->general('strategy_flags', array())); if (isset($strategyFlags['targz']) && isset($strategyFlags['targz']['create'])) { @@ -74,7 +77,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $strategyFlags = ''; } - $command = 'tar cfzh' . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .'; + $command = 'tar cfzh' . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . $excludeFromFileCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .'; $result = $this->runCommandLocal($command); // Strategy Flags @@ -112,4 +115,18 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware return $result; } + + /** + * Generates the Exclude from file for TarGz + * @param string $excludesFilePath + * @return string + */ + protected function excludesListFile($excludesFilePath) + { + $excludesListFileRsync = ''; + if(!empty($excludesFilePath)) { + $excludesListFileRsync = ' --exclude-from=' . $excludesFilePath; + } + return $excludesListFileRsync; + } } From 95f09dc3c9987a8b54532192ace68370b555d315 Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 30 Oct 2014 12:31:05 +0400 Subject: [PATCH 24/34] small fixes @ rsync and targz tasks --- Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php | 2 +- Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index f01d243..b8b1dc6 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -52,7 +52,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware $this->checkOverrideRelease(); $excludes = $this->getExcludes(); - $excludesListFilePath = $this->getExcludesListFile(); + $excludesListFilePath = $this->getConfig()->deployment('file_containing_excludes', ''); // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index f5c0031..7b9dcfe 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -46,7 +46,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $this->checkOverrideRelease(); $excludes = $this->getExcludes(); - $excludesListFilePath = $this->getExcludesListFile(); + $excludesListFilePath = $this->getConfig()->deployment('file_containing_excludes', '');; // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); From 6f551cabf00e73bd1b6efc91e2ff1357a807715c Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Sun, 28 Sep 2014 00:42:15 +0400 Subject: [PATCH 25/34] added relative linking @ Link shared files task --- .../Filesystem/LinkSharedFilesTask.php | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 86dc645..105513c 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -8,6 +8,8 @@ use Mage\Task\SkipException; class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { + const ABSOLUTE_LINKING = 'absolute'; + const RELATIVE_LINKING = 'relative'; /** * Returns the Title of the Task * @return string @@ -25,28 +27,36 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware */ public function run() { - $linkedFiles = $this->getParameter('linked_files', []); - $linkedFolders = $this->getParameter('linked_folders', []); + $linkedFiles = $this->getParameter('linked_files', []); + $linkedFolders = $this->getParameter('linked_folders', []); + $linkingStrategy = $this->getParameter('linking_stategy', self::ABSOLUTE_LINKING); + + $linkedEntities = array_merge($linkedFiles,$linkedFolders); + if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) { throw new SkipException('No files and folders configured for sym-linking.'); } $sharedFolderName = $this->getParameter('shared', 'shared'); - $sharedFolderName = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; + $sharedFolderPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; - - $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); - foreach ($linkedFolders as $folder) { - $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; - $this->runCommandRemote($command); - } - - foreach ($linkedFiles as $folder) { - $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; + $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; + + $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); + if($linkingStrategy==self::RELATIVE_LINKING) + $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; + + foreach ($linkedEntities as $entityPath) { + $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; + if($linkingStrategy==self::RELATIVE_LINKING) { + $parentFolderPath = dirname($entityPath); + $relativePath = empty($parentFolderPath)?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; + $sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath; + } + $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; $this->runCommandRemote($command); } return true; } -} +} \ No newline at end of file From 0a1457312660bb590bce8b2b874ee44190e223fd Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Sun, 28 Sep 2014 16:59:09 +0400 Subject: [PATCH 26/34] relative linking @ Link shared files task. Added exclusion rules to symlinks creation. --- .../Filesystem/LinkSharedFilesTask.php | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 105513c..6ceaa16 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -8,8 +8,16 @@ use Mage\Task\SkipException; class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { + const LINKED_FOLDERS = 'linked_folders'; + const LINKED_STRATEGY = 'linking_stategy'; + const ABSOLUTE_LINKING = 'absolute'; const RELATIVE_LINKING = 'relative'; + + public $linkingStrategies = array( + self::ABSOLUTE_LINKING, + self::RELATIVE_LINKING + ); /** * Returns the Title of the Task * @return string @@ -28,8 +36,8 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware public function run() { $linkedFiles = $this->getParameter('linked_files', []); - $linkedFolders = $this->getParameter('linked_folders', []); - $linkingStrategy = $this->getParameter('linking_stategy', self::ABSOLUTE_LINKING); + $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []); + $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); $linkedEntities = array_merge($linkedFiles,$linkedFolders); @@ -43,14 +51,19 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); - if($linkingStrategy==self::RELATIVE_LINKING) - $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; + $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; - foreach ($linkedEntities as $entityPath) { + foreach ($linkedEntities as $ePath) { + if(is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies ) ) { + $entityPath = key($ePath); + } else { + $strategy = $linkingStrategy; + $entityPath = $ePath; + } $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; - if($linkingStrategy==self::RELATIVE_LINKING) { + if($strategy==self::RELATIVE_LINKING) { $parentFolderPath = dirname($entityPath); - $relativePath = empty($parentFolderPath)?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; + $relativePath = $parentFolderPath=='.'?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; $sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath; } $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; From 50e2d6eeb582ff4f6c8fdf863652cfc7cc0c40fc Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Mon, 29 Sep 2014 13:02:20 +0400 Subject: [PATCH 27/34] small fixes @ link shared files task. wrong constant value --- Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 6ceaa16..4ed89a1 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -9,7 +9,7 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { const LINKED_FOLDERS = 'linked_folders'; - const LINKED_STRATEGY = 'linking_stategy'; + const LINKED_STRATEGY = 'linking_strategy'; const ABSOLUTE_LINKING = 'absolute'; const RELATIVE_LINKING = 'relative'; From 438a81542e99124e54253810dfa98216a7fd2b91 Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 30 Oct 2014 23:49:01 +0400 Subject: [PATCH 28/34] changes @ deploy command. added rollback exception functionality. --- Mage/Command/BuiltIn/DeployCommand.php | 28 ++++++++++++++++++++++++++ Mage/Task/RollbackException.php | 23 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Mage/Task/RollbackException.php diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 3719c49..e412d92 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -3,6 +3,7 @@ * This file is part of the Magallanes package. * * (c) Andrés Montañez +* (c) Alex V Kotelnikov * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,6 +17,7 @@ use Mage\Task\Factory; use Mage\Task\AbstractTask; use Mage\Task\Releases\SkipOnOverride; use Mage\Task\ErrorWithMessageException; +use Mage\Task\RollbackException; use Mage\Task\SkipException; use Mage\Console; use Mage\Config; @@ -428,6 +430,27 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } } + protected function runRollbackTask(){ + $hosts = $this->getConfig()->getHosts(); + + if (count($hosts) == 0) { + Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); + + } else { + $result = true; + foreach ($hosts as $host) { + $this->getConfig()->setHost($host); + + $this->getConfig()->setReleaseId(-1); + $task = Factory::get('releases/rollback', $this->getConfig()); + $task->init(); + $result = $task->run() && $result; + } + return $result; + } + return false; + } + /** * Runs a Task * @@ -461,6 +484,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment Console::output('FAIL', 0); $result = false; } + } catch (RollbackException $e) { + Console::output('FAIL, Rollback started [Message: ' . $e->getMessage() . ']', 0); + $this->runRollbackTask(); + $result = false; + } catch (ErrorWithMessageException $e) { Console::output('FAIL [Message: ' . $e->getMessage() . ']', 0); $result = false; diff --git a/Mage/Task/RollbackException.php b/Mage/Task/RollbackException.php new file mode 100644 index 0000000..d2e56df --- /dev/null +++ b/Mage/Task/RollbackException.php @@ -0,0 +1,23 @@ + +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ + +namespace Mage\Task; + +use Exception; + +/** + * Exception that indicates that the Task was Failed and rollback needed + * + * @author Alex V Kotelnikov + */ +class RollbackException extends Exception +{ + +} \ No newline at end of file From b924b922409b6204dd3f691b5ad0342b11831409 Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Fri, 31 Oct 2014 00:03:31 +0400 Subject: [PATCH 29/34] added config reload @ after rollback exception --- Mage/Command/BuiltIn/DeployCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index e412d92..bbff2b6 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -431,6 +431,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } protected function runRollbackTask(){ + $this->getConfig()->reload(); $hosts = $this->getConfig()->getHosts(); if (count($hosts) == 0) { From df632b3fe3c52cf85825c0e1e156201eb39d484e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 1 Nov 2014 18:15:39 -0200 Subject: [PATCH 30/34] Tweak excludes files. --- Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php | 10 +++++----- Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index b8b1dc6..3555ce0 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -52,7 +52,7 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware $this->checkOverrideRelease(); $excludes = $this->getExcludes(); - $excludesListFilePath = $this->getConfig()->deployment('file_containing_excludes', ''); + $excludesListFilePath = $this->getConfig()->deployment('excludes_file', ''); // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); @@ -122,14 +122,14 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware /** * Generates the Exclude from file for rsync - * @param string $excludesFilePath + * @param string $excludesFile * @return string */ - protected function excludesListFile($excludesFilePath) + protected function excludesListFile($excludesFile) { $excludesListFileRsync = ''; - if(!empty($excludesFilePath)) { - $excludesListFileRsync = ' --exclude-from=' . $excludesFilePath; + if(!empty($excludesFile) && file_exists($excludesFile) && is_file($excludesFile) && is_readable($excludesFile)) { + $excludesListFileRsync = ' --exclude-from=' . $excludesFile; } return $excludesListFileRsync; } diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index 7b9dcfe..d45ea17 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -46,7 +46,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $this->checkOverrideRelease(); $excludes = $this->getExcludes(); - $excludesListFilePath = $this->getConfig()->deployment('file_containing_excludes', '');; + $excludesListFilePath = $this->getConfig()->deployment('excludes_file', '');; // If we are working with releases $deployToDirectory = $this->getConfig()->deployment('to'); @@ -117,15 +117,15 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware } /** - * Generates the Exclude from file for TarGz - * @param string $excludesFilePath + * Generates the Exclude from file for rsync + * @param string $excludesFile * @return string */ - protected function excludesListFile($excludesFilePath) + protected function excludesListFile($excludesFile) { $excludesListFileRsync = ''; - if(!empty($excludesFilePath)) { - $excludesListFileRsync = ' --exclude-from=' . $excludesFilePath; + if(!empty($excludesFile) && file_exists($excludesFile) && is_file($excludesFile) && is_readable($excludesFile)) { + $excludesListFileRsync = ' --exclude-from=' . $excludesFile; } return $excludesListFileRsync; } From 8771cf2ab1ce0df8fb310400e208878d30120db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 1 Nov 2014 19:09:25 -0200 Subject: [PATCH 31/34] Fixes #131 --- Mage/Command/BuiltIn/ReleasesCommand.php | 11 ++++++++++- Mage/Command/BuiltIn/RollbackCommand.php | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Mage/Command/BuiltIn/ReleasesCommand.php b/Mage/Command/BuiltIn/ReleasesCommand.php index 2837903..e9f0443 100644 --- a/Mage/Command/BuiltIn/ReleasesCommand.php +++ b/Mage/Command/BuiltIn/ReleasesCommand.php @@ -44,8 +44,17 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment } $result = true; - foreach ($hosts as $host) { + foreach ($hosts as $hostKey => $host) { + // Check if Host has specific configuration + $hostConfig = null; + if (is_array($host)) { + $hostConfig = $host; + $host = $hostKey; + } + + // Set Host and Host Specific Config $this->getConfig()->setHost($host); + $this->getConfig()->setHostConfig($hostConfig); switch ($subCommand) { case 'list': diff --git a/Mage/Command/BuiltIn/RollbackCommand.php b/Mage/Command/BuiltIn/RollbackCommand.php index 7a5b85b..1023869 100644 --- a/Mage/Command/BuiltIn/RollbackCommand.php +++ b/Mage/Command/BuiltIn/RollbackCommand.php @@ -51,8 +51,17 @@ class RollbackCommand extends AbstractCommand implements RequiresEnvironment } else { $result = true; - foreach ($hosts as $host) { + foreach ($hosts as $hostKey => $host) { + // Check if Host has specific configuration + $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($releaseId); $task = Factory::get('releases/rollback', $this->getConfig()); From 40e8c33846089fd86cd2ac4c7c1b836ad86d05d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 1 Nov 2014 19:19:05 -0200 Subject: [PATCH 32/34] Related to #130 --- Mage/Command/BuiltIn/CompileCommand.php | 2 +- Mage/Command/BuiltIn/DeployCommand.php | 6 +++--- Mage/Command/BuiltIn/ListCommand.php | 4 ++-- Mage/Command/BuiltIn/ReleasesCommand.php | 8 ++++---- Mage/Command/BuiltIn/RollbackCommand.php | 6 +++--- Mage/Command/BuiltIn/UpgradeCommand.php | 2 +- bin/mage | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Mage/Command/BuiltIn/CompileCommand.php b/Mage/Command/BuiltIn/CompileCommand.php index f67e875..9cd94b6 100644 --- a/Mage/Command/BuiltIn/CompileCommand.php +++ b/Mage/Command/BuiltIn/CompileCommand.php @@ -28,7 +28,7 @@ class CompileCommand extends AbstractCommand { if (ini_get('phar.readonly')) { Console::output('The php.ini variable phar.readonly must be Off.', 1, 2); - return 300; + return 200; } $compiler = new Compiler; diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index bbff2b6..8efa11a 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -111,20 +111,20 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment */ public function run() { - $exitCode = 1000; + $exitCode = 240; // Check if Environment is not Locked $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock'; if (file_exists($lockFile)) { Console::output('This environment is locked!', 1, 2); echo file_get_contents($lockFile); - return 1010; + return 231; } // Check for running instance and Lock if (file_exists(getcwd() . '/.mage/~working.lock')) { Console::output('There is already an instance of Magallanes running!', 1, 2); - return 1020; + return 230; } else { touch(getcwd() . '/.mage/~working.lock'); } diff --git a/Mage/Command/BuiltIn/ListCommand.php b/Mage/Command/BuiltIn/ListCommand.php index 48e89bf..8c3561a 100644 --- a/Mage/Command/BuiltIn/ListCommand.php +++ b/Mage/Command/BuiltIn/ListCommand.php @@ -31,7 +31,7 @@ class ListCommand extends AbstractCommand */ public function run() { - $exitCode = 600; + $exitCode = 221; $subCommand = $this->getConfig()->getArgument(1); try { @@ -56,7 +56,7 @@ class ListCommand extends AbstractCommand */ protected function listEnvironments() { - $exitCode = 600; + $exitCode = 220; $environments = array(); $content = scandir(getcwd() . '/.mage/config/environment/'); foreach ($content as $file) { diff --git a/Mage/Command/BuiltIn/ReleasesCommand.php b/Mage/Command/BuiltIn/ReleasesCommand.php index e9f0443..be8b502 100644 --- a/Mage/Command/BuiltIn/ReleasesCommand.php +++ b/Mage/Command/BuiltIn/ReleasesCommand.php @@ -28,7 +28,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment */ public function run() { - $exitCode = 400; + $exitCode = 100; $subCommand = $this->getConfig()->getArgument(1); // Run Tasks for Deployment @@ -40,7 +40,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment 1, 3 ); - return 401; + return 101; } $result = true; @@ -67,7 +67,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment if (!is_numeric($this->getConfig()->getParameter('release', ''))) { Console::output('Missing required releaseid.', 1, 2); - return 410; + return 102; } $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock'; @@ -75,7 +75,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment Console::output('This environment is locked!', 1, 2); echo file_get_contents($lockFile); - return 420; + return 103; } $releaseId = $this->getConfig()->getParameter('release', ''); diff --git a/Mage/Command/BuiltIn/RollbackCommand.php b/Mage/Command/BuiltIn/RollbackCommand.php index 1023869..12a8f4e 100644 --- a/Mage/Command/BuiltIn/RollbackCommand.php +++ b/Mage/Command/BuiltIn/RollbackCommand.php @@ -28,19 +28,19 @@ class RollbackCommand extends AbstractCommand implements RequiresEnvironment */ public function run() { - $exitCode = 450; + $exitCode = 105; $releaseId = $this->getConfig()->getArgument(1); if (!is_numeric($releaseId)) { Console::output('This release is mandatory.', 1, 2); - return 451; + return 104; } $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock'; if (file_exists($lockFile)) { Console::output('This environment is locked!', 1, 2); echo file_get_contents($lockFile); - return 20; + return 106; } // Run Tasks for Deployment diff --git a/Mage/Command/BuiltIn/UpgradeCommand.php b/Mage/Command/BuiltIn/UpgradeCommand.php index 5de6a2d..7e5aae0 100644 --- a/Mage/Command/BuiltIn/UpgradeCommand.php +++ b/Mage/Command/BuiltIn/UpgradeCommand.php @@ -38,7 +38,7 @@ class UpgradeCommand extends AbstractCommand */ public function run() { - $exitCode = 100; + $exitCode = 99; Console::output('Upgrading Magallanes ... ', 1, 0); $user = ''; diff --git a/bin/mage b/bin/mage index b668d45..b5d201e 100755 --- a/bin/mage +++ b/bin/mage @@ -32,4 +32,4 @@ array_shift($argv); $console = new Mage\Console; $exitCode = $console->run($argv); -exit($exitCode); +exit((integer) $exitCode); From c34fa53af5121c4593565e544138a1c6836f4e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 1 Nov 2014 19:31:04 -0200 Subject: [PATCH 33/34] Fixes #121 --- Mage/Command/BuiltIn/AddCommand.php | 8 ++-- Mage/Command/BuiltIn/DeployCommand.php | 44 ++++++++++----------- Mage/Command/BuiltIn/InitCommand.php | 8 ++-- Mage/Command/BuiltIn/InstallCommand.php | 2 +- Mage/Command/BuiltIn/ListCommand.php | 4 +- Mage/Command/BuiltIn/ReleasesCommand.php | 2 +- Mage/Command/BuiltIn/RollbackCommand.php | 2 +- Mage/Command/BuiltIn/UpgradeCommand.php | 4 +- Mage/Command/BuiltIn/VersionCommand.php | 2 +- Mage/Console.php | 2 +- Mage/Console/Colors.php | 2 +- Mage/Task/BuiltIn/Releases/ListTask.php | 8 ++-- Mage/Task/BuiltIn/Releases/RollbackTask.php | 8 ++-- 13 files changed, 48 insertions(+), 48 deletions(-) diff --git a/Mage/Command/BuiltIn/AddCommand.php b/Mage/Command/BuiltIn/AddCommand.php index fab6f71..d7b1d12 100644 --- a/Mage/Command/BuiltIn/AddCommand.php +++ b/Mage/Command/BuiltIn/AddCommand.php @@ -68,7 +68,7 @@ class AddCommand extends AbstractCommand throw new Exception('The environment already exists.'); } - Console::output('Adding new environment: ' . $environmentName . ''); + Console::output('Adding new environment: ' . $environmentName . ''); $releasesConfig = 'releases:' . PHP_EOL . ' enabled: true' . PHP_EOL @@ -93,10 +93,10 @@ class AddCommand extends AbstractCommand $result = file_put_contents($environmentConfigFile, $baseConfig); if ($result) { - Console::output('Success!! Environment config file for ' . $environmentName . ' created successfully at ' . $environmentConfigFile . ''); - Console::output('So please! Review and adjust its configuration.', 2, 2); + Console::output('Success!! Environment config file for ' . $environmentName . ' created successfully at ' . $environmentConfigFile . ''); + Console::output('So please! Review and adjust its configuration.', 2, 2); } else { - Console::output('Error!! Unable to create config file for environment called ' . $environmentName . '', 1, 2); + Console::output('Error!! Unable to create config file for environment called ' . $environmentName . '', 1, 2); } } } diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 8efa11a..943a630 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -133,21 +133,21 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $this->getConfig()->setReleaseId(date('YmdHis')); // Deploy Summary - Console::output('Deploy summary', 1, 1); + Console::output('Deploy summary', 1, 1); // Deploy Summary - Environment - Console::output('Environment: ' . $this->getConfig()->getEnvironment() . '', 2, 1); + Console::output('Environment: ' . $this->getConfig()->getEnvironment() . '', 2, 1); // Deploy Summary - Releases if ($this->getConfig()->release('enabled', false)) { - Console::output('Release ID: ' . $this->getConfig()->getReleaseId() . '', 2, 1); + 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'])) { - Console::output('SCM Branch: ' . $scmConfig['branch'] . '', 2, 1); + Console::output('SCM Branch: ' . $scmConfig['branch'] . '', 2, 1); } } @@ -162,7 +162,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment // Check Status if (self::$failedTasks > 0) { self::$deployStatus = self::FAILED; - Console::output('A total of ' . self::$failedTasks . ' deployment tasks failed: ABORTING', 1, 2); + Console::output('A total of ' . self::$failedTasks . ' deployment tasks failed: ABORTING', 1, 2); } else { // Run Deployment Tasks @@ -171,7 +171,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment // Check Status if (self::$failedTasks > 0) { self::$deployStatus = self::FAILED; - Console::output('A total of ' . self::$failedTasks . ' deployment tasks failed: ABORTING', 1, 2); + Console::output('A total of ' . self::$failedTasks . ' deployment tasks failed: ABORTING', 1, 2); } // Run Post-Deployment Tasks @@ -181,15 +181,15 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment // Time Information Hosts if ($this->hostsCount > 0) { $timeTextHost = $this->transcurredTime($this->endTimeHosts - $this->startTimeHosts); - Console::output('Time for deployment: ' . $timeTextHost . '.'); + Console::output('Time for deployment: ' . $timeTextHost . '.'); $timeTextPerHost = $this->transcurredTime(round(($this->endTimeHosts - $this->startTimeHosts) / $this->hostsCount)); - Console::output('Average time per host: ' . $timeTextPerHost . '.'); + Console::output('Average time per host: ' . $timeTextPerHost . '.'); } // Time Information General $timeText = $this->transcurredTime(time() - $this->startTime); - Console::output('Total time: ' . $timeText . '.', 1, 2); + Console::output('Total time: ' . $timeText . '.', 1, 2); // Send Notifications $this->sendNotification(self::$failedTasks > 0 ? false : true); @@ -251,10 +251,10 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } if (count($tasksToRun) == 0) { - Console::output('No ' . $title . ' tasks defined.', 1, 3); + Console::output('No ' . $title . ' tasks defined.', 1, 3); } else { - Console::output('Starting ' . $title . ' tasks:'); + Console::output('Starting ' . $title . ' tasks:'); $tasks = 0; $completedTasks = 0; @@ -276,7 +276,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $tasksColor = 'red'; } - Console::output('Finished ' . $title . ' tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); + Console::output('Finished ' . $title . ' tasks: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); } } @@ -292,7 +292,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment self::$failedTasks = 0; if ($this->hostsCount == 0) { - Console::output('Warning! No hosts defined, skipping deployment tasks.', 1, 3); + Console::output('Warning! No hosts defined, skipping deployment tasks.', 1, 3); } else { $this->startTimeHosts = time(); @@ -313,7 +313,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $tasks = 0; $completedTasks = 0; - Console::output('Deploying to ' . $this->getConfig()->getHost() . ''); + Console::output('Deploying to ' . $this->getConfig()->getHost() . ''); $tasksToRun = $this->getConfig()->getTasks(); @@ -322,8 +322,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment array_unshift($tasksToRun, $deployStrategy); if (count($tasksToRun) == 0) { - Console::output('Warning! No Deployment tasks defined.', 2); - Console::output('Deployment to ' . $host . ' skipped!', 1, 3); + Console::output('Warning! No Deployment tasks defined.', 2); + Console::output('Deployment to ' . $host . ' skipped!', 1, 3); } else { foreach ($tasksToRun as $taskData) { @@ -343,7 +343,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $tasksColor = 'red'; } - Console::output('Deployment to ' . $this->getConfig()->getHost() . ' completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); + Console::output('Deployment to ' . $this->getConfig()->getHost() . ' completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); } // Reset Host Config @@ -360,7 +360,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment // Releasing if (self::$deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) === true) { // Execute the Releases - Console::output('Starting the Releasing'); + Console::output('Starting the Releasing'); $completedTasks = 0; foreach ($hosts as $hostKey => $host) { @@ -384,7 +384,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment // Reset Host Config $this->getConfig()->setHostConfig(null); } - Console::output('Finished the Releasing', 1, 3); + Console::output('Finished the Releasing', 1, 3); // Execute the Post-Release Tasks foreach ($hosts as $hostKey => $host) { @@ -405,7 +405,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $completedTasks = 0; if (count($tasksToRun) > 0) { - Console::output('Starting Post-Release tasks for ' . $host . ':'); + Console::output('Starting Post-Release tasks for ' . $host . ':'); foreach ($tasksToRun as $task) { $task = Factory::get($task, $this->getConfig(), false, AbstractTask::STAGE_POST_RELEASE); @@ -420,7 +420,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } else { $tasksColor = 'red'; } - Console::output('Finished Post-Release tasks for ' . $host . ': <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); + Console::output('Finished Post-Release tasks for ' . $host . ': <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); } // Reset Host Config @@ -435,7 +435,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $hosts = $this->getConfig()->getHosts(); if (count($hosts) == 0) { - Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); + Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); } else { $result = true; diff --git a/Mage/Command/BuiltIn/InitCommand.php b/Mage/Command/BuiltIn/InitCommand.php index f996335..90d665f 100644 --- a/Mage/Command/BuiltIn/InitCommand.php +++ b/Mage/Command/BuiltIn/InitCommand.php @@ -30,11 +30,11 @@ class InitCommand extends AbstractCommand $exitCode = 50; $configDir = getcwd() . '/.mage'; - Console::output('Initiating managing process for application with Magallanes'); + Console::output('Initiating managing process for application with Magallanes'); // Check if there is already a config dir if (file_exists($configDir)) { - Console::output('Error!! Already exists .mage directory.', 1, 2); + Console::output('Error!! Already exists .mage directory.', 1, 2); } else { $results = array(); $results[] = mkdir($configDir); @@ -48,8 +48,8 @@ class InitCommand extends AbstractCommand $results[] = file_put_contents($configDir . '/config/general.yml', $this->getGeneralConfig()); if (!in_array(false, $results)) { - Console::output('Success!! The configuration for Magallanes has been generated at .mage directory.'); - Console::output('Please!! Review and adjust the configuration.', 2, 2); + Console::output('Success!! The configuration for Magallanes has been generated at .mage directory.'); + Console::output('Please!! Review and adjust the configuration.', 2, 2); $exitCode = 0; } else { diff --git a/Mage/Command/BuiltIn/InstallCommand.php b/Mage/Command/BuiltIn/InstallCommand.php index 932b3c0..4271d43 100644 --- a/Mage/Command/BuiltIn/InstallCommand.php +++ b/Mage/Command/BuiltIn/InstallCommand.php @@ -27,7 +27,7 @@ class InstallCommand extends AbstractCommand public function run() { $exitCode = 88; - Console::output('Installing Magallanes... ', 1, 0); + Console::output('Installing Magallanes... ', 1, 0); // Vars $installDir = $this->getConfig()->getParameter('installDir', '/opt/magallanes'); diff --git a/Mage/Command/BuiltIn/ListCommand.php b/Mage/Command/BuiltIn/ListCommand.php index 8c3561a..0d27862 100644 --- a/Mage/Command/BuiltIn/ListCommand.php +++ b/Mage/Command/BuiltIn/ListCommand.php @@ -67,7 +67,7 @@ class ListCommand extends AbstractCommand sort($environments); if (count($environments) > 0) { - Console::output('These are your configured environments:', 1, 1); + Console::output('These are your configured environments:', 1, 1); foreach ($environments as $environment) { Console::output('* ' . $environment . '', 2, 1); } @@ -75,7 +75,7 @@ class ListCommand extends AbstractCommand $exitCode = 0; } else { - Console::output('You don\'t have any environment configured.', 1, 2); + Console::output('You don\'t have any environment configured.', 1, 2); } return $exitCode; diff --git a/Mage/Command/BuiltIn/ReleasesCommand.php b/Mage/Command/BuiltIn/ReleasesCommand.php index be8b502..3a40439 100644 --- a/Mage/Command/BuiltIn/ReleasesCommand.php +++ b/Mage/Command/BuiltIn/ReleasesCommand.php @@ -36,7 +36,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment if (count($hosts) == 0) { Console::output( - 'Warning! No hosts defined, unable to get releases.', + 'Warning! No hosts defined, unable to get releases.', 1, 3 ); diff --git a/Mage/Command/BuiltIn/RollbackCommand.php b/Mage/Command/BuiltIn/RollbackCommand.php index 12a8f4e..8d85ac8 100644 --- a/Mage/Command/BuiltIn/RollbackCommand.php +++ b/Mage/Command/BuiltIn/RollbackCommand.php @@ -47,7 +47,7 @@ class RollbackCommand extends AbstractCommand implements RequiresEnvironment $hosts = $this->getConfig()->getHosts(); if (count($hosts) == 0) { - Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); + Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); } else { $result = true; diff --git a/Mage/Command/BuiltIn/UpgradeCommand.php b/Mage/Command/BuiltIn/UpgradeCommand.php index 7e5aae0..94fe6e0 100644 --- a/Mage/Command/BuiltIn/UpgradeCommand.php +++ b/Mage/Command/BuiltIn/UpgradeCommand.php @@ -39,7 +39,7 @@ class UpgradeCommand extends AbstractCommand public function run() { $exitCode = 99; - Console::output('Upgrading Magallanes ... ', 1, 0); + Console::output('Upgrading Magallanes ... ', 1, 0); $user = ''; // Check if user is root @@ -49,7 +49,7 @@ class UpgradeCommand extends AbstractCommand if ($user != 'root' && $user != $owner) { Console::output('FAIL', 0, 1); - Console::output('You need to be the ' . $owner . ' user to perform the upgrade, or root.', 2); + Console::output('You need to be the ' . $owner . ' user to perform the upgrade, or root.', 2); } else { // Check version diff --git a/Mage/Command/BuiltIn/VersionCommand.php b/Mage/Command/BuiltIn/VersionCommand.php index 8437242..0c7938c 100644 --- a/Mage/Command/BuiltIn/VersionCommand.php +++ b/Mage/Command/BuiltIn/VersionCommand.php @@ -26,7 +26,7 @@ class VersionCommand extends AbstractCommand */ public function run() { - Console::output('Running Magallanes version ' . MAGALLANES_VERSION . '', 0, 2); + Console::output('Running Magallanes version ' . MAGALLANES_VERSION . '', 0, 2); return 0; } diff --git a/Mage/Console.php b/Mage/Console.php index 9cb04a0..b9dd97c 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -115,7 +115,7 @@ class Console } else { self::output('Starting Magallanes', 0, 1); self::log("Logging enabled"); - self::output('Logging enabled: ' . self::getLogFile() . '', 1, 2); + self::output('Logging enabled: ' . self::getLogFile() . '', 1, 2); } } diff --git a/Mage/Console/Colors.php b/Mage/Console/Colors.php index 84bfb62..5ab48bc 100644 --- a/Mage/Console/Colors.php +++ b/Mage/Console/Colors.php @@ -25,7 +25,7 @@ class Colors */ private static $foregroundColors = array( 'black' => '0;30', - 'dark_gray' => '1;30', + 'bold' => '1', 'blue' => '0;34', 'light_blue' => '1;34', 'green' => '0;32', diff --git a/Mage/Task/BuiltIn/Releases/ListTask.php b/Mage/Task/BuiltIn/Releases/ListTask.php index 0774351..ffbd2c4 100644 --- a/Mage/Task/BuiltIn/Releases/ListTask.php +++ b/Mage/Task/BuiltIn/Releases/ListTask.php @@ -38,7 +38,7 @@ class ListTask extends AbstractTask implements IsReleaseAware $releasesDirectory = $this->getConfig()->release('directory', 'releases'); $symlink = $this->getConfig()->release('symlink', 'current'); - Console::output('Releases available on ' . $this->getConfig()->getHost() . ''); + Console::output('Releases available on ' . $this->getConfig()->getHost() . ''); // Get Releases $output = ''; @@ -51,7 +51,7 @@ class ListTask extends AbstractTask implements IsReleaseAware $currentRelease = trim(array_pop($currentRelease)); if (count($releases) == 0) { - Console::output('No releases available ... ', 2); + Console::output('No releases available ... ', 2); } else { rsort($releases); $releases = array_slice($releases, 0, 10); @@ -80,8 +80,8 @@ class ListTask extends AbstractTask implements IsReleaseAware Console::output( 'Release: ' . $release . ' ' - . '- Date: ' . $releaseDate . ' ' - . '- Index: ' . $releaseIndex . '' . $dateDiff . $isCurrent, 2); + . '- Date: ' . $releaseDate . ' ' + . '- Index: ' . $releaseIndex . '' . $dateDiff . $isCurrent, 2); } } diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index a8ebb9c..7a437fd 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -56,7 +56,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $releases = ($output == '') ? array() : explode(PHP_EOL, $output); if (count($releases) == 0) { - Console::output('Release are not available for ' . $this->getConfig()->getHost() . ' ... FAIL'); + Console::output('Release are not available for ' . $this->getConfig()->getHost() . ' ... FAIL'); } else { rsort($releases); @@ -81,10 +81,10 @@ class RollbackTask extends AbstractTask implements IsReleaseAware } if (!$releaseIsAvailable) { - Console::output('Release ' . $this->getReleaseId() . ' is invalid or unavailable for ' . $this->getConfig()->getHost() . ' ... FAIL'); + Console::output('Release ' . $this->getReleaseId() . ' is invalid or unavailable for ' . $this->getConfig()->getHost() . ' ... FAIL'); } else { - Console::output('Rollback release on ' . $this->getConfig()->getHost() . ''); + Console::output('Rollback release on ' . $this->getConfig()->getHost() . ''); $rollbackTo = $releasesDirectory . '/' . $releaseId; // Get Current Release @@ -178,7 +178,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $tasksColor = 'red'; } - Console::output('Release rollback on ' . $this->getConfig()->getHost() . ' compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); + Console::output('Release rollback on ' . $this->getConfig()->getHost() . ' compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . ' tasks done.', 1, 3); } } From 609745ccc4003198129081503c91359db4c5242c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 1 Nov 2014 19:49:04 -0200 Subject: [PATCH 34/34] Prepare for new release. --- bin/mage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/mage b/bin/mage index b5d201e..728e3aa 100755 --- a/bin/mage +++ b/bin/mage @@ -13,7 +13,7 @@ date_default_timezone_set('UTC'); $baseDir = dirname(dirname(__FILE__)); -define('MAGALLANES_VERSION', '1.0.2'); +define('MAGALLANES_VERSION', '1.0.3'); define('MAGALLANES_DIRECTORY', $baseDir); if (file_exists(__DIR__ . '/../vendor/autoload.php')) {