Allow a release to be zipped

If you enable the parameter 'releases: compressreleases: true', every
release except the current wil be added to a tar.gz. This is to preserve
diskspace on the remote host.
This commit is contained in:
JoeSimsen 2014-07-31 15:06:20 +02:00
parent d3c8cf5767
commit 82c5305137
3 changed files with 444 additions and 368 deletions

View file

@ -247,4 +247,64 @@ abstract class AbstractTask
return $command;
}
/**
* @param $releasesDirectory
* @param $releaseId
* @return bool
*/
protected function tarRelease($releaseId)
{
$result = true;
// for given release, check if tarred
$output = '';
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
$currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
$currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
$command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
$this->runCommandRemote($command, $output);
// if not, do so
if (!$output) {
$commands = array();
$commands[] = 'mv ' . $currentReleaseDirectory . ' ' . $currentReleaseDirectoryTemp;
$commands[] = 'mkdir ' . $currentReleaseDirectory;
$commands[] = 'tar cfz ' . $currentRelease . ' ' . $currentReleaseDirectoryTemp;
$commands[] = 'rm -rf ' . $currentReleaseDirectoryTemp;
$command = implode(' && ', $commands);
$result = $this->runCommandRemote($command, $output);
return $result;
}
return $result;
}
protected function untarRelease($releaseId)
{
$result = true;
// for given release, check if tarred
$output = '';
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
$currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
$currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
$currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
$command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
$this->runCommandRemote($command, $output);
// if tarred, untar now
if ($output) {
$commands = array();
$commands[] = 'tar xfz ' . $currentRelease;
$commands[] = 'rm -rf ' . $currentReleaseDirectory;
$commands[] = 'mv ' .$currentReleaseDirectoryTemp . ' ' . $currentReleaseDirectory;
$command = implode(' && ', $commands);
$result = $this->runCommandRemote($command, $output);
return $result;
}
return $result;
}
}

View file

@ -44,7 +44,16 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
}
$currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
$releaseId = $this->getConfig()->getReleaseId();
if ($this->getConfig()->release('compressreleases', false) == true) {
// Tar.gz releases
$result = $this->tarReleases() && $result;
// Untar new release
$result = $this->untarRelease($releaseId) && $result;
}
$currentCopy = $releasesDirectory . '/' . $releaseId;
//Check if target user:group is specified
$userGroup = $this->getConfig()->deployment('owner');

View file

@ -130,6 +130,13 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
}
}
if ($this->getConfig()->release('compressreleases', false) == true) {
// Tar the current
$result = $this->tarReleases() && $result;
// Untar the rollbackto
$result = $this->untarRelease($releaseId) && $result;
}
// Changing Release
Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);