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.
|
|
|
|
*/
|
|
|
|
|
2017-01-15 02:36:15 +01:00
|
|
|
namespace Mage\Task\BuiltIn\Deploy\Tar;
|
2016-12-31 07:52:25 +01:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
2017-01-15 02:36:15 +01:00
|
|
|
* Tar Task - Create temporal Tar
|
2016-12-31 07:52:25 +01:00
|
|
|
*
|
|
|
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
|
|
|
*/
|
|
|
|
class PrepareTask extends AbstractTask
|
|
|
|
{
|
|
|
|
public function getName()
|
|
|
|
{
|
2017-01-15 02:36:15 +01:00
|
|
|
return 'deploy/tar/prepare';
|
2016-12-31 07:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription()
|
|
|
|
{
|
2017-01-15 02:36:15 +01:00
|
|
|
return '[Deploy] Preparing Tar file';
|
2016-12-31 07:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function execute()
|
|
|
|
{
|
2017-01-12 02:22:21 +01:00
|
|
|
if (!$this->runtime->getEnvOption('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-15 02:36:15 +01:00
|
|
|
$tarLocal = $this->runtime->getTempFile();
|
|
|
|
$this->runtime->setVar('tar_local', $tarLocal);
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
$excludes = $this->getExcludes();
|
2017-07-22 22:14:36 +02:00
|
|
|
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
|
2019-05-01 20:21:30 +02:00
|
|
|
$flags = $this->runtime->getEnvOption('tar_create', stripos(PHP_OS, 'WIN') === 0 ? '--force-local -c -z -p -f' : 'cfzp');
|
2021-02-19 02:18:45 +01:00
|
|
|
$from = './';
|
|
|
|
|
|
|
|
if ($fromPath = $this->runtime->getEnvOption('from', false)) {
|
|
|
|
$from = sprintf('-C %s %s', $fromPath, $from);
|
|
|
|
}
|
|
|
|
|
2017-07-22 22:14:36 +02:00
|
|
|
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
/** @var Process $process */
|
2017-01-15 02:36:15 +01:00
|
|
|
$process = $this->runtime->runLocalCommand($cmdTar, 300);
|
2016-12-31 07:52:25 +01:00
|
|
|
return $process->isSuccessful();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getExcludes()
|
|
|
|
{
|
2017-04-14 21:29:22 +02:00
|
|
|
$excludes = $this->runtime->getMergedOption('exclude', []);
|
2017-02-05 00:26:56 +01:00
|
|
|
$excludes = array_merge(['.git'], array_filter($excludes));
|
2016-12-31 07:52:25 +01:00
|
|
|
|
|
|
|
foreach ($excludes as &$exclude) {
|
2017-01-03 03:56:54 +01:00
|
|
|
$exclude = '--exclude="' . $exclude . '"';
|
2016-12-31 07:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return implode(' ', $excludes);
|
|
|
|
}
|
|
|
|
}
|