Browse Source

Issue #47

Movie cleanup of releases on release task.
1.0
Andrés Montañez 11 years ago
parent
commit
825fc64b0a
  1. 44
      Mage/Task/BuiltIn/Deployment/ReleaseTask.php
  2. 41
      Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php
  3. 2
      Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php
  4. 2
      Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php
  5. 2
      Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php

44
Mage/Task/BuiltIn/Deployment/ReleaseTask.php

@ -90,6 +90,10 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
$result = $this->runCommandRemote($command);
if ($result) {
$this->cleanUpReleases();
}
return $result;
} else {
@ -97,4 +101,44 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
}
}
/**
* Removes old releases
*/
protected function cleanUpReleases()
{
// Count Releases
if ($this->getConfig()->release('enabled', false) == true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
if (substr($symlink, 0, 1) == '/') {
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
}
$maxReleases = $this->getConfig()->release('max', false);
if (($maxReleases !== false) && ($maxReleases > 0)) {
$releasesList = '';
$countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList);
$releasesList = trim($releasesList);
if ($countReleasesFetch && $releasesList != '') {
$releasesList = explode(PHP_EOL, $releasesList);
if (count($releasesList) > $maxReleases) {
$releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId()));
sort($releasesToDelete);
$releasesToDeleteCount = count($releasesToDelete) - $maxReleases;
$releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1);
foreach ($releasesToDelete as $releaseIdToDelete) {
$directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete;
if ($directoryToDelete != '/') {
$command = 'rm -rf ' . $directoryToDelete;
$this->runCommandRemote($command);
}
}
}
}
}
}
}
}

41
Mage/Task/BuiltIn/Deployment/Strategy/BaseStrategyTaskAbstract.php

@ -62,45 +62,4 @@ abstract class BaseStrategyTaskAbstract extends AbstractTask implements IsReleas
return array_merge($excludes, $userExcludes);
}
/**
* Removes old releases
*/
protected function cleanUpReleases()
{
// Count Releases
if ($this->getConfig()->release('enabled', false) == true) {
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$symlink = $this->getConfig()->release('symlink', 'current');
if (substr($symlink, 0, 1) == '/') {
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
}
$maxReleases = $this->getConfig()->release('max', false);
if (($maxReleases !== false) && ($maxReleases > 0)) {
$releasesList = '';
$countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList);
$releasesList = trim($releasesList);
if ($countReleasesFetch && $releasesList != '') {
$releasesList = explode(PHP_EOL, $releasesList);
if (count($releasesList) > $maxReleases) {
$releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId()));
sort($releasesToDelete);
$releasesToDeleteCount = count($releasesToDelete) - $maxReleases;
$releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1);
foreach ($releasesToDelete as $releaseIdToDelete) {
$directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete;
if ($directoryToDelete != '/') {
$command = 'rm -rf ' . $directoryToDelete;
$this->runCommandRemote($command);
}
}
}
}
}
}
}
}

2
Mage/Task/BuiltIn/Deployment/Strategy/GitRebaseTask.php

@ -97,8 +97,6 @@ class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$result = $this->runCommandRemote($command) && $result;
}
$this->cleanUpReleases();
return $result;
}
}

2
Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php

@ -99,8 +99,6 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
$result = $this->runCommandLocal($command);
$this->cleanUpReleases();
return $result;
}

2
Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php

@ -111,8 +111,6 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$command = 'rm ' . $localTarGz . ' ' . $localTarGz . '.tar.gz';
$result = $this->runCommandLocal($command) && $result;
$this->cleanUpReleases();
return $result;
}
}

Loading…
Cancel
Save