Merge pull request #97 from JoeSimsen/master

Allow a release to be zipped
This commit is contained in:
Andrés Montañez 2014-08-06 13:44:37 -03:00
commit 585fda2f50
4 changed files with 451 additions and 374 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

@ -10,6 +10,7 @@
namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Console;
use Mage\Task\BuiltIn\Deployment\Strategy\BaseStrategyTaskAbstract;
use Mage\Task\Releases\IsReleaseAware;
@ -75,11 +76,11 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
$result = $this->runCommandLocal($command) && $result;
// Extract Tar Gz
$this->getReleasesAwareCommand('tar xfz ' . $remoteTarGz . '.tar.gz');
$command = $this->getReleasesAwareCommand('tar xfz ' . $remoteTarGz . '.tar.gz');
$result = $this->runCommandRemote($command) && $result;
// Delete Tar Gz from Remote Host
$this->getReleasesAwareCommand('rm ' . $remoteTarGz . '.tar.gz');
$command = $this->getReleasesAwareCommand('rm ' . $remoteTarGz . '.tar.gz');
$result = $this->runCommandRemote($command) && $result;
// Delete Tar Gz from Local

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);