mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-16 20:45:02 +02:00
[Nostromo] Allow to 'sudo' remote commands
This commit is contained in:
parent
90f122f0ad
commit
83551bd7b8
|
@ -392,10 +392,16 @@ class Runtime
|
||||||
public function runRemoteCommand($cmd, $jail = true, $timeout = 120)
|
public function runRemoteCommand($cmd, $jail = true, $timeout = 120)
|
||||||
{
|
{
|
||||||
$user = $this->getEnvironmentConfig('user');
|
$user = $this->getEnvironmentConfig('user');
|
||||||
|
$sudo = $this->getEnvironmentConfig('sudo', false);
|
||||||
$host = $this->getWorkingHost();
|
$host = $this->getWorkingHost();
|
||||||
$sshConfig = $this->getSSHConfig();
|
$sshConfig = $this->getSSHConfig();
|
||||||
|
|
||||||
|
if ($sudo === true) {
|
||||||
|
$cmdDelegate = sprintf('sudo %s', $cmd);
|
||||||
|
} else {
|
||||||
$cmdDelegate = $cmd;
|
$cmdDelegate = $cmd;
|
||||||
|
}
|
||||||
|
|
||||||
if ($jail) {
|
if ($jail) {
|
||||||
$hostPath = rtrim($this->getEnvironmentConfig('host_path'), '/');
|
$hostPath = rtrim($this->getEnvironmentConfig('host_path'), '/');
|
||||||
if ($this->getReleaseId()) {
|
if ($this->getReleaseId()) {
|
||||||
|
|
|
@ -400,6 +400,111 @@ class DeployCommandTest extends TestCase
|
||||||
$this->assertEquals(0, $tester->getStatusCode());
|
$this->assertEquals(0, $tester->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDeploymentWithSudo()
|
||||||
|
{
|
||||||
|
$application = new MageTestApplication();
|
||||||
|
$application->add(new DeployCommand());
|
||||||
|
|
||||||
|
$runtime = new RuntimeMockup();
|
||||||
|
$runtime->setConfiguration(array(
|
||||||
|
'environments' =>
|
||||||
|
array(
|
||||||
|
'test' =>
|
||||||
|
array(
|
||||||
|
'user' => 'tester',
|
||||||
|
'sudo' => true,
|
||||||
|
'branch' => 'test',
|
||||||
|
'host_path' => '/var/www/test',
|
||||||
|
'exclude' =>
|
||||||
|
array(
|
||||||
|
0 => 'vendor',
|
||||||
|
1 => 'app/cache',
|
||||||
|
2 => 'app/log',
|
||||||
|
3 => 'web/app_dev.php',
|
||||||
|
),
|
||||||
|
'hosts' =>
|
||||||
|
array(
|
||||||
|
0 => 'testhost',
|
||||||
|
),
|
||||||
|
'pre-deploy' =>
|
||||||
|
array(
|
||||||
|
0 => 'git/update',
|
||||||
|
1 => 'composer/install',
|
||||||
|
2 => 'composer/generate-autoload',
|
||||||
|
),
|
||||||
|
'on-deploy' =>
|
||||||
|
array(
|
||||||
|
0 =>
|
||||||
|
array(
|
||||||
|
'symfony/cache-clear' =>
|
||||||
|
array(
|
||||||
|
'env' => 'dev',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
1 =>
|
||||||
|
array(
|
||||||
|
'symfony/cache-warmup' =>
|
||||||
|
array(
|
||||||
|
'env' => 'dev',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
2 =>
|
||||||
|
array(
|
||||||
|
'symfony/assets-install' =>
|
||||||
|
array(
|
||||||
|
'env' => 'dev',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
3 =>
|
||||||
|
array(
|
||||||
|
'symfony/assetic-dump' =>
|
||||||
|
array(
|
||||||
|
'env' => 'dev',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'on-release' => null,
|
||||||
|
'post-release' => null,
|
||||||
|
'post-deploy' => null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
/** @var AbstractCommand $command */
|
||||||
|
$command = $application->find('deploy');
|
||||||
|
$command->setRuntime($runtime);
|
||||||
|
|
||||||
|
$tester = new CommandTester($command);
|
||||||
|
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands();
|
||||||
|
|
||||||
|
$testCase = array(
|
||||||
|
0 => 'git branch | grep "*"',
|
||||||
|
1 => 'git checkout test',
|
||||||
|
2 => 'git pull',
|
||||||
|
3 => 'composer install --dev',
|
||||||
|
4 => 'composer dumpautoload --optimize',
|
||||||
|
5 => 'rsync -avz --exclude=.git --exclude=vendor --exclude=app/cache --exclude=app/log --exclude=web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||||
|
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:clear --env=dev \\"',
|
||||||
|
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:warmup --env=dev \\"',
|
||||||
|
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assets:install --env=dev --symlink --relative web\\"',
|
||||||
|
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assetic:dump --env=dev \\"',
|
||||||
|
10 => '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 testDeploymentWithSkippingTask()
|
public function testDeploymentWithSkippingTask()
|
||||||
{
|
{
|
||||||
$application = new MageTestApplication();
|
$application = new MageTestApplication();
|
||||||
|
|
Loading…
Reference in a new issue