Merge pull request #393 from andres-montanez/nostromo

Release for Version 3.3.0
This commit is contained in:
Andrés Montañez 2017-07-22 18:01:32 -03:00 committed by GitHub
commit 3ed4c758c0
9 changed files with 119 additions and 6 deletions

View file

@ -1,6 +1,11 @@
CHANGELOG for 3.X
=================
* 3.3.0 (2017-07-22)
* [PR#386] Allow to define timeout (default 120s) for symfony/assetic-dump task.
* [PR#392] Allow to define Host Port in Host configuration.
* Allow to specify the binary path of tar on for create and extract
* 3.2.0 (2017-04-14)
* Allow to pre-register Custom Tasks
* [PR#365] New option "from" to define deployment start point

View file

@ -17,6 +17,6 @@ namespace Mage;
*/
class Mage
{
const VERSION = '3.2';
const VERSION = '3.3.0';
const CODENAME = 'Nostromo';
}

View file

@ -457,7 +457,11 @@ class Runtime
*/
public function getSSHConfig()
{
$sshConfig = $this->getEnvOption('ssh', ['port' => '22', 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
$sshConfig = $this->getEnvOption('ssh', ['port' => 22, 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
if ($this->getHostPort() !== null) {
$sshConfig['port'] = $this->getHostPort();
}
if (!array_key_exists('port', $sshConfig)) {
$sshConfig['port'] = '22';
@ -470,6 +474,17 @@ class Runtime
return $sshConfig;
}
/**
* Get the current Host Port or default ssh port
*
* @return integer
*/
public function getHostPort()
{
$info = explode(':', $this->getWorkingHost());
return isset($info[1]) ? $info[1] : null;
}
/**
* Gets a Temporal File name
*

View file

@ -43,6 +43,7 @@ class CopyTask extends AbstractTask
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
$currentReleaseId = $this->runtime->getReleaseId();
$tarPath = $this->runtime->getEnvOption('tar_extract_path', 'tar');
$flags = $this->runtime->getEnvOption('tar_extract', 'xfzop');
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
@ -54,7 +55,7 @@ class CopyTask extends AbstractTask
/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdCopy, 300);
if ($process->isSuccessful()) {
$cmdUnTar = sprintf('cd %s && tar %s %s', $targetDir, $flags, $tarRemote);
$cmdUnTar = sprintf('cd %s && %s %s %s', $targetDir, $tarPath, $flags, $tarRemote);
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);
if ($process->isSuccessful()) {
$cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote);

View file

@ -41,9 +41,10 @@ class PrepareTask extends AbstractTask
$this->runtime->setVar('tar_local', $tarLocal);
$excludes = $this->getExcludes();
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
$flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
$from = $this->runtime->getEnvOption('from', './');
$cmdTar = sprintf('tar %s %s %s %s', $flags, $tarLocal, $excludes, $from);
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdTar, 300);

View file

@ -36,7 +36,7 @@ class AsseticDumpTask extends AbstractTask
$command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
/** @var Process $process */
$process = $this->runtime->runCommand(trim($command));
$process = $this->runtime->runCommand(trim($command), $options['timeout']);
return $process->isSuccessful();
}
@ -44,7 +44,7 @@ class AsseticDumpTask extends AbstractTask
protected function getOptions()
{
$options = array_merge(
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
['console' => 'bin/console', 'env' => 'dev', 'flags' => '', 'timeout' => 120],
$this->runtime->getMergedOption('symfony'),
$this->options
);

View file

@ -16,6 +16,7 @@ use Symfony\Component\Process\Process;
class RuntimeMockup extends Runtime
{
protected $ranCommands = [];
protected $ranCommandTimeouts = [];
protected $forceFail = [];
public function getRanCommands()
@ -23,6 +24,11 @@ class RuntimeMockup extends Runtime
return $this->ranCommands;
}
public function getRanCommandTimeoutFor($cmd)
{
return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null;
}
/**
* Generate the Release ID
*
@ -44,6 +50,7 @@ class RuntimeMockup extends Runtime
public function runLocalCommand($cmd, $timeout = 120)
{
$this->ranCommands[] = $cmd;
$this->ranCommandTimeouts[$cmd] = $timeout;
$process = new ProcessMockup($cmd);
$process->forceFail = $this->forceFail;

View file

@ -119,6 +119,20 @@ class RuntimeTest extends TestCase
$this->assertEquals('-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no', $sshConfig['flags']);
}
public function testSSHConfigPortDefinedInHostNotation()
{
$runtime = new Runtime();
$runtime->setWorkingHost('223.12.24.64:1056');
$sshConfig = $runtime->getSSHConfig();
$this->assertEquals('1056', $sshConfig['port']);
$runtime->setWorkingHost('223.12.24.64');
$sshConfig = $runtime->getSSHConfig();
$this->assertEquals('22', $sshConfig['port']);
}
public function testSSHConfigEmptyOptions()
{
$runtime = new Runtime();

View file

@ -0,0 +1,70 @@
<?php
namespace Mage\tests\Task\BuiltIn\Symfony;
use Mage\Task\BuiltIn\Symfony\AsseticDumpTask;
use Mage\Tests\Runtime\RuntimeMockup;
class AsseticDumpTaskTest extends \PHPUnit_Framework_TestCase
{
/**
* @var RuntimeMockup
*/
private $runtime;
public function setUp()
{
$this->runtime = new RuntimeMockup();
$this->runtime->setConfiguration(['environments' => ['test' => []]]);
$this->runtime->setEnvironment('test');
}
public function testAsseticDumpTask()
{
$task = new AsseticDumpTask();
$task->setOptions(['env' => 'test']);
$task->setRuntime($this->runtime);
$this->assertEquals('[Symfony] Assetic Dump', $task->getDescription());
$task->execute();
$testCase = [
'bin/console assetic:dump --env=test' => 120,
];
$this->assertRanCommands($testCase);
}
public function testAsseticDumpTaskWithTimeoutOption()
{
$task = new AsseticDumpTask();
$task->setOptions(['env' => 'test', 'timeout' => 300]);
$task->setRuntime($this->runtime);
$task->execute();
$testCase = [
'bin/console assetic:dump --env=test' => 300,
];
$this->assertRanCommands($testCase);
}
/**
* @param $testCase
*/
private function assertRanCommands($testCase)
{
$ranCommands = $this->runtime->getRanCommands();
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
$index = 0;
foreach ($testCase as $command => $timeout) {
$this->assertEquals($command, $ranCommands[$index++]);
$this->assertEquals($timeout, $this->runtime->getRanCommandTimeoutFor($command));
}
}
}