mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	Merge pull request #393 from andres-montanez/nostromo
Release for Version 3.3.0
This commit is contained in:
		
						commit
						3ed4c758c0
					
				@ -1,6 +1,11 @@
 | 
				
			|||||||
CHANGELOG for 3.X
 | 
					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)
 | 
					* 3.2.0 (2017-04-14)
 | 
				
			||||||
 * Allow to pre-register Custom Tasks
 | 
					 * Allow to pre-register Custom Tasks
 | 
				
			||||||
 * [PR#365] New option "from" to define deployment start point
 | 
					 * [PR#365] New option "from" to define deployment start point
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,6 @@ namespace Mage;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class Mage
 | 
					class Mage
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    const VERSION = '3.2';
 | 
					    const VERSION = '3.3.0';
 | 
				
			||||||
    const CODENAME = 'Nostromo';
 | 
					    const CODENAME = 'Nostromo';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -457,7 +457,11 @@ class Runtime
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getSSHConfig()
 | 
					    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)) {
 | 
					        if (!array_key_exists('port', $sshConfig)) {
 | 
				
			||||||
            $sshConfig['port'] = '22';
 | 
					            $sshConfig['port'] = '22';
 | 
				
			||||||
@ -470,6 +474,17 @@ class Runtime
 | 
				
			|||||||
        return $sshConfig;
 | 
					        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
 | 
					     * Gets a Temporal File name
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
@ -43,6 +43,7 @@ class CopyTask extends AbstractTask
 | 
				
			|||||||
        $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
 | 
					        $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
 | 
				
			||||||
        $currentReleaseId = $this->runtime->getReleaseId();
 | 
					        $currentReleaseId = $this->runtime->getReleaseId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tarPath = $this->runtime->getEnvOption('tar_extract_path', 'tar');
 | 
				
			||||||
        $flags = $this->runtime->getEnvOption('tar_extract', 'xfzop');
 | 
					        $flags = $this->runtime->getEnvOption('tar_extract', 'xfzop');
 | 
				
			||||||
        $targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
 | 
					        $targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -54,7 +55,7 @@ class CopyTask extends AbstractTask
 | 
				
			|||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runLocalCommand($cmdCopy, 300);
 | 
					        $process = $this->runtime->runLocalCommand($cmdCopy, 300);
 | 
				
			||||||
        if ($process->isSuccessful()) {
 | 
					        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);
 | 
					            $process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);
 | 
				
			||||||
            if ($process->isSuccessful()) {
 | 
					            if ($process->isSuccessful()) {
 | 
				
			||||||
                $cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote);
 | 
					                $cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote);
 | 
				
			||||||
 | 
				
			|||||||
@ -41,9 +41,10 @@ class PrepareTask extends AbstractTask
 | 
				
			|||||||
        $this->runtime->setVar('tar_local', $tarLocal);
 | 
					        $this->runtime->setVar('tar_local', $tarLocal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $excludes = $this->getExcludes();
 | 
					        $excludes = $this->getExcludes();
 | 
				
			||||||
 | 
					        $tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
 | 
				
			||||||
        $flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
 | 
					        $flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
 | 
				
			||||||
        $from = $this->runtime->getEnvOption('from', './');
 | 
					        $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 */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runLocalCommand($cmdTar, 300);
 | 
					        $process = $this->runtime->runLocalCommand($cmdTar, 300);
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,7 @@ class AsseticDumpTask extends AbstractTask
 | 
				
			|||||||
        $command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
 | 
					        $command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand(trim($command));
 | 
					        $process = $this->runtime->runCommand(trim($command), $options['timeout']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $process->isSuccessful();
 | 
					        return $process->isSuccessful();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -44,7 +44,7 @@ class AsseticDumpTask extends AbstractTask
 | 
				
			|||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => '', 'timeout' => 120],
 | 
				
			||||||
            $this->runtime->getMergedOption('symfony'),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
				
			|||||||
@ -16,6 +16,7 @@ use Symfony\Component\Process\Process;
 | 
				
			|||||||
class RuntimeMockup extends Runtime
 | 
					class RuntimeMockup extends Runtime
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    protected $ranCommands = [];
 | 
					    protected $ranCommands = [];
 | 
				
			||||||
 | 
					    protected $ranCommandTimeouts = [];
 | 
				
			||||||
    protected $forceFail = [];
 | 
					    protected $forceFail = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getRanCommands()
 | 
					    public function getRanCommands()
 | 
				
			||||||
@ -23,6 +24,11 @@ class RuntimeMockup extends Runtime
 | 
				
			|||||||
        return $this->ranCommands;
 | 
					        return $this->ranCommands;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getRanCommandTimeoutFor($cmd)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Generate the Release ID
 | 
					     * Generate the Release ID
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -44,6 +50,7 @@ class RuntimeMockup extends Runtime
 | 
				
			|||||||
    public function runLocalCommand($cmd, $timeout = 120)
 | 
					    public function runLocalCommand($cmd, $timeout = 120)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->ranCommands[] = $cmd;
 | 
					        $this->ranCommands[] = $cmd;
 | 
				
			||||||
 | 
					        $this->ranCommandTimeouts[$cmd] = $timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $process = new ProcessMockup($cmd);
 | 
					        $process = new ProcessMockup($cmd);
 | 
				
			||||||
        $process->forceFail = $this->forceFail;
 | 
					        $process->forceFail = $this->forceFail;
 | 
				
			||||||
 | 
				
			|||||||
@ -119,6 +119,20 @@ class RuntimeTest extends TestCase
 | 
				
			|||||||
        $this->assertEquals('-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no', $sshConfig['flags']);
 | 
					        $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()
 | 
					    public function testSSHConfigEmptyOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $runtime = new Runtime();
 | 
					        $runtime = new Runtime();
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										70
									
								
								tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php
									
									
									
									
									
										Normal 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));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user