From 5c4a2ad0beb869bb18861969444f18b93b387221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 15:08:02 +0300 Subject: [PATCH 01/41] Add .idea to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a147ed3..8b80908 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ mage.phar ehthumbs.db Icon? Thumbs.db + +composer.phar +.idea \ No newline at end of file From 642773b5af8f4c249fc33f22af98fcb17c8da8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 15:36:14 +0300 Subject: [PATCH 02/41] PSR-2 style. --- .../Filesystem/LinkSharedFilesTask.php | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 4ed89a1..c0948f2 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -5,21 +5,44 @@ use Mage\Task\AbstractTask; use Mage\Task\Releases\IsReleaseAware; use Mage\Task\SkipException; +/** + * Class LinkSharedFilesTask + * + * @package Mage\Task\BuiltIn\Filesystem + * @author Andrey Kolchenko + */ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { - const LINKED_FOLDERS = 'linked_folders'; - const LINKED_STRATEGY = 'linking_strategy'; + /** + * Linked folders parameter name + */ + const LINKED_FOLDERS = 'linked_folders'; + /** + * Linking strategy parameter name + */ + const LINKED_STRATEGY = 'linking_strategy'; + /** + * Absolute linked strategy + */ const ABSOLUTE_LINKING = 'absolute'; + /** + * Relative linked strategy + */ const RELATIVE_LINKING = 'relative'; + /** + * @var array + */ public $linkingStrategies = array( self::ABSOLUTE_LINKING, self::RELATIVE_LINKING ); + /** * Returns the Title of the Task + * * @return string */ public function getName() @@ -35,11 +58,11 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware */ public function run() { - $linkedFiles = $this->getParameter('linked_files', []); - $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []); + $linkedFiles = $this->getParameter('linked_files', []); + $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []); $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); - $linkedEntities = array_merge($linkedFiles,$linkedFolders); + $linkedEntities = array_merge($linkedFiles, $linkedFolders); if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) { throw new SkipException('No files and folders configured for sym-linking.'); @@ -51,20 +74,23 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); - $relativeDiffPath = str_replace($this->getConfig()->deployment('to'),'',$currentCopy) . '/'; + $relativeDiffPath = str_replace($this->getConfig()->deployment('to'), '', $currentCopy) . '/'; foreach ($linkedEntities as $ePath) { - if(is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies ) ) { + if (is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies)) { $entityPath = key($ePath); } else { $strategy = $linkingStrategy; $entityPath = $ePath; } $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; - if($strategy==self::RELATIVE_LINKING) { + if ($strategy == self::RELATIVE_LINKING) { $parentFolderPath = dirname($entityPath); - $relativePath = $parentFolderPath=='.'?$relativeDiffPath:$relativeDiffPath.$parentFolderPath.'/'; - $sharedEntityLinkedPath = ltrim(preg_replace('/(\w+\/)/', '../', $relativePath),'/').$sharedFolderName .'/'. $entityPath; + $relativePath = $parentFolderPath == '.' ? $relativeDiffPath : $relativeDiffPath . $parentFolderPath . '/'; + $sharedEntityLinkedPath = ltrim( + preg_replace('/(\w+\/)/', '../', $relativePath), + '/' + ) . $sharedFolderName . '/' . $entityPath; } $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; $this->runCommandRemote($command); @@ -72,4 +98,4 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware return true; } -} \ No newline at end of file +} From 4c719f5efdfe419ae2daafe9dc3edd5d92cf33d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 15:37:07 +0300 Subject: [PATCH 03/41] PHP 5.3 does not support "[]" brackets. --- Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index c0948f2..16eb289 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -58,13 +58,13 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware */ public function run() { - $linkedFiles = $this->getParameter('linked_files', []); - $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, []); + $linkedFiles = $this->getParameter('linked_files', array()); + $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, array()); $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); $linkedEntities = array_merge($linkedFiles, $linkedFolders); - if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) { + if (empty($linkedFiles) && empty($linkedFolders)) { throw new SkipException('No files and folders configured for sym-linking.'); } From d52927fe07b39f756489f86b2f43fce30f0fbf98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 16:39:43 +0300 Subject: [PATCH 04/41] Get path and strategy. --- .../Filesystem/LinkSharedFilesTask.php | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 16eb289..d457d4d 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -35,7 +35,7 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware /** * @var array */ - public $linkingStrategies = array( + private static $linkingStrategies = array( self::ABSOLUTE_LINKING, self::RELATIVE_LINKING ); @@ -77,12 +77,7 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware $relativeDiffPath = str_replace($this->getConfig()->deployment('to'), '', $currentCopy) . '/'; foreach ($linkedEntities as $ePath) { - if (is_array($ePath) && in_array($strategy = reset($ePath), $this->linkingStrategies)) { - $entityPath = key($ePath); - } else { - $strategy = $linkingStrategy; - $entityPath = $ePath; - } + list($entityPath, $strategy) = $this->getPath($ePath); $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; if ($strategy == self::RELATIVE_LINKING) { $parentFolderPath = dirname($entityPath); @@ -98,4 +93,25 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware return true; } + + /** + * @param array|string $linkedEntity + * + * @return array [$path, $strategy] + */ + private function getPath($linkedEntity) + { + $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); + if (is_array($linkedEntity)) { + list($path, $strategy) = each($linkedEntity); + if (!in_array($strategy, self::$linkingStrategies)) { + $strategy = $linkingStrategy; + } + } else { + $strategy = $linkingStrategy; + $path = $linkedEntity; + } + + return [$path, $strategy]; + } } From ce2da4e270f2085ea5e2da9c064ee524635f6f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 16:42:13 +0300 Subject: [PATCH 05/41] Getting linked entities. --- .../BuiltIn/Filesystem/LinkSharedFilesTask.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index d457d4d..2276cca 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -13,7 +13,10 @@ use Mage\Task\SkipException; */ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { - + /** + * Linked folders parameter name + */ + const LINKED_FILES = 'linked_files'; /** * Linked folders parameter name */ @@ -58,13 +61,12 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware */ public function run() { - $linkedFiles = $this->getParameter('linked_files', array()); - $linkedFolders = $this->getParameter(self::LINKED_FOLDERS, array()); - $linkingStrategy = $this->getParameter(self::LINKED_STRATEGY, self::ABSOLUTE_LINKING); + $linkedEntities = array_merge( + $this->getParameter(self::LINKED_FILES, array()), + $this->getParameter(self::LINKED_FOLDERS, array()) + ); - $linkedEntities = array_merge($linkedFiles, $linkedFolders); - - if (empty($linkedFiles) && empty($linkedFolders)) { + if (empty($linkedEntities)) { throw new SkipException('No files and folders configured for sym-linking.'); } From 9d309007988a8220dd58d114a37dae88721406eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 17:12:49 +0300 Subject: [PATCH 06/41] Add symfony/filesystem to requires block. --- composer.json | 3 ++- composer.lock | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 composer.lock diff --git a/composer.json b/composer.json index 4018174..0063d15 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "type": "library", "keywords": ["deployment"], "require": { - "php": ">=5.3" + "php": ">=5.3", + "symfony/filesystem": ">=2.1.0,<=2.6.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..54108f8 --- /dev/null +++ b/composer.lock @@ -0,0 +1,66 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "e7a3fa9a09b1ab45ed140d6813a94262", + "packages": [ + { + "name": "symfony/filesystem", + "version": "v2.5.6", + "target-dir": "Symfony/Component/Filesystem", + "source": { + "type": "git", + "url": "https://github.com/symfony/Filesystem.git", + "reference": "4e62fab0060a826561c78b665925b37c870c45f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/4e62fab0060a826561c78b665925b37c870c45f5", + "reference": "4e62fab0060a826561c78b665925b37c870c45f5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Filesystem\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "http://symfony.com", + "time": "2014-09-22 09:14:18" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "platform": { + "php": ">=5.3" + }, + "platform-dev": [] +} From 3a41a860d055bd582949f4fdd2b4322ac6ffb6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 17:16:55 +0300 Subject: [PATCH 07/41] Make target dir before invoking "ln". Fix bug with spaces in path. --- .../Filesystem/LinkSharedFilesTask.php | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 2276cca..714b424 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -4,6 +4,7 @@ namespace Mage\Task\BuiltIn\Filesystem; use Mage\Task\AbstractTask; use Mage\Task\Releases\IsReleaseAware; use Mage\Task\SkipException; +use Symfony\Component\Filesystem\Filesystem; /** * Class LinkSharedFilesTask @@ -70,26 +71,23 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware throw new SkipException('No files and folders configured for sym-linking.'); } - $sharedFolderName = $this->getParameter('shared', 'shared'); - $sharedFolderPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; - $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - $releasesDirectoryPath = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; - + $remoteDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/'; + $sharedFolderPath = $remoteDirectory . $this->getParameter('shared', 'shared'); + $releasesDirectoryPath = $remoteDirectory . $this->getConfig()->release('directory', 'releases'); $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); - $relativeDiffPath = str_replace($this->getConfig()->deployment('to'), '', $currentCopy) . '/'; + $fileSystem = new Filesystem(); foreach ($linkedEntities as $ePath) { list($entityPath, $strategy) = $this->getPath($ePath); - $sharedEntityLinkedPath = "$sharedFolderPath/$entityPath"; - if ($strategy == self::RELATIVE_LINKING) { - $parentFolderPath = dirname($entityPath); - $relativePath = $parentFolderPath == '.' ? $relativeDiffPath : $relativeDiffPath . $parentFolderPath . '/'; - $sharedEntityLinkedPath = ltrim( - preg_replace('/(\w+\/)/', '../', $relativePath), - '/' - ) . $sharedFolderName . '/' . $entityPath; + if ($strategy === self::RELATIVE_LINKING) { + $dirName = dirname($currentCopy . '/' . $entityPath); + $target = $fileSystem->makePathRelative($sharedFolderPath, $dirName) . $entityPath; + } else { + $target = $sharedFolderPath . '/' . $entityPath; } - $command = "ln -nfs $sharedEntityLinkedPath $currentCopy/$entityPath"; + $command = 'mkdir -p ' . escapeshellarg(dirname($target)); + $this->runCommandRemote($command); + $command = 'ln -nfs ' . escapeshellarg($target) . ' ' . escapeshellarg($currentCopy . '/' . $entityPath); $this->runCommandRemote($command); } From 1dc97d77f88f3cdb670544a83aa28ed253a3fe14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Nov 2014 17:19:40 +0300 Subject: [PATCH 08/41] Fix email. --- 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 714b424..5d4346f 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -10,7 +10,7 @@ use Symfony\Component\Filesystem\Filesystem; * Class LinkSharedFilesTask * * @package Mage\Task\BuiltIn\Filesystem - * @author Andrey Kolchenko + * @author Andrey Kolchenko */ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { From 8ae83cbabd8622c6c4d40c4c5092d32ebf848ec8 Mon Sep 17 00:00:00 2001 From: Ismael Ambrosi Date: Fri, 5 Dec 2014 02:40:30 -0200 Subject: [PATCH 09/41] Use instanceof instead of method is_a Since is_a is a method, it is significantly slower than using instanceof Following is a perfomance comparison: http://micro-optimization.com/is_a-vs-instanceof --- Mage/Task/Factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index 912026f..57dff35 100644 --- a/Mage/Task/Factory.php +++ b/Mage/Task/Factory.php @@ -59,7 +59,7 @@ class Factory $instance = new $className($taskConfig, $inRollback, $stage, $taskParameters); - if (!is_a($instance, 'Mage\Task\AbstractTask')) { + if (!($instance instanceof AbstractTask)) { throw new Exception('The Task ' . $taskName . ' must be an instance of Mage\Task\AbstractTask.'); } From 2a8beeb864db194ece21b37ae91a896251e34d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D0=BB?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 8 Dec 2014 12:57:26 +0300 Subject: [PATCH 10/41] Remove symfony/filesystem from project depends. --- .../Filesystem/LinkSharedFilesTask.php | 41 +++++++++++++-- composer.json | 3 +- composer.lock | 52 +------------------ 3 files changed, 41 insertions(+), 55 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 5d4346f..2682b86 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -4,7 +4,6 @@ namespace Mage\Task\BuiltIn\Filesystem; use Mage\Task\AbstractTask; use Mage\Task\Releases\IsReleaseAware; use Mage\Task\SkipException; -use Symfony\Component\Filesystem\Filesystem; /** * Class LinkSharedFilesTask @@ -75,13 +74,12 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware $sharedFolderPath = $remoteDirectory . $this->getParameter('shared', 'shared'); $releasesDirectoryPath = $remoteDirectory . $this->getConfig()->release('directory', 'releases'); $currentCopy = $releasesDirectoryPath . '/' . $this->getConfig()->getReleaseId(); - $fileSystem = new Filesystem(); foreach ($linkedEntities as $ePath) { list($entityPath, $strategy) = $this->getPath($ePath); if ($strategy === self::RELATIVE_LINKING) { $dirName = dirname($currentCopy . '/' . $entityPath); - $target = $fileSystem->makePathRelative($sharedFolderPath, $dirName) . $entityPath; + $target = $this->makePathRelative($sharedFolderPath, $dirName) . $entityPath; } else { $target = $sharedFolderPath . '/' . $entityPath; } @@ -94,6 +92,43 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware return true; } + /** + * Given an existing path, convert it to a path relative to a given starting path + * + * @param string $endPath Absolute path of target + * @param string $startPath Absolute path where traversal begins + * + * @return string Path of target relative to starting path + * + * @author Fabien Potencier + * @see https://github.com/symfony/Filesystem/blob/v2.6.1/Filesystem.php#L332 + */ + private function makePathRelative($endPath, $startPath) + { + // Normalize separators on Windows + if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + $endPath = strtr($endPath, '\\', '/'); + $startPath = strtr($startPath, '\\', '/'); + } + // Split the paths into arrays + $startPathArr = explode('/', trim($startPath, '/')); + $endPathArr = explode('/', trim($endPath, '/')); + // Find for which directory the common path stops + $index = 0; + while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) { + $index++; + } + // Determine how deep the start path is relative to the common path (ie, "web/bundles" = 2 levels) + $depth = count($startPathArr) - $index; + // Repeated "../" for each level need to reach the common path + $traverser = str_repeat('../', $depth); + $endPathRemainder = implode('/', array_slice($endPathArr, $index)); + // Construct $endPath from traversing to the common path, then to the remaining $endPath + $relativePath = $traverser . (strlen($endPathRemainder) > 0 ? $endPathRemainder . '/' : ''); + + return (strlen($relativePath) === 0) ? './' : $relativePath; + } + /** * @param array|string $linkedEntity * diff --git a/composer.json b/composer.json index 27ef259..2183c74 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,7 @@ "type": "library", "keywords": ["deployment"], "require": { - "php": ">=5.3", - "symfony/filesystem": ">=2.1.0,<=2.6.0" + "php": ">=5.3" }, "require-dev": { "phpunit/phpunit": "4.3.5" diff --git a/composer.lock b/composer.lock index b341b73..bc2e079 100644 --- a/composer.lock +++ b/composer.lock @@ -4,56 +4,8 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "61974b12f91cf9124bfd75a369d20ff8", - "packages": [ - { - "name": "symfony/filesystem", - "version": "v2.6.0", - "target-dir": "Symfony/Component/Filesystem", - "source": { - "type": "git", - "url": "https://github.com/symfony/Filesystem.git", - "reference": "6f7c7e42f20ee200d8ac5d2ec1d2a524138305e0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Filesystem/zipball/6f7c7e42f20ee200d8ac5d2ec1d2a524138305e0", - "reference": "6f7c7e42f20ee200d8ac5d2ec1d2a524138305e0", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Filesystem\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Filesystem Component", - "homepage": "http://symfony.com", - "time": "2014-11-16 17:28:09" - } - ], + "hash": "a19528b890d301384e45c1ed7d221e26", + "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", From d2b7e0e94f9890d66d6841d0942deaa2c5ee00fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 13:58:06 +0100 Subject: [PATCH 11/41] Adds Permissions task. Parameters are : paths, checkPathsExist, owner, group, rights --- .../BuiltIn/Filesystem/PermissionsTask.php | 256 ++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsTask.php diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php new file mode 100644 index 0000000..ee4a91a --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -0,0 +1,256 @@ + + */ +class PermissionsTask extends AbstractTask +{ + /** + * Paths to change of permissions separated by PATH_SEPARATOR. + * + * @var string + */ + private $paths; + + /** + * If set to true, will check existance of given paths on remote host and + * throw SkipException if at least one does not exist. + * + * @var boolean + */ + private $checkPathsExist = true; + + /** + * Owner to set for the given paths (ex : "www-data") + * + * @var string + */ + private $owner; + + /** + * Group to set for the given paths (ex : "www-data") + * + * @var string + */ + private $group; + + /** + * Rights to set for the given paths (ex: "755") + * + * @var string + */ + private $rights; + + /** + * Initialize parameters. + * + * @throws SkipException + */ + public function init() + { + parent::init(); + + if (! is_null($this->getParameter('checkPathsExist'))) { + $this->setCheckPathsExist($this->getParameter('checkPathsExist')); + } + + if (! $this->getParameter('paths')) { + throw new SkipException('Param paths is mandatory'); + } + $this->setPaths(explode(PATH_SEPARATOR, $this->getParameter('paths', ''))); + + if (! is_null($this->getParameter('owner'))) { + $this->setOwner($this->getParameter('owner')); + } + + if (! is_null($this->getParameter('group'))) { + $this->setGroup($this->getParameter('group')); + } + + if (! is_null($this->getParameter('rights'))) { + $this->setRights($this->getParameter('rights')); + } + } + + /** + * @return string + */ + public function getName() + { + return "Change rights / owner / group for paths : " . $this->getPathsForCmd() . " [built-in]"; + } + + /** + * @return boolean + */ + public function run() + { + $command = ''; + + if ($this->paths && $this->owner) { + $command .= 'chown -R ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; + } + + if ($this->paths && $this->group) { + $command .= 'chgrp -R ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; + } + + if ($this->paths && $this->rights) { + $command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; + } + + $result = $this->runCommandRemote($command); + + return $result; + } + + /** + * Transforms paths array to a string separated by 1 space in order to use + * it in a command line. + * + * @return string + */ + protected function getPathsForCmd($paths = null) + { + if (is_null($paths)) { + $paths = $this->paths; + } + + return implode(' ', $paths); + } + + /** + * Set paths. Will check if they exist on remote host depending on + * checkPathsExist flag. + * + * @param array $paths + * @return PermissionsTask + * @throws SkipException + */ + protected function setPaths(array $paths) + { + if ($this->checkPathsExist == true) { + $commands = array(); + foreach ($paths as $path) { + $commands[] = '(([ -f ' . $path . ' ]) || ([ -d ' . $path . ' ]))'; + } + + $command = implode(' && ', $commands); + if (! $this->runCommandRemote($command)) { + throw new SkipException('Make sure all paths given exist on remote host : ' . $this->getPathsForCmd($paths)); + } + } + + $this->paths = $paths; + + return $this; + } + + /** + * @return string + */ + protected function getPaths() + { + return $this->paths; + } + + /** + * Set checkPathsExist. + * + * @param boolean $checkPathsExist + * @return PermissionsTask + */ + protected function setCheckPathsExist($checkPathsExist) + { + $this->checkPathsExist = $checkPathsExist; + + return $this; + } + + /** + * @return boolean + */ + protected function getCheckPathsExist() + { + return $this->checkPathsExist; + } + + /** + * Set owner. + * + * @todo check existance of $owner on remote, might be different ways depending on OS. + * + * @param string $owner + * @return PermissionsTask + */ + protected function setOwner($owner) + { + $this->owner = $owner; + + return $this; + } + + /** + * @return string + */ + protected function getOwner() + { + return $this->owner; + } + + /** + * Set group. + * + * @todo check existance of $group on remote, might be different ways depending on OS. + * + * @param string $group + * @return PermissionsTask + */ + protected function setGroup($group) + { + $this->group = $group; + + return $this; + } + + /** + * @return string + */ + protected function getGroup() + { + return $this->group; + } + + /** + * Set rights. + * + * @todo better way to check if $rights is in a correct format. + * + * @param string $rights + * @return PermissionsTask + */ + protected function setRights($rights) + { + if (strlen($rights) != 3 || !is_numeric($rights) || $rights > 777) { + throw new SkipException('Make sure the rights "' . $rights . '" are in a correct format.'); + } + + $this->rights = $rights; + + return $this; + } + + /** + * @return string + */ + protected function getRights() + { + return $this->rights; + } +} \ No newline at end of file From 8247b15ad009c213e26488825460aaa3aa8f12f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 13:59:57 +0100 Subject: [PATCH 12/41] Adds PermissionsWritableByApache task that extends Permissions task we predefined parameters --- .../PermissionsWritableByApacheTask.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php new file mode 100644 index 0000000..57d45da --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php @@ -0,0 +1,26 @@ + + */ +class PermissionsWritableByApacheTask extends PermissionsTask +{ + public function init() + { + parent::init(); + + $this->setGroup('www-data') + ->setRights('775'); + } + + /** + * @return string + */ + public function getName() + { + return "Gives write permissions to Apache user for given paths [built-in]"; + } +} \ No newline at end of file From a58dcbe7668dd8ebe7a5b39391d1203cfd96388b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 15:14:43 +0100 Subject: [PATCH 13/41] git local commands should be executed in the deployment:from directory --- Mage/Task/BuiltIn/Scm/ChangeBranchTask.php | 5 +++-- Mage/Task/BuiltIn/Scm/UpdateTask.php | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php b/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php index 8c5e33f..20859c5 100644 --- a/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php +++ b/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php @@ -63,14 +63,15 @@ class ChangeBranchTask extends AbstractTask */ public function run() { + $preCommand = 'cd ' . $this->getConfig()->deployment('from', './') . '; '; switch ($this->getConfig()->general('scm')) { case 'git': if ($this->getParameter('_changeBranchRevert', false)) { - $command = 'git checkout ' . self::$startingBranch; + $command = $preCommand . 'git checkout ' . self::$startingBranch; $result = $this->runCommandLocal($command); } else { - $command = 'git branch | grep \'*\' | cut -d\' \' -f 2'; + $command = $preCommand . 'git branch | grep \'*\' | cut -d\' \' -f 2'; $currentBranch = 'master'; $result = $this->runCommandLocal($command, $currentBranch); diff --git a/Mage/Task/BuiltIn/Scm/UpdateTask.php b/Mage/Task/BuiltIn/Scm/UpdateTask.php index 22c496e..3347a97 100644 --- a/Mage/Task/BuiltIn/Scm/UpdateTask.php +++ b/Mage/Task/BuiltIn/Scm/UpdateTask.php @@ -54,9 +54,10 @@ class UpdateTask extends AbstractTask */ public function run() { + $command = 'cd ' . $this->getConfig()->deployment('from', './') . '; '; switch ($this->getConfig()->general('scm')) { case 'git': - $command = 'git pull'; + $command .= 'git pull'; break; default: From 9d1e6aba6f996440a137753fda3c56744e03d736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 15:57:33 +0100 Subject: [PATCH 14/41] Allow for changing permissions on local host too depending on the stage --- .../BuiltIn/Filesystem/PermissionsTask.php | 28 +++++++++++++------ .../PermissionsWritableByApacheTask.php | 8 +++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php index ee4a91a..ab924af 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -5,7 +5,14 @@ use Mage\Task\AbstractTask; use Mage\Task\SkipException; /** - * Task for setting permissions on given paths. + * Task for setting permissions on given paths. Change will be done on local or + * remote host depending on the stage of the deployment. + * + * Usage : + * pre-deploy: + * - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} + * on-deploy: + * - filesystem/permissions: {paths: app/cache:app/logs, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} * * @author Jérémy Huet */ @@ -14,12 +21,15 @@ class PermissionsTask extends AbstractTask /** * Paths to change of permissions separated by PATH_SEPARATOR. * + * If the stage is on local host you should give full paths. If on remote + * you may give full or relative to the current release directory paths. + * * @var string */ private $paths; /** - * If set to true, will check existance of given paths on remote host and + * If set to true, will check existance of given paths on the host and * throw SkipException if at least one does not exist. * * @var boolean @@ -105,7 +115,7 @@ class PermissionsTask extends AbstractTask $command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; } - $result = $this->runCommandRemote($command); + $result = $this->runCommand($command); return $result; } @@ -126,7 +136,7 @@ class PermissionsTask extends AbstractTask } /** - * Set paths. Will check if they exist on remote host depending on + * Set paths. Will check if they exist on the host depending on * checkPathsExist flag. * * @param array $paths @@ -142,8 +152,8 @@ class PermissionsTask extends AbstractTask } $command = implode(' && ', $commands); - if (! $this->runCommandRemote($command)) { - throw new SkipException('Make sure all paths given exist on remote host : ' . $this->getPathsForCmd($paths)); + if (! $this->runCommand($command)) { + throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths)); } } @@ -184,7 +194,7 @@ class PermissionsTask extends AbstractTask /** * Set owner. * - * @todo check existance of $owner on remote, might be different ways depending on OS. + * @todo check existance of $owner on host, might be different ways depending on OS. * * @param string $owner * @return PermissionsTask @@ -207,7 +217,7 @@ class PermissionsTask extends AbstractTask /** * Set group. * - * @todo check existance of $group on remote, might be different ways depending on OS. + * @todo check existance of $group on host, might be different ways depending on OS. * * @param string $group * @return PermissionsTask @@ -253,4 +263,4 @@ class PermissionsTask extends AbstractTask { return $this->rights; } -} \ No newline at end of file +} diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php index 57d45da..c786e5e 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php @@ -4,6 +4,12 @@ namespace Mage\Task\BuiltIn\Filesystem; /** * Task for giving Apache write permissions on given paths. * + * Usage : + * pre-deploy: + * - filesystem/permissions-writable-by-apache: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true} + * on-deploy: + * - filesystem/permissions-writable-by-apache: {paths: app/cache:app/logs, checkPathsExist: true} + * * @author Jérémy Huet */ class PermissionsWritableByApacheTask extends PermissionsTask @@ -23,4 +29,4 @@ class PermissionsWritableByApacheTask extends PermissionsTask { return "Gives write permissions to Apache user for given paths [built-in]"; } -} \ No newline at end of file +} From 89d82b9992281763b59e13ce7638fa2663fcf2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 16:05:13 +0100 Subject: [PATCH 15/41] Changing EOL to Linux LF --- .../BuiltIn/Filesystem/PermissionsTask.php | 532 +++++++++--------- .../PermissionsWritableByApacheTask.php | 64 +-- 2 files changed, 298 insertions(+), 298 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php index ab924af..e04ef91 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -1,266 +1,266 @@ - - */ -class PermissionsTask extends AbstractTask -{ - /** - * Paths to change of permissions separated by PATH_SEPARATOR. - * - * If the stage is on local host you should give full paths. If on remote - * you may give full or relative to the current release directory paths. - * - * @var string - */ - private $paths; - - /** - * If set to true, will check existance of given paths on the host and - * throw SkipException if at least one does not exist. - * - * @var boolean - */ - private $checkPathsExist = true; - - /** - * Owner to set for the given paths (ex : "www-data") - * - * @var string - */ - private $owner; - - /** - * Group to set for the given paths (ex : "www-data") - * - * @var string - */ - private $group; - - /** - * Rights to set for the given paths (ex: "755") - * - * @var string - */ - private $rights; - - /** - * Initialize parameters. - * - * @throws SkipException - */ - public function init() - { - parent::init(); - - if (! is_null($this->getParameter('checkPathsExist'))) { - $this->setCheckPathsExist($this->getParameter('checkPathsExist')); - } - - if (! $this->getParameter('paths')) { - throw new SkipException('Param paths is mandatory'); - } - $this->setPaths(explode(PATH_SEPARATOR, $this->getParameter('paths', ''))); - - if (! is_null($this->getParameter('owner'))) { - $this->setOwner($this->getParameter('owner')); - } - - if (! is_null($this->getParameter('group'))) { - $this->setGroup($this->getParameter('group')); - } - - if (! is_null($this->getParameter('rights'))) { - $this->setRights($this->getParameter('rights')); - } - } - - /** - * @return string - */ - public function getName() - { - return "Change rights / owner / group for paths : " . $this->getPathsForCmd() . " [built-in]"; - } - - /** - * @return boolean - */ - public function run() - { - $command = ''; - - if ($this->paths && $this->owner) { - $command .= 'chown -R ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; - } - - if ($this->paths && $this->group) { - $command .= 'chgrp -R ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; - } - - if ($this->paths && $this->rights) { - $command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; - } - - $result = $this->runCommand($command); - - return $result; - } - - /** - * Transforms paths array to a string separated by 1 space in order to use - * it in a command line. - * - * @return string - */ - protected function getPathsForCmd($paths = null) - { - if (is_null($paths)) { - $paths = $this->paths; - } - - return implode(' ', $paths); - } - - /** - * Set paths. Will check if they exist on the host depending on - * checkPathsExist flag. - * - * @param array $paths - * @return PermissionsTask - * @throws SkipException - */ - protected function setPaths(array $paths) - { - if ($this->checkPathsExist == true) { - $commands = array(); - foreach ($paths as $path) { - $commands[] = '(([ -f ' . $path . ' ]) || ([ -d ' . $path . ' ]))'; - } - - $command = implode(' && ', $commands); - if (! $this->runCommand($command)) { - throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths)); - } - } - - $this->paths = $paths; - - return $this; - } - - /** - * @return string - */ - protected function getPaths() - { - return $this->paths; - } - - /** - * Set checkPathsExist. - * - * @param boolean $checkPathsExist - * @return PermissionsTask - */ - protected function setCheckPathsExist($checkPathsExist) - { - $this->checkPathsExist = $checkPathsExist; - - return $this; - } - - /** - * @return boolean - */ - protected function getCheckPathsExist() - { - return $this->checkPathsExist; - } - - /** - * Set owner. - * - * @todo check existance of $owner on host, might be different ways depending on OS. - * - * @param string $owner - * @return PermissionsTask - */ - protected function setOwner($owner) - { - $this->owner = $owner; - - return $this; - } - - /** - * @return string - */ - protected function getOwner() - { - return $this->owner; - } - - /** - * Set group. - * - * @todo check existance of $group on host, might be different ways depending on OS. - * - * @param string $group - * @return PermissionsTask - */ - protected function setGroup($group) - { - $this->group = $group; - - return $this; - } - - /** - * @return string - */ - protected function getGroup() - { - return $this->group; - } - - /** - * Set rights. - * - * @todo better way to check if $rights is in a correct format. - * - * @param string $rights - * @return PermissionsTask - */ - protected function setRights($rights) - { - if (strlen($rights) != 3 || !is_numeric($rights) || $rights > 777) { - throw new SkipException('Make sure the rights "' . $rights . '" are in a correct format.'); - } - - $this->rights = $rights; - - return $this; - } - - /** - * @return string - */ - protected function getRights() - { - return $this->rights; - } -} + + */ +class PermissionsTask extends AbstractTask +{ + /** + * Paths to change of permissions separated by PATH_SEPARATOR. + * + * If the stage is on local host you should give full paths. If on remote + * you may give full or relative to the current release directory paths. + * + * @var string + */ + private $paths; + + /** + * If set to true, will check existance of given paths on the host and + * throw SkipException if at least one does not exist. + * + * @var boolean + */ + private $checkPathsExist = true; + + /** + * Owner to set for the given paths (ex : "www-data") + * + * @var string + */ + private $owner; + + /** + * Group to set for the given paths (ex : "www-data") + * + * @var string + */ + private $group; + + /** + * Rights to set for the given paths (ex: "755") + * + * @var string + */ + private $rights; + + /** + * Initialize parameters. + * + * @throws SkipException + */ + public function init() + { + parent::init(); + + if (! is_null($this->getParameter('checkPathsExist'))) { + $this->setCheckPathsExist($this->getParameter('checkPathsExist')); + } + + if (! $this->getParameter('paths')) { + throw new SkipException('Param paths is mandatory'); + } + $this->setPaths(explode(PATH_SEPARATOR, $this->getParameter('paths', ''))); + + if (! is_null($this->getParameter('owner'))) { + $this->setOwner($this->getParameter('owner')); + } + + if (! is_null($this->getParameter('group'))) { + $this->setGroup($this->getParameter('group')); + } + + if (! is_null($this->getParameter('rights'))) { + $this->setRights($this->getParameter('rights')); + } + } + + /** + * @return string + */ + public function getName() + { + return "Change rights / owner / group for paths : " . $this->getPathsForCmd() . " [built-in]"; + } + + /** + * @return boolean + */ + public function run() + { + $command = ''; + + if ($this->paths && $this->owner) { + $command .= 'chown -R ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; + } + + if ($this->paths && $this->group) { + $command .= 'chgrp -R ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; + } + + if ($this->paths && $this->rights) { + $command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; + } + + $result = $this->runCommand($command); + + return $result; + } + + /** + * Transforms paths array to a string separated by 1 space in order to use + * it in a command line. + * + * @return string + */ + protected function getPathsForCmd($paths = null) + { + if (is_null($paths)) { + $paths = $this->paths; + } + + return implode(' ', $paths); + } + + /** + * Set paths. Will check if they exist on the host depending on + * checkPathsExist flag. + * + * @param array $paths + * @return PermissionsTask + * @throws SkipException + */ + protected function setPaths(array $paths) + { + if ($this->checkPathsExist == true) { + $commands = array(); + foreach ($paths as $path) { + $commands[] = '(([ -f ' . $path . ' ]) || ([ -d ' . $path . ' ]))'; + } + + $command = implode(' && ', $commands); + if (! $this->runCommand($command)) { + throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths)); + } + } + + $this->paths = $paths; + + return $this; + } + + /** + * @return string + */ + protected function getPaths() + { + return $this->paths; + } + + /** + * Set checkPathsExist. + * + * @param boolean $checkPathsExist + * @return PermissionsTask + */ + protected function setCheckPathsExist($checkPathsExist) + { + $this->checkPathsExist = $checkPathsExist; + + return $this; + } + + /** + * @return boolean + */ + protected function getCheckPathsExist() + { + return $this->checkPathsExist; + } + + /** + * Set owner. + * + * @todo check existance of $owner on host, might be different ways depending on OS. + * + * @param string $owner + * @return PermissionsTask + */ + protected function setOwner($owner) + { + $this->owner = $owner; + + return $this; + } + + /** + * @return string + */ + protected function getOwner() + { + return $this->owner; + } + + /** + * Set group. + * + * @todo check existance of $group on host, might be different ways depending on OS. + * + * @param string $group + * @return PermissionsTask + */ + protected function setGroup($group) + { + $this->group = $group; + + return $this; + } + + /** + * @return string + */ + protected function getGroup() + { + return $this->group; + } + + /** + * Set rights. + * + * @todo better way to check if $rights is in a correct format. + * + * @param string $rights + * @return PermissionsTask + */ + protected function setRights($rights) + { + if (strlen($rights) != 3 || !is_numeric($rights) || $rights > 777) { + throw new SkipException('Make sure the rights "' . $rights . '" are in a correct format.'); + } + + $this->rights = $rights; + + return $this; + } + + /** + * @return string + */ + protected function getRights() + { + return $this->rights; + } +} diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php index c786e5e..5bb3f7c 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php @@ -1,32 +1,32 @@ - - */ -class PermissionsWritableByApacheTask extends PermissionsTask -{ - public function init() - { - parent::init(); - - $this->setGroup('www-data') - ->setRights('775'); - } - - /** - * @return string - */ - public function getName() - { - return "Gives write permissions to Apache user for given paths [built-in]"; - } -} + + */ +class PermissionsWritableByApacheTask extends PermissionsTask +{ + public function init() + { + parent::init(); + + $this->setGroup('www-data') + ->setRights('775'); + } + + /** + * @return string + */ + public function getName() + { + return "Gives write permissions to Apache user for given paths [built-in]"; + } +} From e449a4529fc52987afb8f2170ac5f0c597ec3b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 16:22:56 +0100 Subject: [PATCH 16/41] Adds a recursive parameter and allows for more chmod possibilities such as +a --- .../BuiltIn/Filesystem/PermissionsTask.php | 51 +++++++++++++++---- .../PermissionsWritableByApacheTask.php | 6 +-- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php index e04ef91..167f1d2 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -10,9 +10,9 @@ use Mage\Task\SkipException; * * Usage : * pre-deploy: - * - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} + * - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, recursive: false, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} * on-deploy: - * - filesystem/permissions: {paths: app/cache:app/logs, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} + * - filesystem/permissions: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} * * @author Jérémy Huet */ @@ -57,6 +57,13 @@ class PermissionsTask extends AbstractTask */ private $rights; + /** + * If set to true, will recursively change permissions on given paths. + * + * @var string + */ + private $recursive = false; + /** * Initialize parameters. * @@ -86,6 +93,10 @@ class PermissionsTask extends AbstractTask if (! is_null($this->getParameter('rights'))) { $this->setRights($this->getParameter('rights')); } + + if (! is_null($this->getParameter('recursive'))) { + $this->setRecursive($this->getParameter('recursive')); + } } /** @@ -102,17 +113,18 @@ class PermissionsTask extends AbstractTask public function run() { $command = ''; + $recursive = $this->recursive ? '-R' : ''; if ($this->paths && $this->owner) { - $command .= 'chown -R ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; + $command .= 'chown '. $recursive .' ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; } if ($this->paths && $this->group) { - $command .= 'chgrp -R ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; + $command .= 'chgrp '. $recursive .' ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; } if ($this->paths && $this->rights) { - $command .= 'chmod -R ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; + $command .= 'chmod '. $recursive .' ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; } $result = $this->runCommand($command); @@ -178,7 +190,7 @@ class PermissionsTask extends AbstractTask */ protected function setCheckPathsExist($checkPathsExist) { - $this->checkPathsExist = $checkPathsExist; + $this->checkPathsExist = (bool) $checkPathsExist; return $this; } @@ -240,17 +252,13 @@ class PermissionsTask extends AbstractTask /** * Set rights. * - * @todo better way to check if $rights is in a correct format. + * @todo check if $rights is in a correct format. * * @param string $rights * @return PermissionsTask */ protected function setRights($rights) { - if (strlen($rights) != 3 || !is_numeric($rights) || $rights > 777) { - throw new SkipException('Make sure the rights "' . $rights . '" are in a correct format.'); - } - $this->rights = $rights; return $this; @@ -263,4 +271,25 @@ class PermissionsTask extends AbstractTask { return $this->rights; } + + /** + * Set recursive. + * + * @param boolean $recursive + * @return PermissionsTask + */ + protected function setRecursive($recursive) + { + $this->recursive = (bool) $recursive; + + return $this; + } + + /** + * @return boolean + */ + protected function getRecursive() + { + return $this->recursive; + } } diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php index 5bb3f7c..defd90e 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php @@ -6,9 +6,9 @@ namespace Mage\Task\BuiltIn\Filesystem; * * Usage : * pre-deploy: - * - filesystem/permissions-writable-by-apache: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, checkPathsExist: true} + * - filesystem/permissions-writable-by-apache: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, recursive: false, checkPathsExist: true} * on-deploy: - * - filesystem/permissions-writable-by-apache: {paths: app/cache:app/logs, checkPathsExist: true} + * - filesystem/permissions-writable-by-apache: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true} * * @author Jérémy Huet */ @@ -19,7 +19,7 @@ class PermissionsWritableByApacheTask extends PermissionsTask parent::init(); $this->setGroup('www-data') - ->setRights('775'); + ->setRights('g+w'); } /** From 979a86992cbc9dcd3ef3674f1c71ff766eca4708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sat, 13 Dec 2014 16:44:47 +0100 Subject: [PATCH 17/41] More generic way to retrieve web server user --- .../PermissionsWritableByApacheTask.php | 32 ----------- .../PermissionsWritableByWebServerTask.php | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 32 deletions(-) delete mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php create mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php deleted file mode 100644 index defd90e..0000000 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByApacheTask.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -class PermissionsWritableByApacheTask extends PermissionsTask -{ - public function init() - { - parent::init(); - - $this->setGroup('www-data') - ->setRights('g+w'); - } - - /** - * @return string - */ - public function getName() - { - return "Gives write permissions to Apache user for given paths [built-in]"; - } -} diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php new file mode 100644 index 0000000..69ad065 --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php @@ -0,0 +1,54 @@ + + */ +class PermissionsWritableByWebServerTask extends PermissionsTask +{ + /** + * Set group with web server user and give group write permissions. + */ + public function init() + { + parent::init(); + + $this->setGroup($this->getParameter('group', $this->getWebServerUser())) + ->setRights('g+w'); + } + + /** + * @return string + */ + public function getName() + { + return "Gives write permissions to web server user for given paths [built-in]"; + } + + /** + * Tries to guess the web server user by going thru the running processes. + * + * @return string + * @throws SkipException + */ + protected function getWebServerUser() + { + $this->runCommand("ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1", $webServerUser); + + if (empty($webServerUser)) { + throw new SkipException("Can't guess web server user. Please check if it is running or force it by setting the group parameter"); + } + + return $webServerUser; + } +} From ffdadb45cf480a7522ec2962c847c6a29596629a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Mon, 15 Dec 2014 18:50:09 +0100 Subject: [PATCH 18/41] More generic way to handle command line options --- .../BuiltIn/Filesystem/PermissionsTask.php | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php index 167f1d2..981a0de 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -113,18 +113,17 @@ class PermissionsTask extends AbstractTask public function run() { $command = ''; - $recursive = $this->recursive ? '-R' : ''; if ($this->paths && $this->owner) { - $command .= 'chown '. $recursive .' ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; + $command .= 'chown '. $this->getOptionsForCmd() .' ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; } if ($this->paths && $this->group) { - $command .= 'chgrp '. $recursive .' ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; + $command .= 'chgrp '. $this->getOptionsForCmd() .' ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; } if ($this->paths && $this->rights) { - $command .= 'chmod '. $recursive .' ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; + $command .= 'chmod '. $this->getOptionsForCmd() .' ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; } $result = $this->runCommand($command); @@ -132,6 +131,27 @@ class PermissionsTask extends AbstractTask return $result; } + /** + * Returns the options for the commands to run. Only supports -R for now. + * + * @return string + */ + protected function getOptionsForCmd() + { + $optionsForCmd = ''; + $options = array( + 'R' => $this->recursive + ); + + foreach($options as $option => $apply) { + if ($apply == true) { + $optionsForCmd .= $option; + } + } + + return $optionsForCmd ? '-' . $optionsForCmd : ''; + } + /** * Transforms paths array to a string separated by 1 space in order to use * it in a command line. From 209c6b9aa319184f973b459b1d4a4d3abc5a4394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Mon, 15 Dec 2014 18:50:27 +0100 Subject: [PATCH 19/41] typo --- .../BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php index 69ad065..66ba1d7 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php @@ -8,7 +8,7 @@ use Mage\Task\SkipException; * * Usage : * pre-deploy: - * - filesystem/permissions-writable-by-web-server: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, recursive: false, checkPathsExist: true} + * - filesystem/permissions-writable-by-web-server: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/logs, recursive: false, checkPathsExist: true} * on-deploy: * - filesystem/permissions-writable-by-web-server: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true} * From 42d3d5a8a139c61b1d663e5ab0616ebb9af59f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Thu, 18 Dec 2014 17:45:12 +0100 Subject: [PATCH 20/41] Better usage doc + allow to set owner and group by using www-data:www-data syntax + task now fails if at least one command returns error --- .../BuiltIn/Filesystem/PermissionsTask.php | 48 ++++++++++++------- .../PermissionsWritableByWebServerTask.php | 8 +++- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php index 981a0de..8f1f6f4 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -11,6 +11,14 @@ use Mage\Task\SkipException; * Usage : * pre-deploy: * - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, recursive: false, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} + * - filesystem/permissions: + * paths: + * - /var/www/myapp/app/cache + * - /var/www/myapp/app/logs + * recursive: false + * checkPathsExist: true + * owner: www-data:www-data + * rights: 775 * on-deploy: * - filesystem/permissions: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} * @@ -37,7 +45,8 @@ class PermissionsTask extends AbstractTask private $checkPathsExist = true; /** - * Owner to set for the given paths (ex : "www-data") + * Owner to set for the given paths (ex : "www-data" or "www-data:www-data" + * to set both owner and group at the same time) * * @var string */ @@ -51,7 +60,7 @@ class PermissionsTask extends AbstractTask private $group; /** - * Rights to set for the given paths (ex: "755") + * Rights to set for the given paths (ex: "755" or "g+w") * * @var string */ @@ -80,22 +89,27 @@ class PermissionsTask extends AbstractTask if (! $this->getParameter('paths')) { throw new SkipException('Param paths is mandatory'); } - $this->setPaths(explode(PATH_SEPARATOR, $this->getParameter('paths', ''))); + $this->setPaths(is_array($this->getParameter('paths')) ? $this->getParameter('paths') : explode(PATH_SEPARATOR, $this->getParameter('paths', ''))); - if (! is_null($this->getParameter('owner'))) { - $this->setOwner($this->getParameter('owner')); + if (! is_null($owner = $this->getParameter('owner'))) { + if (strpos($owner, ':') !== false) { + $this->setOwner(array_shift(explode(':', $owner))); + $this->setGroup(array_pop(explode(':', $owner))); + } else { + $this->setOwner($owner); + } } - if (! is_null($this->getParameter('group'))) { - $this->setGroup($this->getParameter('group')); + if (! is_null($group = $this->getParameter('group'))) { + $this->setGroup($group); } - if (! is_null($this->getParameter('rights'))) { - $this->setRights($this->getParameter('rights')); + if (! is_null($rights = $this->getParameter('rights'))) { + $this->setRights($rights); } - if (! is_null($this->getParameter('recursive'))) { - $this->setRecursive($this->getParameter('recursive')); + if (! is_null($recursive = $this->getParameter('recursive'))) { + $this->setRecursive($recursive); } } @@ -104,7 +118,7 @@ class PermissionsTask extends AbstractTask */ public function getName() { - return "Change rights / owner / group for paths : " . $this->getPathsForCmd() . " [built-in]"; + return "Changing rights / owner / group for given paths [built-in]"; } /** @@ -112,21 +126,21 @@ class PermissionsTask extends AbstractTask */ public function run() { - $command = ''; + $commands = array(); if ($this->paths && $this->owner) { - $command .= 'chown '. $this->getOptionsForCmd() .' ' . $this->owner . ' ' . $this->getPathsForCmd() . ';'; + $commands []= 'chown '. $this->getOptionsForCmd() .' ' . $this->owner . ' ' . $this->getPathsForCmd(); } if ($this->paths && $this->group) { - $command .= 'chgrp '. $this->getOptionsForCmd() .' ' . $this->group . ' ' . $this->getPathsForCmd() . ';'; + $commands []= 'chgrp '. $this->getOptionsForCmd() .' ' . $this->group . ' ' . $this->getPathsForCmd(); } if ($this->paths && $this->rights) { - $command .= 'chmod '. $this->getOptionsForCmd() .' ' . $this->rights . ' ' . $this->getPathsForCmd() . ';'; + $commands []= 'chmod '. $this->getOptionsForCmd() .' ' . $this->rights . ' ' . $this->getPathsForCmd(); } - $result = $this->runCommand($command); + $result = $this->runCommand(implode(' && ', $commands)); return $result; } diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php index 66ba1d7..ec1fe7d 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php @@ -9,6 +9,12 @@ use Mage\Task\SkipException; * Usage : * pre-deploy: * - filesystem/permissions-writable-by-web-server: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/logs, recursive: false, checkPathsExist: true} + * - filesystem/permissions-writable-by-web-server: + * paths: + * - /var/www/myapp/app/cache + * - /var/www/myapp/app/logs + * recursive: false + * checkPathsExist: true * on-deploy: * - filesystem/permissions-writable-by-web-server: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true} * @@ -32,7 +38,7 @@ class PermissionsWritableByWebServerTask extends PermissionsTask */ public function getName() { - return "Gives write permissions to web server user for given paths [built-in]"; + return "Giving write permissions to web server user for given paths [built-in]"; } /** From fbc50a52bd25d5d9eb2e5d59e2c57cfe93b7ae9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Thu, 18 Dec 2014 17:46:13 +0100 Subject: [PATCH 21/41] Adds a task to only have read permission for web server --- ...PermissionsReadableOnlyByWebServerTask.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php new file mode 100644 index 0000000..d0a04e8 --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php @@ -0,0 +1,60 @@ + + */ +class PermissionsReadableOnlyByWebServerTask extends PermissionsTask +{ + /** + * Set group with web server user and give group write permissions. + */ + public function init() + { + parent::init(); + + $this->setGroup($this->getParameter('group', $this->getWebServerUser())) + ->setRights('040'); + } + + /** + * @return string + */ + public function getName() + { + return "Giving read permissions only to web server user for given paths [built-in]"; + } + + /** + * Tries to guess the web server user by going thru the running processes. + * + * @return string + * @throws SkipException + */ + protected function getWebServerUser() + { + $this->runCommand("ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1", $webServerUser); + + if (empty($webServerUser)) { + throw new SkipException("Can't guess web server user. Please check if it is running or force it by setting the group parameter"); + } + + return $webServerUser; + } +} From 3b70a8a3c1e3a8b894bcd118e61df9302c574621 Mon Sep 17 00:00:00 2001 From: Dmitry Motylev Date: Tue, 23 Dec 2014 17:34:48 +0000 Subject: [PATCH 22/41] fix: DeployCommand does not fail when no one "Post-Deployment Tasks" failed and failed "Deployment Task" exist --- Mage/Command/BuiltIn/DeployCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 943a630..f53eac0 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -202,7 +202,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment if (self::$failedTasks === 0) { $exitCode = 0; } - + + if (self::$deployStatus === self::FAILED) { + $exitCode = 1; + } + return $exitCode; } From 5643616e50581dbb29d8ce1b177af56b1c297ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Huet?= Date: Sun, 28 Dec 2014 16:47:59 +0100 Subject: [PATCH 23/41] Only tries to guess web server user if none provided with 'group' parameter --- .../Filesystem/PermissionsReadableOnlyByWebServerTask.php | 2 +- Mage/Task/BuiltIn/Filesystem/PermissionsTask.php | 3 ++- .../BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php index d0a04e8..375489d 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsReadableOnlyByWebServerTask.php @@ -29,7 +29,7 @@ class PermissionsReadableOnlyByWebServerTask extends PermissionsTask { parent::init(); - $this->setGroup($this->getParameter('group', $this->getWebServerUser())) + $this->setGroup($this->getParameter('group') ? $this->getParameter('group') : $this->getWebServerUser()) ->setRights('040'); } diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php index 8f1f6f4..171770b 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsTask.php @@ -27,7 +27,8 @@ use Mage\Task\SkipException; class PermissionsTask extends AbstractTask { /** - * Paths to change of permissions separated by PATH_SEPARATOR. + * Paths to change of permissions in an array or a string separated by + * PATH_SEPARATOR. * * If the stage is on local host you should give full paths. If on remote * you may give full or relative to the current release directory paths. diff --git a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php index ec1fe7d..6abaf07 100644 --- a/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php +++ b/Mage/Task/BuiltIn/Filesystem/PermissionsWritableByWebServerTask.php @@ -29,7 +29,7 @@ class PermissionsWritableByWebServerTask extends PermissionsTask { parent::init(); - $this->setGroup($this->getParameter('group', $this->getWebServerUser())) + $this->setGroup($this->getParameter('group') ? $this->getParameter('group') : $this->getWebServerUser()) ->setRights('g+w'); } From 70c482358164a61be7f6ef82d7e97ca3a24b5077 Mon Sep 17 00:00:00 2001 From: Alexander Miehe Date: Fri, 9 Jan 2015 14:05:37 +0100 Subject: [PATCH 24/41] Add config option to set ConnectTimeout for ssh connections --- Mage/Config.php | 10 ++++++++++ Mage/Task/AbstractTask.php | 1 + Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Mage/Config.php b/Mage/Config.php index e839c22..dd78593 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -391,6 +391,16 @@ class Config return $this->deployment('identity-file') ? ('-i ' . $this->deployment('identity-file') . ' ') : ''; } + /** + * Get the ConnectTimeout option + * + * @return string + */ + public function getConnectTimeoutOption() + { + return $this->environmentConfig('connect-timeout') ? ('-o ConnectTimeout=' . $this->environmentConfig('connect-timeout') . ' ') : ''; + } + /** * Get the current Host * diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 663b387..491adfb 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -201,6 +201,7 @@ abstract class AbstractTask $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' ' . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' + . $this->getConfig()->getConnectTimeoutOption() . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName(); $remoteCommand = str_replace('"', '\"', $command); diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index d45ea17..9bb1b25 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -89,7 +89,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware } // Copy Tar Gz to Remote Host - $command = 'scp ' . $strategyFlags . ' ' . $this->getConfig()->getHostIdentityFileOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz ' + $command = 'scp ' . $strategyFlags . ' ' . $this->getConfig()->getHostIdentityFileOption() . $this->getConfig()->getConnectTimeoutOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory; $result = $this->runCommandLocal($command) && $result; From 4e17263773ea06b64aa6c191ec0875adfaaf43d9 Mon Sep 17 00:00:00 2001 From: Stefan Paletta Date: Fri, 9 Jan 2015 17:27:14 +0100 Subject: [PATCH 25/41] =?UTF-8?q?switch=20the=20=C2=BBcurrent=C2=AB=20syml?= =?UTF-8?q?ink=20in=20an=20atomic=20way?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 7 ++++--- Mage/Task/BuiltIn/Releases/RollbackTask.php | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 84187ad..e7baf30 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -75,9 +75,10 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride } // Remove symlink if exists; create new symlink and change owners - $command = 'rm -f ' . $symlink - . ' ; ' - . 'ln -sf ' . $currentCopy . ' ' . $symlink; + $tmplink = $currentCopy . '.tmp'; + $command = 'ln -sfn ' . $currentCopy . ' ' . $tmplink + . ' && ' + . 'mv -T ' . $tmplink . ' ' . $symlink; if ($resultFetch && $userGroup != '') { $command .= ' && ' diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 7a437fd..1aff8e3 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -127,9 +127,11 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $userGroup = ''; $resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup); - $command = 'rm -f ' . $symlink + + $tmplink = $rollbackTo . '.tmp'; + $command = 'ln -sfn ' . $currentCopy . ' ' . $tmplink . ' && ' - . 'ln -sf ' . $rollbackTo . ' ' . $symlink; + . 'mv -T ' . $tmplink . ' ' . $symlink; if ($resultFetch) { $command .= ' && chown -h ' . $userGroup . ' ' . $symlink; From 4cdb95f3beb1aaaa11010b01a92cd5a33d4c0f9d Mon Sep 17 00:00:00 2001 From: Alexander Miehe Date: Mon, 12 Jan 2015 19:50:19 +0100 Subject: [PATCH 26/41] make h option for targz optional, default is set h option --- Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index 9bb1b25..625bd7b 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -77,7 +77,10 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $strategyFlags = ''; } - $command = 'tar cfzh' . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . $excludeFromFileCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .'; + // remove h option only if dump_symlinks is allowed in the release config part + $dumpSymlinks = $this->getConfig()->release('dump_symlinks') ? '' : 'h'; + + $command = 'tar cfz'. $dumpSymlinks . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . $excludeFromFileCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .'; $result = $this->runCommandLocal($command); // Strategy Flags From bbeedffd82f5683918aec5b8f865560f48e88909 Mon Sep 17 00:00:00 2001 From: Stefan Paletta Date: Tue, 13 Jan 2015 17:16:52 +0100 Subject: [PATCH 27/41] make ApplyFaclsTask compatible with default AbstractTask::runCommandRemote()parameter $cdToDirectoryFirst=true --- Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php b/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php index 03786ce..3f40ee7 100644 --- a/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php @@ -25,7 +25,6 @@ class ApplyFaclsTask extends AbstractTask implements IsReleaseAware public function run() { $releasesDirectory = $this->getConfig()->release('directory', 'releases'); - $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); From 55a5c0c640f939d0164fbea503467e4102c71709 Mon Sep 17 00:00:00 2001 From: Alexander Miehe Date: Wed, 14 Jan 2015 09:30:52 +0100 Subject: [PATCH 28/41] Fix key name to follow naming convention --- Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index 625bd7b..ba16246 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -77,8 +77,8 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $strategyFlags = ''; } - // remove h option only if dump_symlinks is allowed in the release config part - $dumpSymlinks = $this->getConfig()->release('dump_symlinks') ? '' : 'h'; + // remove h option only if dump-symlinks is allowed in the release config part + $dumpSymlinks = $this->getConfig()->release('dump-symlinks') ? '' : 'h'; $command = 'tar cfz'. $dumpSymlinks . $strategyFlags . ' ' . $localTarGz . '.tar.gz ' . $excludeCmd . $excludeFromFileCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .'; $result = $this->runCommandLocal($command); From 1a81e7000ba347b680972d7d92440a0c74c62e38 Mon Sep 17 00:00:00 2001 From: Alexander Miehe Date: Wed, 14 Jan 2015 11:49:31 +0100 Subject: [PATCH 29/41] Add example config with explanation --- .../production.yml.dump-symlinks.txt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docs/example-config/.mage/config/environment/production.yml.dump-symlinks.txt diff --git a/docs/example-config/.mage/config/environment/production.yml.dump-symlinks.txt b/docs/example-config/.mage/config/environment/production.yml.dump-symlinks.txt new file mode 100644 index 0000000..1ff2547 --- /dev/null +++ b/docs/example-config/.mage/config/environment/production.yml.dump-symlinks.txt @@ -0,0 +1,43 @@ +#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 +# This option allows to dump the symlink with the TarGz strategy and use the symlink on the deployment host. +# This is useful, if the files the symlink point to only exist on the deployment host and not on the host who runs the mage command. +# The default value is false to keep bc. +# See : http://linux.die.net/man/1/tar -h, --dereference + dump-symlinks: true +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 27bc2b7de097cbb1fe2ee2b5af1b61d6920c2d32 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Fri, 16 Jan 2015 19:36:25 +0100 Subject: [PATCH 30/41] Add contribution guidelines --- CONTRIBUTING.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..826aaf2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,71 @@ +Contributor guidelines for Magallanes +===================================== +Welcome to Magallanes! We are much appreciated you've decided to contribute this project! +Please read the following guidelines to make your and our work easier and cleaner. + +**TL;DR** + +1. Write clean code with no mess left +2. Contribute the docs when adding configurable new feature +3. Push your code into `develop` branch +4. Ensure your code is fully covered by tests + + +---------- + +# Reporting issues +If you have a problem or you've noticed some bug, please feel free to open new issue. However please follow the rules below: +* First, make sure that similar/the same issue doesn't already exist +* If you've already found the solution of the problem you are about to report, plaase feel free to open new pull request. Then follow the rules below in **Developing Magallanes** section. +* If you are able to, include some test cases or steps to reproduce the bug for us to examine the problem to reach the problem origin. + +## Opening pull requests +Pull Request are actually some kind of issues with code, so please keep the rules above in **Reporting issues** section before making the pull requests. +Our code isn't so beautiful, tested and testable as we would like it to be but if you're pushing your code please be sure it meets the requirements from **Organization and code quality** chapter. We want to improve the existing code to facilitate extending it and making fixes quicker. So if you are editing some class and you find it ugly, please do not ignore it. Following [The Boy Scout Rule](http://www.informit.com/articles/article.aspx?p=1235624&seqNum=6) - *Leave the campground cleaner than you found it* - we allcan improve the existing code. + +## Contributing the documentation +Magallanes is made to deploy application quick and with no need to write redudant code. Usage is as simple as writing the configuration for target project in YAML files. In the nearest future we would like to make some Wiki with all available options, tasks and commands. For now, the only "documentation" is examples file in `doc` directory. If the code you are going to include in your pull requests adds or changes config options, please make sure you that you create a new sample in that file. You should also to the same with commands. + +# Developing Magallanes +## Branches +The flow is pretty simple. +In most common cases we work on `develop` branch. It's a branch with the newest changes which sometimes need more testing. All pull requests are opened to be merged into that branch. That keeps us safe to not deploy unsafe code into production - `master` branch. When we decide that every changeset in `develop` is tested manually and works as it's intented, we merge it to master. +If the change you commited is pretty hot and needs to be released ASAP, you are allowed to make a pull request to `master` branch. But it's the only case, please try to avoid it. All pull request that are not made on `develop` will be rejected. +If you want to use develop branch in your code, simple pass `dev-develop` to dependency version in your `composer.json` file: +```json +{ + "require": { + "andres-montanez/magallanes": "dev-develop" + } +} +``` +## Organization and code quality +We use [PSR2](http://www.php-fig.org/psr/psr-2/) as PHP coding standard. +Some of rules we follow that are not included in document above: + +* Variables' and properties' names are camelCased (e.g.: `$thisIsMyVariable`) +* Avoid too long or too short variables' and methods' names, like `$thisIsMyAwesomeVariableAndImProudOfIt` +* Names of your properties/method should be intuitive and self-describing - that means your code should look like a book. Developer who reads the code should immediately know what the variable includes or what the method does. +* Let your methods will be verbs. For boolean methods, prefix it with `is`, `has`, and so on. E.g.: `isConfigurable`, `hasChildren`. +* Be [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29) and follow [KISS](http://en.wikipedia.org/wiki/KISS_principle) - let the class be responsible only for its tasks. +* Write testable code and if there's a need - easy extendible. +* Avoid duplications + +The rules above have been set a long time after the project has started. If you notice some violations, plase open new issue or even pull request with fixes, we'll be much appreciated. + +### Tools you can use to ensure your code quality + +1. **PHP-CodeSniffer** +2. **PHP Mess Detector** +3. PHP Copy/Paste Detector +4. PHP Dead Code Detector + +## Testing and quality +We use PHPUnit to test our classes. Now not the whole project is covered with tests but we've been working on it for some time. If you want your code to be merged into Magallanes, we want you to push it with proper tests. We would love to reach and keep at leats 90% of code coverage. In short time we want to configure quality tools to make sure your code is tested properly with minimum coverage. Anyway, try to keep 100% of Code Coverage in your pull requests. +Tests structure follow the same structure as production code with `Test` suffix in class and file name. All tests should go to `tests` directory in project root. So if you've created a class `Mage\Tasks\BuilIn\NewTask` the testing class should be called `MageTest\Tasks\BuiltIn\NewTaskTest`. + +## Configuration +Magallanes configuration is kept in YAML files. Please follow those rules whie adding or changing the configuration: +* Keep 2 spaces indentation in each level +* Multi-word config keys should be joined with dash (`-`), like `my-custom-task` +* If your contribution includes new config key, please be sure that you've documented it in configuration documentation. From 257b7ab03ebce01c32fd70948a1fecdba5afe14a Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Sat, 17 Jan 2015 13:31:51 +0100 Subject: [PATCH 31/41] Correct typo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 826aaf2..767b314 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,7 @@ We use PHPUnit to test our classes. Now not the whole project is covered with te Tests structure follow the same structure as production code with `Test` suffix in class and file name. All tests should go to `tests` directory in project root. So if you've created a class `Mage\Tasks\BuilIn\NewTask` the testing class should be called `MageTest\Tasks\BuiltIn\NewTaskTest`. ## Configuration -Magallanes configuration is kept in YAML files. Please follow those rules whie adding or changing the configuration: +Magallanes configuration is kept in YAML files. Please follow those rules while adding or changing the configuration: * Keep 2 spaces indentation in each level * Multi-word config keys should be joined with dash (`-`), like `my-custom-task` * If your contribution includes new config key, please be sure that you've documented it in configuration documentation. From 4673d266704902f243d77a74c5ac1cd97b8c496b Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Fri, 23 Jan 2015 19:40:23 +0100 Subject: [PATCH 32/41] [#183] Add some instructions about code coverage --- CONTRIBUTING.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 767b314..710c26b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,7 +61,15 @@ The rules above have been set a long time after the project has started. If you 4. PHP Dead Code Detector ## Testing and quality -We use PHPUnit to test our classes. Now not the whole project is covered with tests but we've been working on it for some time. If you want your code to be merged into Magallanes, we want you to push it with proper tests. We would love to reach and keep at leats 90% of code coverage. In short time we want to configure quality tools to make sure your code is tested properly with minimum coverage. Anyway, try to keep 100% of Code Coverage in your pull requests. +We use PHPUnit to test our classes. Now not the whole project is covered with tests but we've been working on it for some time. If you want your code to be merged into Magallanes, we want you to push it with proper tests. We would love to reach and keep at least 90% of line code coverage. In short time we want to configure quality tools to make sure your code is tested properly with minimum coverage. Anyway, try to keep 100% of Code Coverage in your pull requests. To run your tests with code coverage report, you can either run it with: +``` +/bin/phpunit --coverage-text +``` +or with more friendly and detailed user graphical representation, into HTML: +``` +/bin/phpunit --coverate-html report +``` +where `report` is the directory where html report files shall be stored. Tests structure follow the same structure as production code with `Test` suffix in class and file name. All tests should go to `tests` directory in project root. So if you've created a class `Mage\Tasks\BuilIn\NewTask` the testing class should be called `MageTest\Tasks\BuiltIn\NewTaskTest`. ## Configuration From 731169595c45a86280d719992cc3bf3a25c34f77 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Fri, 23 Jan 2015 19:53:08 +0100 Subject: [PATCH 33/41] Add some notes about commit messages --- CONTRIBUTING.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 710c26b..e044b1e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,6 +22,24 @@ If you have a problem or you've noticed some bug, please feel free to open new i ## Opening pull requests Pull Request are actually some kind of issues with code, so please keep the rules above in **Reporting issues** section before making the pull requests. Our code isn't so beautiful, tested and testable as we would like it to be but if you're pushing your code please be sure it meets the requirements from **Organization and code quality** chapter. We want to improve the existing code to facilitate extending it and making fixes quicker. So if you are editing some class and you find it ugly, please do not ignore it. Following [The Boy Scout Rule](http://www.informit.com/articles/article.aspx?p=1235624&seqNum=6) - *Leave the campground cleaner than you found it* - we allcan improve the existing code. +Keep your git commits as atomic as it's possible. It brings better history description only by commit messages and allow us to eventually revert the single commits with no affects. Your commit messages should be also descriptive. The first line of commit should be short, try to limit it up to 50 characters. The messages should be written impreatively, like following: +``` +Add MyCustomTask +``` +If you need to write more about your tasks, please enter the description in next lines. There you can write whatever you want, like why you made this commit and what it consists of. +``` +Add MyCustomTask + +This task has very important role for the project. I found this very useful for all developers. I think the deploy with it should be a lot easier. +``` + +Optionally you can tag your messages in square brackets. It can be issue number or simple flag. Examples: +``` +[#183] Add new CONTRIBUTING document +[FIX] Set correct permissions on deploy stage +[FEATURE] Create new PermissionsTask +``` +Remember of square brackets when adding issue number. If you'd forget adding them, your whole message will be a comment! ## Contributing the documentation Magallanes is made to deploy application quick and with no need to write redudant code. Usage is as simple as writing the configuration for target project in YAML files. In the nearest future we would like to make some Wiki with all available options, tasks and commands. For now, the only "documentation" is examples file in `doc` directory. If the code you are going to include in your pull requests adds or changes config options, please make sure you that you create a new sample in that file. You should also to the same with commands. From dae179acad7d6e3c535f8ea098f4ebc9f9f5e8d2 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 2 Dec 2014 19:44:43 +0100 Subject: [PATCH 34/41] Add vendor's bins to bin directory --- .gitignore | 2 ++ composer.json | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 66f4d84..88c7e14 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ vendor mage.phar +bin +!bin/mage # OS generated files # // GitHub Recommendation ###################### diff --git a/composer.json b/composer.json index 2183c74..a3a6868 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,9 @@ "Command\\": ".mage/commands" } }, + "config": { + "bin-dir": "bin" + }, "bin": [ "bin/mage" ] From 86f25b2de63ea769659dce3ce7e598fa88e882d5 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 2 Dec 2014 19:53:33 +0100 Subject: [PATCH 35/41] Add 'with' to config class method expectations --- tests/MageTest/Console/ColorsTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php index 2655409..51cc5bc 100644 --- a/tests/MageTest/Console/ColorsTest.php +++ b/tests/MageTest/Console/ColorsTest.php @@ -18,6 +18,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase $config = $this->getMock('Mage\Config'); $config->expects($this->once()) ->method('getParameter') + ->with('no-color') ->will($this->returnValue(false)); $string = 'FooBar'; @@ -37,6 +38,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase $config = $this->getMock('Mage\Config'); $config->expects($this->once()) ->method('getParameter') + ->with('no-color') ->will($this->returnValue(true)); $string = 'FooBar'; @@ -56,6 +58,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase $config = $this->getMock('Mage\Config'); $config->expects($this->once()) ->method('getParameter') + ->with('no-color') ->will($this->returnValue(false)); $string = 'FooBar'; From 93249ce5e58738aee43af5f578a19bfe95dc2c3b Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 2 Dec 2014 19:53:43 +0100 Subject: [PATCH 36/41] Add coverage annotations --- tests/MageTest/Console/ColorsTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php index 51cc5bc..2aaf262 100644 --- a/tests/MageTest/Console/ColorsTest.php +++ b/tests/MageTest/Console/ColorsTest.php @@ -7,11 +7,13 @@ use PHPUnit_Framework_TestCase; /** * @group Mage_Console_Colors + * @coversDefaultClass Mage\Console\Colors */ class ColorsTest extends PHPUnit_Framework_TestCase { /** * @group 159 + * @covers ::color */ public function testColor() { @@ -32,6 +34,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase /** * @group 159 + * @covers ::color */ public function testColorNoColor() { @@ -52,6 +55,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase /** * @group 159 + * @covers ::color */ public function testColorUnknownColorName() { From 8694805eba3c7a13207f4603c33f201d9c013129 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 2 Dec 2014 19:55:46 +0100 Subject: [PATCH 37/41] Move colour config parameter to class property --- tests/MageTest/Console/ColorsTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php index 2aaf262..1830cc7 100644 --- a/tests/MageTest/Console/ColorsTest.php +++ b/tests/MageTest/Console/ColorsTest.php @@ -11,6 +11,7 @@ use PHPUnit_Framework_TestCase; */ class ColorsTest extends PHPUnit_Framework_TestCase { + protected $noColorParameter = "no-color"; /** * @group 159 * @covers ::color @@ -20,7 +21,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase $config = $this->getMock('Mage\Config'); $config->expects($this->once()) ->method('getParameter') - ->with('no-color') + ->with($this->noColorParameter) ->will($this->returnValue(false)); $string = 'FooBar'; @@ -41,7 +42,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase $config = $this->getMock('Mage\Config'); $config->expects($this->once()) ->method('getParameter') - ->with('no-color') + ->with($this->noColorParameter) ->will($this->returnValue(true)); $string = 'FooBar'; @@ -62,7 +63,7 @@ class ColorsTest extends PHPUnit_Framework_TestCase $config = $this->getMock('Mage\Config'); $config->expects($this->once()) ->method('getParameter') - ->with('no-color') + ->with($this->noColorParameter) ->will($this->returnValue(false)); $string = 'FooBar'; From b00509cf8e8a2bdaf93485746fa140cdb65bb95c Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 2 Dec 2014 19:56:58 +0100 Subject: [PATCH 38/41] Add some colors to phpunit output! :) --- phpunit.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a5e1c3b..6fbbd61 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,8 +5,8 @@ backupGlobals="false" verbose="true" strict="true" - colors="false"> - + colors="true"> + tests From 9d9e5e2bea4cbae2667976b2d4c2a96b64e592ed Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Sat, 24 Jan 2015 21:50:31 +0100 Subject: [PATCH 39/41] Update composer.lock due to outer changes --- composer.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index bc2e079..e882f21 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a19528b890d301384e45c1ed7d221e26", + "hash": "c66ae8cd7e44d614445b273f310d9c34", "packages": [], "packages-dev": [ { @@ -755,6 +755,7 @@ "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": ">=5.3" }, From cc615dda816d8dcc2a657f7460167df23393a2d0 Mon Sep 17 00:00:00 2001 From: Dmitriy Ulyanov Date: Sun, 25 Jan 2015 21:50:00 +0300 Subject: [PATCH 40/41] Ignoring errors while deleting temp files --- .gitignore | 5 ++++- Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 66f4d84..c879e0d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,7 @@ mage.phar ehthumbs.db Icon? Thumbs.db -nbproject \ No newline at end of file + +# IDE generated files +.idea +nbproject diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index ba16246..2345860 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -109,11 +109,11 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware $result = $this->runCommandRemote($command) && $result; // Delete Tar Gz from Remote Host - $command = $this->getReleasesAwareCommand('rm ' . $remoteTarGz . '.tar.gz'); + $command = $this->getReleasesAwareCommand('rm -f ' . $remoteTarGz . '.tar.gz'); $result = $this->runCommandRemote($command) && $result; // Delete Tar Gz from Local - $command = 'rm ' . $localTarGz . ' ' . $localTarGz . '.tar.gz'; + $command = 'rm -f ' . $localTarGz . ' ' . $localTarGz . '.tar.gz'; $result = $this->runCommandLocal($command) && $result; return $result; From 327625bad714fdc3e3b4a970f96ddff988297f29 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 27 Jan 2015 19:47:08 +0100 Subject: [PATCH 41/41] [#183] Change test's description property visibility to private --- tests/MageTest/Console/ColorsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php index 1830cc7..5038303 100644 --- a/tests/MageTest/Console/ColorsTest.php +++ b/tests/MageTest/Console/ColorsTest.php @@ -11,7 +11,7 @@ use PHPUnit_Framework_TestCase; */ class ColorsTest extends PHPUnit_Framework_TestCase { - protected $noColorParameter = "no-color"; + private $noColorParameter = "no-color"; /** * @group 159 * @covers ::color