From beb663e801df7874a2939c5f6e32f977ca43deee Mon Sep 17 00:00:00 2001 From: Osukaru Date: Mon, 7 Apr 2014 12:20:41 +0200 Subject: [PATCH 01/11] Added identity file option for ssh and scp commands --- Mage/Config.php | 36 ++++++++++++------- Mage/Task/AbstractTask.php | 2 +- .../BuiltIn/Deployment/Strategy/RsyncTask.php | 2 +- .../BuiltIn/Deployment/Strategy/TarGzTask.php | 2 +- bin/mage | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Mage/Config.php b/Mage/Config.php index a119886..6ce69e1 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -341,10 +341,20 @@ class Config public function getHostPort() { $info = explode(':', $this->host); - $info[] = $this->deployment('port', '22'); + $info[] = $this->deployment('port', '22'); return $info[1]; } + /** + * Get the general Host Identity File Option + * + * @return string + */ + public function getHostIdentityFileOption() + { + return $this->deployment('identity-file') ? '-i '.$this->deployment('identity-file').' ': ''; + } + /** * Get the current Host * @@ -405,7 +415,7 @@ class Config } // Global Config - $config = $this->getEnvironmentOption('deployment', array()); + $config = $this->getEnvironmentOption('deployment', array()); if (isset($config[$option])) { if (is_array($default) && ($config[$option] == '')) { return $default; @@ -424,7 +434,7 @@ class Config * @param string $default * @return mixed */ - public function release($option, $default = false) + public function release($option, $default = false) { // Host Config if (is_array($this->hostConfig) && isset($this->hostConfig['releases'])) { @@ -432,17 +442,17 @@ class Config return $this->hostConfig['releases'][$option]; } } - - $config = $this->getEnvironmentOption('releases', array()); + + $config = $this->getEnvironmentOption('releases', array()); if (isset($config[$option])) { - if (is_array($default) && ($config[$option] == '')) { - return $default; - } else { - return $config[$option]; - } - } else { - return $default; - } + if (is_array($default) && ($config[$option] == '')) { + return $default; + } else { + return $config[$option]; + } + } else { + return $default; + } } /** diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index d6afcec..f028ab7 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -192,7 +192,7 @@ abstract class AbstractTask // if general.yml includes "ssy_needs_tty: true", then add "-t" to the ssh command $needs_tty = ($this->getConfig()->general('ssh_needs_tty',false) ? '-t' : ''); - $localCommand = 'ssh ' . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' ' + $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' ' . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ' ' . '"cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && ' diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php index ead532c..74af0ea 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php @@ -94,7 +94,7 @@ class RsyncTask extends AbstractTask implements IsReleaseAware } $command = 'rsync -avz ' - . '--rsh="ssh -p' . $this->getConfig()->getHostPort() . '" ' + . '--rsh="ssh ' . $this->getConfig()->getHostIdentityFileOption() . '-p' . $this->getConfig()->getHostPort() . '" ' . $this->excludes(array_merge($excludes, $userExcludes)) . ' ' . $this->getConfig()->deployment('from') . ' ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory; diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php index aa23c70..e1b6477 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php @@ -89,7 +89,7 @@ class TarGzTask extends AbstractTask implements IsReleaseAware $result = $this->runCommandLocal($command); // Copy Tar Gz to Remote Host - $command = 'scp -P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz ' + $command = 'scp ' . $this->getConfig()->getHostIdentityFileOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz ' . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory; $result = $this->runCommandLocal($command) && $result; diff --git a/bin/mage b/bin/mage index 9236138..d62464b 100755 --- a/bin/mage +++ b/bin/mage @@ -13,7 +13,7 @@ date_default_timezone_set('UTC'); $baseDir = dirname(dirname(__FILE__)); -define('MAGALLANES_VERSION', '1.0.1'); +define('MAGALLANES_VERSION', '1.0.2'); define('MAGALLANES_DIRECTORY', $baseDir); // Preload From 59574711c1cb537187a4501c23f85608c1e6b613 Mon Sep 17 00:00:00 2001 From: David Lin Date: Tue, 15 Apr 2014 09:59:16 +1000 Subject: [PATCH 02/11] Fixed a bug in the builtin ChangeBranchTask.php --- Mage/Task/BuiltIn/Scm/ChangeBranchTask.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php b/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php index c585017..7cfa5d5 100644 --- a/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php +++ b/Mage/Task/BuiltIn/Scm/ChangeBranchTask.php @@ -63,8 +63,7 @@ class ChangeBranchTask extends AbstractTask */ public function run() { - $scmConfig = $this->getConfig()->general('scm', array()); - switch ((isset($scmConfig['type']) ? $scmConfig['type'] : false)) { + switch ($this->getConfig()->general('scm')) { case 'git': if ($this->getParameter('_changeBranchRevert', false)) { $command = 'git checkout ' . self::$startingBranch; From fee82c3cf14303f16c0484b9992572674f67e0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 26 Apr 2014 13:21:15 -0700 Subject: [PATCH 03/11] Update mage --- bin/mage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/mage b/bin/mage index d62464b..9236138 100755 --- a/bin/mage +++ b/bin/mage @@ -13,7 +13,7 @@ date_default_timezone_set('UTC'); $baseDir = dirname(dirname(__FILE__)); -define('MAGALLANES_VERSION', '1.0.2'); +define('MAGALLANES_VERSION', '1.0.1'); define('MAGALLANES_DIRECTORY', $baseDir); // Preload From 8785a3498d1d2abd0c11722013b6f4bbe828650a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 26 Apr 2014 13:21:48 -0700 Subject: [PATCH 04/11] Update Config.php --- Mage/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/Config.php b/Mage/Config.php index 6ce69e1..fe22b13 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -352,7 +352,7 @@ class Config */ public function getHostIdentityFileOption() { - return $this->deployment('identity-file') ? '-i '.$this->deployment('identity-file').' ': ''; + return $this->deployment('identity-file') ? ('-i ' . $this->deployment('identity-file') . ' ') : ''; } /** @@ -506,4 +506,4 @@ class Config } } -} \ No newline at end of file +} From eefec4cbc04f6018427297f158048ef53caacf7b Mon Sep 17 00:00:00 2001 From: Mario Mueller Date: Sun, 4 May 2014 08:55:04 +0200 Subject: [PATCH 05/11] Added three new tasks. One task for generating the composer production autoloader, one for linking shared files and folders into the release and one to set filesystem acls while rolling out a new release. --- .../BuiltIn/Composer/GenerateAutoload.php | 40 ++++++++++++++ Mage/Task/BuiltIn/Filesystem/ApplyFacls.php | 50 +++++++++++++++++ .../BuiltIn/Filesystem/LinkSharedFiles.php | 53 +++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 Mage/Task/BuiltIn/Composer/GenerateAutoload.php create mode 100644 Mage/Task/BuiltIn/Filesystem/ApplyFacls.php create mode 100644 Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php diff --git a/Mage/Task/BuiltIn/Composer/GenerateAutoload.php b/Mage/Task/BuiltIn/Composer/GenerateAutoload.php new file mode 100644 index 0000000..00ae10a --- /dev/null +++ b/Mage/Task/BuiltIn/Composer/GenerateAutoload.php @@ -0,0 +1,40 @@ +getConfig()->release('directory', 'releases'); + $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; + $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); + + $sharedFolderName = $this->getParameter('shared', 'shared'); + $sharedFolderName = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; + + $composerPath = $this->getParameter('composer', "$sharedFolderName/composer.phar"); + return $this->runCommandRemote("/usr/bin/env php $composerPath --working-dir=$currentCopy dumpautoload --optimize", $output); + } +} diff --git a/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php b/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php new file mode 100644 index 0000000..02a014d --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php @@ -0,0 +1,50 @@ +getConfig()->release('directory', 'releases'); + $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; + $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); + + + $aclParam = $this->getParameter('acl_param', ''); + if (empty($aclParam)) { + throw new SkipException('Parameter acl_param not set.'); + } + + $folders = $this->getParameter('folders', []); + $recursive = $this->getParameter('recursive', false) ? ' -R ' : ' '; + + foreach ($folders as $folder) { + $this->runCommandRemote("setfacl$recursive-m $aclParam $currentCopy/$folder", $output); + } + + return true; + } +} diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php new file mode 100644 index 0000000..5b01a76 --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php @@ -0,0 +1,53 @@ +getParameter('linked_files', []); + $linkedFolders = $this->getParameter('linked_folders', []); + if (sizeof($linkedFiles) == 0 && sizeof($linkedFolders) == 0) { + throw new SkipException('No files and folders configured for sym-linking.'); + } + + $sharedFolderName = $this->getParameter('shared', 'shared'); + $sharedFolderName = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $sharedFolderName; + $releasesDirectory = $this->getConfig()->release('directory', 'releases'); + $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; + + $currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId(); + foreach ($linkedFolders as $folder) { + $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; + $this->runCommandRemote($command); + } + + foreach ($linkedFiles as $folder) { + $command = "ln -nfs $sharedFolderName/$folder $currentCopy/$folder"; + $this->runCommandRemote($command); + } + + return true; + } +} From 86ef2786070f78f23ef2e779709719576209e7bc Mon Sep 17 00:00:00 2001 From: juanda Date: Wed, 7 May 2014 12:55:14 +0200 Subject: [PATCH 06/11] strategy git-rebase is enabled --- Mage/Command/BuiltIn/DeployCommand.php | 6 +++++- .../Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 916d546..cbc9c51 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -310,7 +310,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment case 'targz': $deployStrategy = 'deployment/strategy/tar-gz'; break; - + + case 'git-rebase': + $deployStrategy = 'deployment/strategy/git-rebase'; + break; + case 'guess': default: if ($this->getConfig()->release('enabled', false) == true) { diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php index 56afa57..5bcbd8e 100644 --- a/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php @@ -34,13 +34,13 @@ class GitRebaseTask extends AbstractTask implements IsReleaseAware * @see \Mage\Task\AbstractTask::run() */ public function run() - { - $branch = $this->getParameter('branch'); - $remote = $this->getParameter('remote'); - + { + $branch = $this->getParameter('branch', 'master'); + $remote = $this->getParameter('remote', 'origin'); + // Fetch Remote $command = 'git fetch ' . $remote; - $result = $this->runCommandRemote($command) && $result; + $result = $this->runCommandRemote($command); // Checkout $command = 'git checkout ' . $branch; From ea9c83b07f53bad1308d889b29958b0b965ceb09 Mon Sep 17 00:00:00 2001 From: Tony Nelson Date: Thu, 8 May 2014 15:41:05 -0500 Subject: [PATCH 07/11] Only call chown on releases if there's a userGroup --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 7f8fef9..7a149c4 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -59,14 +59,13 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride $command .= ' && ' . 'chown -h ' . $userGroup . ' ' . $symlink . ' && ' - . 'chown -R ' . $userGroup . ' ' . $currentCopy; + . 'chown -R ' . $userGroup . ' ' . $currentCopy + . ' && ' + . 'chown ' . $userGroup . ' ' . $releasesDirectory; } $result = $this->runCommandRemote($command); - // Set Directory Releases to same owner - $result = $this->runCommandRemote('chown ' . $userGroup . ' ' . $releasesDirectory); - return $result; } else { @@ -74,4 +73,4 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride } } -} \ No newline at end of file +} From eee36a850ae04399fb731ec960056667012dd714 Mon Sep 17 00:00:00 2001 From: Ismael Ambrosi Date: Thu, 22 May 2014 22:56:05 -0300 Subject: [PATCH 08/11] Fixed namespace for Filesystem tasks --- Mage/Task/BuiltIn/Filesystem/ApplyFacls.php | 2 +- Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php b/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php index 02a014d..3bf73ff 100644 --- a/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php +++ b/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php @@ -1,5 +1,5 @@ Date: Thu, 22 May 2014 23:03:14 -0300 Subject: [PATCH 09/11] Removed unused use statements --- Mage/Command/Factory.php | 1 - Mage/Config.php | 1 - Mage/Console.php | 1 - Mage/Mailer.php | 1 - Mage/Task/AbstractTask.php | 2 -- Mage/Task/Factory.php | 8 +++----- 6 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Mage/Command/Factory.php b/Mage/Command/Factory.php index 56b350a..7e6b322 100644 --- a/Mage/Command/Factory.php +++ b/Mage/Command/Factory.php @@ -10,7 +10,6 @@ namespace Mage\Command; -use Mage\Command\AbstractCommand; use Mage\Config; use Mage\Autoload; diff --git a/Mage/Config.php b/Mage/Config.php index fe22b13..8329f2d 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -10,7 +10,6 @@ namespace Mage; -use Symfony\Component\Yaml\Yaml; use Exception; /** diff --git a/Mage/Console.php b/Mage/Console.php index 4c5e0a2..293e47f 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -10,7 +10,6 @@ namespace Mage; -use Mage\Config; use Mage\Command\Factory; use Mage\Command\RequiresEnvironment; use Mage\Console\Colors; diff --git a/Mage/Mailer.php b/Mage/Mailer.php index 48b9fa2..96ec30b 100644 --- a/Mage/Mailer.php +++ b/Mage/Mailer.php @@ -10,7 +10,6 @@ namespace Mage; -use Mage\Console; /** * Mailer Helper. diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index f028ab7..69ba25f 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -12,8 +12,6 @@ namespace Mage\Task; use Mage\Console; use Mage\Config; -use Mage\Task\ErrorWithMessageException; -use Mage\Task\SkipException; use Mage\Task\Releases\IsReleaseAware; use Exception; diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index 6a0b0eb..20d9497 100644 --- a/Mage/Task/Factory.php +++ b/Mage/Task/Factory.php @@ -12,8 +12,6 @@ namespace Mage\Task; use Mage\Config; use Mage\Autoload; -use Mage\Task\ErrorWithMessageException; -use Mage\Task\AbstractTask; use Exception; @@ -28,7 +26,7 @@ class Factory * Gets an instance of a Task. * * @param string|array $taskData - * @param Mage\Config $taskConfig + * @param Config $taskConfig * @param boolean $inRollback * @param string $stage * @return \Mage\Task\AbstractTask @@ -44,7 +42,7 @@ class Factory } $instance = null; - $taskName = ucwords(str_replace('-', ' ', $taskName)); + $taskName = ucwords(str_replace('-', ' ', $taskName)); $taskName = str_replace(' ', '', $taskName); if (strpos($taskName, '/') === false) { @@ -69,4 +67,4 @@ class Factory return $instance; } -} \ No newline at end of file +} From f9845317424f95d334f6ed797bec91ced90dc068 Mon Sep 17 00:00:00 2001 From: Jan Malte Gerth Date: Tue, 27 May 2014 13:57:41 +0200 Subject: [PATCH 10/11] fixed failing testing for successful json_decode --- Mage/Command/BuiltIn/UpgradeCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/Command/BuiltIn/UpgradeCommand.php b/Mage/Command/BuiltIn/UpgradeCommand.php index 330f056..25907bc 100644 --- a/Mage/Command/BuiltIn/UpgradeCommand.php +++ b/Mage/Command/BuiltIn/UpgradeCommand.php @@ -54,7 +54,7 @@ class UpgradeCommand extends AbstractCommand // Check version $version = json_decode(file_get_contents(self::UPGRADE)); - if ($version !== false) { + if ($version !== false && $version !== null) { $versionCompare = version_compare(MAGALLANES_VERSION, $version->latest); if ($versionCompare == 0) { Console::output('SKIP', 0, 1); @@ -94,4 +94,4 @@ class UpgradeCommand extends AbstractCommand } } } -} \ No newline at end of file +} From dacfaa2c5efc69e27bdcf88096870ba4648e370c Mon Sep 17 00:00:00 2001 From: Jan Malte Gerth Date: Wed, 11 Jun 2014 17:35:40 +0200 Subject: [PATCH 11/11] fixes #73 missing "Task" suffix for LinkSharedFiles --- .../Filesystem/{LinkSharedFiles.php => LinkSharedFilesTask.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Mage/Task/BuiltIn/Filesystem/{LinkSharedFiles.php => LinkSharedFilesTask.php} (95%) diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php similarity index 95% rename from Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php rename to Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index c8c0f78..9850401 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFiles.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -5,7 +5,7 @@ use Mage\Task\AbstractTask; use Mage\Task\Releases\IsReleaseAware; use Mage\Task\SkipException; -class LinkSharedFiles extends AbstractTask implements IsReleaseAware +class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware { /**