diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php
index 85d4705..81dd5f3 100644
--- a/Mage/Command/BuiltIn/DeployCommand.php
+++ b/Mage/Command/BuiltIn/DeployCommand.php
@@ -163,7 +163,27 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
Console::output('Deploying to ' . $this->getConfig()->getHost() . '');
$tasksToRun = $this->getConfig()->getTasks();
- array_unshift($tasksToRun, 'deployment/rsync');
+
+ // Guess a Deploy Strategy
+ switch ($this->getConfig()->deployment('strategy', 'guess')) {
+ case 'rsync':
+ $deployStrategy = 'deployment/strategy/rsync';
+ break;
+
+ case 'targz':
+ $deployStrategy = 'deployment/strategy/tar-gz';
+ break;
+
+ case 'guess':
+ default:
+ if ($this->getConfig()->release('enabled', false) == true) {
+ $deployStrategy = 'deployment/strategy/tar-gz';
+ } else {
+ $deployStrategy = 'deployment/strategy/rsync';
+ }
+ break;
+ }
+ array_unshift($tasksToRun, $deployStrategy);
if (count($tasksToRun) == 0) {
Console::output('Warning! No Deployment tasks defined.', 2);
diff --git a/Mage/Task/BuiltIn/Deployment/RsyncTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php
similarity index 95%
rename from Mage/Task/BuiltIn/Deployment/RsyncTask.php
rename to Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php
index e79f712..4d670a5 100644
--- a/Mage/Task/BuiltIn/Deployment/RsyncTask.php
+++ b/Mage/Task/BuiltIn/Deployment/Strategy/RsyncTask.php
@@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/
-namespace Mage\Task\BuiltIn\Deployment;
+namespace Mage\Task\BuiltIn\Deployment\Strategy;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\IsReleaseAware;
@@ -30,12 +30,12 @@ class RsyncTask extends AbstractTask implements IsReleaseAware
{
if ($this->getConfig()->release('enabled', false) == true) {
if ($this->getConfig()->getParameter('overrideRelease', false) == true) {
- return 'Rsync (with Releases override) [built-in]';
+ return 'Deploy via Rsync (with Releases override) [built-in]';
} else {
- return 'Rsync (with Releases) [built-in]';
+ return 'Deploy via Rsync (with Releases) [built-in]';
}
} else {
- return 'Rsync [built-in]';
+ return 'Deploy via Rsync [built-in]';
}
}
diff --git a/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php
new file mode 100644
index 0000000..e203d60
--- /dev/null
+++ b/Mage/Task/BuiltIn/Deployment/Strategy/TarGzTask.php
@@ -0,0 +1,157 @@
+
+*
+* For the full copyright and license information, please view the LICENSE
+* file that was distributed with this source code.
+*/
+
+namespace Mage\Task\BuiltIn\Deployment\Strategy;
+
+use Mage\Task\AbstractTask;
+use Mage\Task\Releases\IsReleaseAware;
+
+use Exception;
+
+/**
+ * Task for Sync the Local Code to the Remote Hosts via Tar GZ
+ *
+ * @author Andrés Montañez
+ */
+class TarGzTask extends AbstractTask implements IsReleaseAware
+{
+ /**
+ * (non-PHPdoc)
+ * @see \Mage\Task\AbstractTask::getName()
+ */
+ public function getName()
+ {
+ if ($this->getConfig()->release('enabled', false) == true) {
+ if ($this->getConfig()->getParameter('overrideRelease', false) == true) {
+ return 'Deploy via TarGz (with Releases override) [built-in]';
+ } else {
+ return 'Deploy via TarGz (with Releases) [built-in]';
+ }
+ } else {
+ return 'Deploy via TarGz [built-in]';
+ }
+ }
+
+ /**
+ * Syncs the Local Code to the Remote Host
+ * @see \Mage\Task\AbstractTask::run()
+ */
+ public function run()
+ {
+ $overrideRelease = $this->getParameter('overrideRelease', false);
+
+ if ($overrideRelease == true) {
+ $releaseToOverride = false;
+ $resultFetch = $this->runCommandRemote('ls -ld current | cut -d"/" -f2', $releaseToOverride);
+ if (is_numeric($releaseToOverride)) {
+ $this->getConfig()->setReleaseId($releaseToOverride);
+ }
+ }
+
+ $excludes = array(
+ '.git',
+ '.svn',
+ '.mage',
+ '.gitignore',
+ '.gitkeep',
+ 'nohup.out'
+ );
+
+ // 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->getConfig()->getReleaseId();
+ $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
+ }
+
+ // Create Tar Gz
+ $localTarGz = tempnam(sys_get_temp_dir(), 'mage');
+ $remoteTarGz = basename($localTarGz);
+ $command = 'tar cfz ' . $localTarGz . '.tar.gz ' . $this->getConfig()->deployment('from');
+ $result = $this->runCommandLocal($command);
+
+ //. $this->excludes(array_merge($excludes, $userExcludes)) . ' '
+
+ // Copy Tar Gz to Remote Host
+ $command = 'scp -P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz '
+ . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
+ $result = $this->runCommandLocal($command) && $result;
+
+ // Extract Tar Gz
+ if ($this->getConfig()->release('enabled', false) == true) {
+ $releasesDirectory = $this->getConfig()->release('directory', 'releases');
+
+ $deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
+ $command = 'cd ' . $deployToDirectory . ' && tar xfz ' . $remoteTarGz . '.tar.gz';
+ } else {
+ $command = 'tar xfz ' . $remoteTarGz . '.tar.gz';
+ }
+ $result = $this->runCommandRemote($command) && $result;
+
+ // Delete Tar Gz from Remote Host
+ if ($this->getConfig()->release('enabled', false) == true) {
+ $releasesDirectory = $this->getConfig()->release('directory', 'releases');
+
+ $deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
+ $command = 'rm ' . $deployToDirectory . '/' . $remoteTarGz . '.tar.gz';
+ } else {
+ $command = 'rm ' . $remoteTarGz . '.tar.gz';
+ }
+ $result = $this->runCommandRemote($command) && $result;
+
+ // Delete Tar Gz from Local
+ $command = 'rm ' . $localTarGz . ' ' . $localTarGz . '.tar.gz';
+ $result = $this->runCommandLocal($command) && $result;
+
+ // 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 ($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;
+ $result = $result && $this->runCommandRemote($command);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return $result;
+ }
+}
\ No newline at end of file