diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 84720f5..5f4f39c 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/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 +} 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 a119886..8329f2d 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -10,7 +10,6 @@ namespace Mage; -use Symfony\Component\Yaml\Yaml; use Exception; /** @@ -341,10 +340,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 +414,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 +433,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 +441,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; + } } /** @@ -496,4 +505,4 @@ class Config } } -} \ No newline at end of file +} 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 d6afcec..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; @@ -192,7 +190,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/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/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 +} 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; 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/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php b/Mage/Task/BuiltIn/Filesystem/ApplyFacls.php new file mode 100644 index 0000000..3bf73ff --- /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/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php new file mode 100644 index 0000000..9850401 --- /dev/null +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -0,0 +1,54 @@ +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; + } +} 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; diff --git a/Mage/Task/Factory.php b/Mage/Task/Factory.php index b49c1c9..a8a7066 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; @@ -29,6 +27,7 @@ class Factory * * @param string|array $taskData * @param \Mage\Config $taskConfig + * @param Config $taskConfig * @param boolean $inRollback * @param string $stage * @return \Mage\Task\AbstractTask @@ -70,4 +69,4 @@ class Factory return $instance; } -} \ No newline at end of file +}