diff --git a/CHANGELOG.md b/CHANGELOG.md index 00a628c9..d40ac366 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/src/Mage.php b/src/Mage.php index 79fb8740..435b2c14 100644 --- a/src/Mage.php +++ b/src/Mage.php @@ -17,6 +17,6 @@ */ class Mage { - const VERSION = '3.2'; + const VERSION = '3.3.0'; const CODENAME = 'Nostromo'; } diff --git a/src/Runtime/Runtime.php b/src/Runtime/Runtime.php index b42826d4..f28e03fe 100644 --- a/src/Runtime/Runtime.php +++ b/src/Runtime/Runtime.php @@ -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'; @@ -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 * diff --git a/src/Task/BuiltIn/Deploy/Tar/CopyTask.php b/src/Task/BuiltIn/Deploy/Tar/CopyTask.php index 06094527..294d2bc6 100644 --- a/src/Task/BuiltIn/Deploy/Tar/CopyTask.php +++ b/src/Task/BuiltIn/Deploy/Tar/CopyTask.php @@ -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); @@ -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); diff --git a/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php b/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php index fb0c5fe2..9db84862 100644 --- a/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php +++ b/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php @@ -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); diff --git a/src/Task/BuiltIn/Symfony/AsseticDumpTask.php b/src/Task/BuiltIn/Symfony/AsseticDumpTask.php index 3f23d193..8d1400c4 100644 --- a/src/Task/BuiltIn/Symfony/AsseticDumpTask.php +++ b/src/Task/BuiltIn/Symfony/AsseticDumpTask.php @@ -36,7 +36,7 @@ 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(); } @@ -44,7 +44,7 @@ public function execute() 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 ); diff --git a/tests/Runtime/RuntimeMockup.php b/tests/Runtime/RuntimeMockup.php index 622da0c7..65b6c325 100644 --- a/tests/Runtime/RuntimeMockup.php +++ b/tests/Runtime/RuntimeMockup.php @@ -16,6 +16,7 @@ class RuntimeMockup extends Runtime { protected $ranCommands = []; + protected $ranCommandTimeouts = []; protected $forceFail = []; public function getRanCommands() @@ -23,6 +24,11 @@ public function getRanCommands() return $this->ranCommands; } + public function getRanCommandTimeoutFor($cmd) + { + return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null; + } + /** * Generate the Release ID * @@ -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; diff --git a/tests/Runtime/RuntimeTest.php b/tests/Runtime/RuntimeTest.php index 64a96c95..cb1ccd9f 100644 --- a/tests/Runtime/RuntimeTest.php +++ b/tests/Runtime/RuntimeTest.php @@ -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(); diff --git a/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php new file mode 100644 index 00000000..e1f694ee --- /dev/null +++ b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php @@ -0,0 +1,70 @@ +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)); + } + } +}