2016-12-31 07:52:25 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of the Magallanes package.
|
|
|
|
*
|
|
|
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Mage\Task\BuiltIn\Deploy\TarGz;
|
|
|
|
|
2017-01-07 05:53:57 +01:00
|
|
|
use Mage\Task\Exception\ErrorException;
|
2016-12-31 07:52:25 +01:00
|
|
|
use Symfony\Component\Process\Process;
|
|
|
|
use Mage\Task\AbstractTask;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TarGz Task - Copy Tar
|
|
|
|
*
|
|
|
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
|
|
|
*/
|
|
|
|
class CopyTask extends AbstractTask
|
|
|
|
{
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'deploy/targz/copy';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription()
|
|
|
|
{
|
|
|
|
return '[Deploy] Copying files with TarGZ';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
if (!$this->runtime->getEnvironmentConfig('releases', false)) {
|
2017-01-06 02:14:35 +01:00
|
|
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
2016-12-31 07:52:25 +01:00
|
|
|
}
|
|
|
|
|
2017-01-04 02:43:08 +01:00
|
|
|
$user = $this->runtime->getEnvironmentConfig('user', $this->runtime->getCurrentUser());
|
2016-12-31 07:52:25 +01:00
|
|
|
$host = $this->runtime->getWorkingHost();
|
2016-12-31 21:51:47 +01:00
|
|
|
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
|
2016-12-31 07:52:25 +01:00
|
|
|
$hostPath = rtrim($this->runtime->getEnvironmentConfig('host_path'), '/');
|
|
|
|
$currentReleaseId = $this->runtime->getReleaseId();
|
|
|
|
|
|
|
|
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
|
|
|
|
|
|
|
|
$tarGzLocal = $this->runtime->getVar('targz_local');
|
|
|
|
$tarGzRemote = basename($tarGzLocal);
|
|
|
|
|
2016-12-31 21:51:47 +01:00
|
|
|
$cmdCopy = sprintf('scp -P %d %s %s %s@%s:%s/%s', $sshConfig['port'], $sshConfig['flags'], $tarGzLocal, $user, $host, $targetDir, $tarGzRemote);
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/** @var Process $process */
|
|
|
|
$process = $this->runtime->runLocalCommand($cmdCopy, 300);
|
|
|
|
if ($process->isSuccessful()) {
|
2016-12-31 21:51:47 +01:00
|
|
|
$cmdUnTar = sprintf('cd %s && tar xfz %s', $targetDir, $tarGzRemote);
|
|
|
|
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);
|
2016-12-31 07:52:25 +01:00
|
|
|
if ($process->isSuccessful()) {
|
|
|
|
$cmdDelete = sprintf('rm %s/%s', $targetDir, $tarGzRemote);
|
|
|
|
$process = $this->runtime->runRemoteCommand($cmdDelete, false);
|
2017-01-06 17:10:37 +01:00
|
|
|
return $process->isSuccessful();
|
2016-12-31 07:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|