Skip to content

Commit

Permalink
Merge pull request #393 from andres-montanez/nostromo
Browse files Browse the repository at this point in the history
Release for Version 3.3.0
  • Loading branch information
andres-montanez committed Jul 22, 2017
2 parents 46684ea + 621bb8e commit 3ed4c75
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Mage.php
Expand Up @@ -17,6 +17,6 @@
*/
class Mage
{
const VERSION = '3.2';
const VERSION = '3.3.0';
const CODENAME = 'Nostromo';
}
17 changes: 16 additions & 1 deletion src/Runtime/Runtime.php
Expand Up @@ -457,7 +457,11 @@ public function runRemoteCommand($cmd, $jail, $timeout = 120)
*/
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';
Expand All @@ -470,6 +474,17 @@ public function getSSHConfig()
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
*
Expand Down
3 changes: 2 additions & 1 deletion src/Task/BuiltIn/Deploy/Tar/CopyTask.php
Expand Up @@ -43,6 +43,7 @@ public function execute()
$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);

Expand All @@ -54,7 +55,7 @@ public function execute()
/** @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);
Expand Down
3 changes: 2 additions & 1 deletion src/Task/BuiltIn/Deploy/Tar/PrepareTask.php
Expand Up @@ -41,9 +41,10 @@ public function execute()
$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);
Expand Down
4 changes: 2 additions & 2 deletions src/Task/BuiltIn/Symfony/AsseticDumpTask.php
Expand Up @@ -36,15 +36,15 @@ public function execute()
$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();
}

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
);
Expand Down
7 changes: 7 additions & 0 deletions tests/Runtime/RuntimeMockup.php
Expand Up @@ -16,13 +16,19 @@
class RuntimeMockup extends Runtime
{
protected $ranCommands = [];
protected $ranCommandTimeouts = [];
protected $forceFail = [];

public function getRanCommands()
{
return $this->ranCommands;
}

public function getRanCommandTimeoutFor($cmd)
{
return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null;
}

/**
* Generate the Release ID
*
Expand All @@ -44,6 +50,7 @@ public function generateReleaseId()
public function runLocalCommand($cmd, $timeout = 120)
{
$this->ranCommands[] = $cmd;
$this->ranCommandTimeouts[$cmd] = $timeout;

$process = new ProcessMockup($cmd);
$process->forceFail = $this->forceFail;
Expand Down
14 changes: 14 additions & 0 deletions tests/Runtime/RuntimeTest.php
Expand Up @@ -119,6 +119,20 @@ public function testSSHConfigUndefinedOptions()
$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();
Expand Down
70 changes: 70 additions & 0 deletions tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php
@@ -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));
}
}
}

0 comments on commit 3ed4c75

Please sign in to comment.