mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-07 08:16:40 +02:00
Fixes for v4.1.1
This commit is contained in:
parent
b7ade4d2de
commit
373ce5d761
|
@ -1,6 +1,12 @@
|
||||||
CHANGELOG for 4.X
|
CHANGELOG for 4.X
|
||||||
=================
|
=================
|
||||||
|
|
||||||
|
* 4.1.1 (2021-02-20)
|
||||||
|
* Add `copyDirectory` option
|
||||||
|
* Bug fixes
|
||||||
|
* Improve testing and coverage
|
||||||
|
|
||||||
|
|
||||||
* 4.1.0 (2021-02-19)
|
* 4.1.0 (2021-02-19)
|
||||||
* PHP 8 and Symfony 5 compatibility [PR#448]
|
* PHP 8 and Symfony 5 compatibility [PR#448]
|
||||||
* Timeout option for SSH [PR#436]
|
* Timeout option for SSH [PR#436]
|
||||||
|
|
|
@ -17,6 +17,6 @@ namespace Mage;
|
||||||
*/
|
*/
|
||||||
class Mage
|
class Mage
|
||||||
{
|
{
|
||||||
const VERSION = '4.1.0';
|
const VERSION = '4.1.1';
|
||||||
const CODENAME = 'Discovery One';
|
const CODENAME = 'Discovery One';
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,11 @@ class Runtime
|
||||||
*/
|
*/
|
||||||
protected $rollback = false;
|
protected $rollback = false;
|
||||||
|
|
||||||
|
public function isWindows()
|
||||||
|
{
|
||||||
|
return stripos(PHP_OS, 'WIN') === 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the Release ID
|
* Generate the Release ID
|
||||||
*
|
*
|
||||||
|
|
|
@ -42,11 +42,11 @@ class PrepareTask extends AbstractTask
|
||||||
|
|
||||||
$excludes = $this->getExcludes();
|
$excludes = $this->getExcludes();
|
||||||
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
|
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
|
||||||
$flags = $this->runtime->getEnvOption('tar_create', stripos(PHP_OS, 'WIN') === 0 ? '--force-local -c -z -p -f' : 'cfzp');
|
$flags = $this->runtime->getEnvOption('tar_create', $this->runtime->isWindows() ? '--force-local -c -z -p -f' : 'cfzp');
|
||||||
$from = './';
|
$from = $this->runtime->getEnvOption('from', './');
|
||||||
|
|
||||||
if ($fromPath = $this->runtime->getEnvOption('from', false)) {
|
if ($this->runtime->getEnvOption('copyDirectory', false)) {
|
||||||
$from = sprintf('-C %s %s', $fromPath, $from);
|
$from = sprintf('-C %s ./', $from);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
|
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
|
||||||
|
|
|
@ -13,6 +13,7 @@ namespace Mage\Tests\Command\BuiltIn;
|
||||||
use Mage\Command\BuiltIn\DeployCommand;
|
use Mage\Command\BuiltIn\DeployCommand;
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
use Mage\Tests\MageApplicationMockup;
|
use Mage\Tests\MageApplicationMockup;
|
||||||
|
use Mage\Tests\MageApplicationWindowsMockup;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
@ -133,6 +134,106 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
|
|
||||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||||
|
|
||||||
|
$testCase = array(
|
||||||
|
0 => 'git branch | grep "*"',
|
||||||
|
1 => 'git checkout test',
|
||||||
|
2 => 'git pull',
|
||||||
|
3 => 'composer install --optimize-autoloader',
|
||||||
|
4 => 'composer dump-autoload --optimize',
|
||||||
|
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./dist',
|
||||||
|
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
||||||
|
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||||
|
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
||||||
|
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||||
|
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
|
||||||
|
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
|
||||||
|
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
|
||||||
|
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||||
|
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||||
|
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||||
|
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
|
||||||
|
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
|
||||||
|
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
|
||||||
|
19 => 'rm /tmp/mageXYZ',
|
||||||
|
20 => 'git checkout master',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check total of Executed Commands
|
||||||
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||||||
|
|
||||||
|
// Check Generated Commands
|
||||||
|
foreach ($testCase as $index => $command) {
|
||||||
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(0, $tester->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeploymentWithReleasesWithFromCommandsOnWindows()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationWindowsMockup(__DIR__ . '/../../Resources/testhost-with-from.yml');
|
||||||
|
|
||||||
|
$application->getRuntime()->setReleaseId('20170101015120');
|
||||||
|
|
||||||
|
/** @var AbstractCommand $command */
|
||||||
|
$command = $application->find('deploy');
|
||||||
|
$this->assertTrue($command instanceof DeployCommand);
|
||||||
|
|
||||||
|
$tester = new CommandTester($command);
|
||||||
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
|
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||||
|
|
||||||
|
$testCase = array(
|
||||||
|
0 => 'git branch | grep "*"',
|
||||||
|
1 => 'git checkout test',
|
||||||
|
2 => 'git pull',
|
||||||
|
3 => 'composer install --optimize-autoloader',
|
||||||
|
4 => 'composer dump-autoload --optimize',
|
||||||
|
5 => 'tar --force-local -c -z -p -f /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./dist',
|
||||||
|
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
||||||
|
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||||
|
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
||||||
|
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||||
|
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
|
||||||
|
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
|
||||||
|
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
|
||||||
|
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||||
|
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||||
|
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||||
|
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
|
||||||
|
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
|
||||||
|
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
|
||||||
|
19 => 'rm /tmp/mageXYZ',
|
||||||
|
20 => 'git checkout master',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check total of Executed Commands
|
||||||
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||||||
|
|
||||||
|
// Check Generated Commands
|
||||||
|
foreach ($testCase as $index => $command) {
|
||||||
|
$this->assertEquals($command, $ranCommands[$index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(0, $tester->getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeploymentWithReleasesWithFromCommandsWithDirectoryCopy()
|
||||||
|
{
|
||||||
|
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-from-copy-directory.yml');
|
||||||
|
|
||||||
|
$application->getRuntime()->setReleaseId('20170101015120');
|
||||||
|
|
||||||
|
/** @var AbstractCommand $command */
|
||||||
|
$command = $application->find('deploy');
|
||||||
|
$this->assertTrue($command instanceof DeployCommand);
|
||||||
|
|
||||||
|
$tester = new CommandTester($command);
|
||||||
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
|
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||||
|
|
||||||
$testCase = array(
|
$testCase = array(
|
||||||
0 => 'git branch | grep "*"',
|
0 => 'git branch | grep "*"',
|
||||||
1 => 'git checkout test',
|
1 => 'git checkout test',
|
||||||
|
@ -189,7 +290,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||||
2 => 'git pull',
|
2 => 'git pull',
|
||||||
3 => 'composer install --optimize-autoloader',
|
3 => 'composer install --optimize-autoloader',
|
||||||
4 => 'composer dump-autoload --optimize',
|
4 => 'composer dump-autoload --optimize',
|
||||||
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" -C ./ ./',
|
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
|
||||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
||||||
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
||||||
|
|
27
tests/MageApplicationWindowsMockup.php
Normal file
27
tests/MageApplicationWindowsMockup.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the Magallanes package.
|
||||||
|
*
|
||||||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mage\Tests;
|
||||||
|
|
||||||
|
use Mage\Tests\Runtime\RuntimeWindowsMockup;
|
||||||
|
use Mage\MageApplication;
|
||||||
|
|
||||||
|
class MageApplicationWindowsMockup extends MageApplication
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Gets the Runtime instance to use
|
||||||
|
*
|
||||||
|
* @return RuntimeWindowsMockup
|
||||||
|
*/
|
||||||
|
protected function instantiateRuntime()
|
||||||
|
{
|
||||||
|
return new RuntimeWindowsMockup();
|
||||||
|
}
|
||||||
|
}
|
29
tests/Resources/testhost-with-from-copy-directory.yml
Normal file
29
tests/Resources/testhost-with-from-copy-directory.yml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
magephp:
|
||||||
|
log_dir: /tmp
|
||||||
|
environments:
|
||||||
|
test:
|
||||||
|
user: tester
|
||||||
|
branch: test
|
||||||
|
from: ./dist
|
||||||
|
copyDirectory: true
|
||||||
|
host_path: /var/www/test
|
||||||
|
releases: 4
|
||||||
|
exclude:
|
||||||
|
- ./var/cache/*
|
||||||
|
- ./var/log/*
|
||||||
|
- ./web/app_dev.php
|
||||||
|
-
|
||||||
|
-
|
||||||
|
hosts:
|
||||||
|
- testhost
|
||||||
|
pre-deploy:
|
||||||
|
- git/update
|
||||||
|
- composer/install
|
||||||
|
- composer/dump-autoload
|
||||||
|
on-deploy:
|
||||||
|
- symfony/cache-warmup: { env: 'dev' }
|
||||||
|
- symfony/assets-install: { env: 'dev' }
|
||||||
|
- symfony/cache-pool-prune: { env: 'dev' }
|
||||||
|
on-release:
|
||||||
|
post-release:
|
||||||
|
post-deploy:
|
19
tests/Runtime/RuntimeWindowsMockup.php
Normal file
19
tests/Runtime/RuntimeWindowsMockup.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* This file is part of the Magallanes package.
|
||||||
|
*
|
||||||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mage\Tests\Runtime;
|
||||||
|
|
||||||
|
class RuntimeWindowsMockup extends RuntimeMockup
|
||||||
|
{
|
||||||
|
public function isWindows()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue