Major overhauling and refactoring of Magallanes Command and Tasks modulairty and workflow.

ADVICE: there is no Backwards Compatibility with custom tasks, those
using the _config instance will be broken or those using the
getEnvironmentName().
This commit is contained in:
Andrés Montañez
2012-09-21 00:23:07 -03:00
parent 05b102b273
commit 811c83e13a
29 changed files with 803 additions and 639 deletions
+7 -7
View File
@@ -10,15 +10,15 @@ class Mage_Task_BuiltIn_Deployment_Releases
public function run()
{
if ($this->_config->release('enabled', false) == true) {
$releasesDirectory = $this->_config->release('directory', 'releases');
$symlink = $this->_config->release('symlink', 'current');
if ($this->getConfig()->release('enabled', false) == true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
if (substr($symlink, 0, 1) == '/') {
$releasesDirectory = rtrim($this->_config->deployment('to'), '/') . '/' . $releasesDirectory;
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
}
$currentCopy = $releasesDirectory . '/' . $this->_config->getReleaseId();
$currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
// Fetch the user and group from base directory
$userGroup = '33:33';
@@ -35,7 +35,7 @@ class Mage_Task_BuiltIn_Deployment_Releases
$result = $this->_runRemoteCommand($command);
// Count Releases
$maxReleases = $this->_config->release('max', false);
$maxReleases = $this->getConfig()->release('max', false);
if (($maxReleases !== false) && ($maxReleases > 0)) {
$releasesList = '';
$countReleasesFetch = $this->_runRemoteCommand('ls -1 ' . $releasesDirectory, $releasesList);
@@ -44,7 +44,7 @@ class Mage_Task_BuiltIn_Deployment_Releases
if ($releasesList != '') {
$releasesList = explode(PHP_EOL, $releasesList);
if (count($releasesList) > $maxReleases) {
$releasesToDelete = array_diff($releasesList, array($this->_config->getReleaseId()));
$releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId()));
sort($releasesToDelete);
$releasesToDeleteCount = count($releasesToDelete) - $maxReleases;
$releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1);
+23 -23
View File
@@ -5,11 +5,11 @@ class Mage_Task_BuiltIn_Deployment_Rsync
{
public function getName()
{
if ($this->_config->release('enabled', false) == true) {
if ($this->getActionOption('overrideRelease', false) == true) {
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->getParameter('overrideRelease', false) == true) {
return 'Rsync (with Releases override) [built-in]';
} else {
return 'Rsync (with Releases) [built-in]';
return 'Rsync (with Releases) [built-in]';
}
} else {
return 'Rsync [built-in]';
@@ -18,13 +18,13 @@ class Mage_Task_BuiltIn_Deployment_Rsync
public function run()
{
$overrideRelease = $this->getActionOption('overrideRelease', false);
$overrideRelease = $this->getConfig()->getParameter('overrideRelease', false);
if ($overrideRelease == true) {
$releaseToOverride = false;
$resultFetch = $this->_runRemoteCommand('ls -ld current | cut -d\"/\" -f2', $releaseToOverride);
if (is_numeric($releaseToOverride)) {
$this->_config->setReleaseId($releaseToOverride);
$this->getConfig()->setReleaseId($releaseToOverride);
}
}
@@ -34,39 +34,39 @@ class Mage_Task_BuiltIn_Deployment_Rsync
'.mage',
'.gitignore'
);
// Look for User Excludes
$userExcludes = $this->_config->deployment('excludes', array());
// If we are working with releases
$deployToDirectory = $this->_config->deployment('to');
if ($this->_config->release('enabled', false) == true) {
$releasesDirectory = $this->_config->release('directory', 'releases');
$deployToDirectory = rtrim($this->_config->deployment('to'), '/')
// Look for User Excludes
$userExcludes = $this->getConfig()->deployment('excludes', array());
// If we are working with releases
$deployToDirectory = $this->getConfig()->deployment('to');
if ($this->getConfig()->release('enabled', false) == true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
. '/' . $releasesDirectory
. '/' . $this->_config->getReleaseId();
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config->getReleaseId());
. '/' . $this->getConfig()->getReleaseId();
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
}
$command = 'rsync -avz '
. '--rsh="ssh -p' . $this->_config->getHostPort() . '" '
. '--rsh="ssh -p' . $this->getConfig()->getHostPort() . '" '
. $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
. $this->_config->deployment('from') . ' '
. $this->_config->deployment('user') . '@' . $this->_config->getHostName() . ':' . $deployToDirectory;
. $this->getConfig()->deployment('from') . ' '
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
$result = $this->_runLocalCommand($command);
return $result;
}
private function _excludes(Array $excludes)
{
$excludesRsync = '';
foreach ($excludes as $exclude) {
$excludesRsync .= ' --exclude ' . $exclude . ' ';
}
$excludesRsync = trim($excludesRsync);
return $excludesRsync;
}