From 280f48cd184f5e4e980c31d17fcdacc8e1a150e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Fri, 14 Apr 2017 23:07:04 -0300 Subject: [PATCH 1/8] Version --- src/Mage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mage.php b/src/Mage.php index 79fb8740..4944c52d 100644 --- a/src/Mage.php +++ b/src/Mage.php @@ -17,6 +17,6 @@ */ class Mage { - const VERSION = '3.2'; + const VERSION = '3.x-dev'; const CODENAME = 'Nostromo'; } From 21bcdf76cc9e20223586bf6bffc48cb5e6b7d9c3 Mon Sep 17 00:00:00 2001 From: Tobias Lode Date: Mon, 29 May 2017 10:07:13 +0200 Subject: [PATCH 2/8] Add timeout option for assetic:dump task --- src/Task/BuiltIn/Symfony/AsseticDumpTask.php | 4 +- tests/Runtime/RuntimeMockup.php | 7 ++ .../BuiltIn/Symfony/AsseticDumpTaskTest.php | 70 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php 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..e5377b46 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 $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/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php new file mode 100644 index 00000000..b481f47d --- /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)); + } + } +} From 66191b7088e7748930ad6f83f933cd89add0aa11 Mon Sep 17 00:00:00 2001 From: Tobias Lode Date: Mon, 29 May 2017 10:38:58 +0200 Subject: [PATCH 3/8] Remove coalesce operator Remove strict types declaration --- tests/Runtime/RuntimeMockup.php | 2 +- tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Runtime/RuntimeMockup.php b/tests/Runtime/RuntimeMockup.php index e5377b46..65b6c325 100644 --- a/tests/Runtime/RuntimeMockup.php +++ b/tests/Runtime/RuntimeMockup.php @@ -26,7 +26,7 @@ public function getRanCommands() public function getRanCommandTimeoutFor($cmd) { - return $this->ranCommandTimeouts[$cmd] ?? null; + return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null; } /** diff --git a/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php index b481f47d..e1f694ee 100644 --- a/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php +++ b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php @@ -1,4 +1,4 @@ - Date: Wed, 5 Jul 2017 12:13:09 +0200 Subject: [PATCH 4/8] Support colon notation in host config definition --- src/Runtime/Runtime.php | 15 +++++++++++++-- tests/Runtime/RuntimeTest.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Runtime/Runtime.php b/src/Runtime/Runtime.php index b42826d4..5c3304b5 100644 --- a/src/Runtime/Runtime.php +++ b/src/Runtime/Runtime.php @@ -457,10 +457,10 @@ 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', ['flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']); if (!array_key_exists('port', $sshConfig)) { - $sshConfig['port'] = '22'; + $sshConfig['port'] = $this->getHostPort(); } if (!array_key_exists('flags', $sshConfig)) { @@ -470,6 +470,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] : '22'; + } + /** * Gets a Temporal File name * 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(); From 4735f0c51ed8cd9b7e3e3658fed950e0d5bd67fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 22 Jul 2017 16:35:28 -0300 Subject: [PATCH 5/8] Tweak host port --- src/Runtime/Runtime.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Runtime/Runtime.php b/src/Runtime/Runtime.php index 5c3304b5..f28e03fe 100644 --- a/src/Runtime/Runtime.php +++ b/src/Runtime/Runtime.php @@ -457,12 +457,16 @@ public function runRemoteCommand($cmd, $jail, $timeout = 120) */ public function getSSHConfig() { - $sshConfig = $this->getEnvOption('ssh', ['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 (!array_key_exists('port', $sshConfig)) { + if ($this->getHostPort() !== null) { $sshConfig['port'] = $this->getHostPort(); } + if (!array_key_exists('port', $sshConfig)) { + $sshConfig['port'] = '22'; + } + if (!array_key_exists('flags', $sshConfig)) { $sshConfig['flags'] = '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'; } @@ -478,7 +482,7 @@ public function getSSHConfig() public function getHostPort() { $info = explode(':', $this->getWorkingHost()); - return isset($info[1]) ? $info[1] : '22'; + return isset($info[1]) ? $info[1] : null; } /** From c8d868962232b35226a3a11f29ffe1aff09beea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 22 Jul 2017 17:14:36 -0300 Subject: [PATCH 6/8] Allow to define the tar binary path. --- src/Task/BuiltIn/Deploy/Tar/CopyTask.php | 3 ++- src/Task/BuiltIn/Deploy/Tar/PrepareTask.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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); From b62ae49bb0aee99377bee2258e614983265fc249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 22 Jul 2017 17:24:19 -0300 Subject: [PATCH 7/8] Update Changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) 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 From 621bb8e8df7b92181fd6561ea60e8cbcbeb291ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 22 Jul 2017 17:46:31 -0300 Subject: [PATCH 8/8] Update to Version 3.3.0 --- src/Mage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mage.php b/src/Mage.php index 4944c52d..435b2c14 100644 --- a/src/Mage.php +++ b/src/Mage.php @@ -17,6 +17,6 @@ */ class Mage { - const VERSION = '3.x-dev'; + const VERSION = '3.3.0'; const CODENAME = 'Nostromo'; }