mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-09 17:26:45 +02:00
[Nostromo] Refactor Runtime methods.
This commit is contained in:
parent
7493e3cfae
commit
b095cd0bb8
|
@ -48,7 +48,7 @@ class EnvironmentsCommand extends AbstractCommand
|
||||||
$table = new Table($output);
|
$table = new Table($output);
|
||||||
$table->setHeaders(['Environment', 'User', 'Branch', 'Hosts']);
|
$table->setHeaders(['Environment', 'User', 'Branch', 'Hosts']);
|
||||||
|
|
||||||
$configuration = $this->runtime->getConfigOptions('environments');
|
$configuration = $this->runtime->getConfigOption('environments');
|
||||||
foreach ($configuration as $environment => $config) {
|
foreach ($configuration as $environment => $config) {
|
||||||
$row = [$environment];
|
$row = [$environment];
|
||||||
|
|
||||||
|
|
|
@ -70,24 +70,24 @@ class DeployCommand extends AbstractCommand
|
||||||
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
|
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
|
||||||
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
|
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
|
||||||
|
|
||||||
if ($this->runtime->getEnvParam('releases', false)) {
|
if ($this->runtime->getEnvOption('releases', false)) {
|
||||||
$this->runtime->generateReleaseId();
|
$this->runtime->generateReleaseId();
|
||||||
$output->writeln(sprintf(' Release ID: <fg=green>%s</>', $this->runtime->getReleaseId()));
|
$output->writeln(sprintf(' Release ID: <fg=green>%s</>', $this->runtime->getReleaseId()));
|
||||||
$this->log(sprintf('Release ID: %s', $this->runtime->getReleaseId()));
|
$this->log(sprintf('Release ID: %s', $this->runtime->getReleaseId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->runtime->getConfigOptions('log_file', false)) {
|
if ($this->runtime->getConfigOption('log_file', false)) {
|
||||||
$output->writeln(sprintf(' Logfile: <fg=green>%s</>', $this->runtime->getConfigOptions('log_file')));
|
$output->writeln(sprintf(' Logfile: <fg=green>%s</>', $this->runtime->getConfigOption('log_file')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln(sprintf(' Strategy: <fg=green>%s</>', $strategy->getName()));
|
$output->writeln(sprintf(' Strategy: <fg=green>%s</>', $strategy->getName()));
|
||||||
|
|
||||||
if ($input->getOption('branch') !== false) {
|
if ($input->getOption('branch') !== false) {
|
||||||
$this->runtime->setEnvironmentConfig('branch', $input->getOption('branch'));
|
$this->runtime->setEnvOption('branch', $input->getOption('branch'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->runtime->getEnvParam('branch', false)) {
|
if ($this->runtime->getEnvOption('branch', false)) {
|
||||||
$output->writeln(sprintf(' Branch: <fg=green>%s</>', $this->runtime->getEnvParam('branch')));
|
$output->writeln(sprintf(' Branch: <fg=green>%s</>', $this->runtime->getEnvOption('branch')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
@ -140,7 +140,7 @@ class DeployCommand extends AbstractCommand
|
||||||
|
|
||||||
protected function runOnHosts(OutputInterface $output, $tasks)
|
protected function runOnHosts(OutputInterface $output, $tasks)
|
||||||
{
|
{
|
||||||
$hosts = $this->runtime->getEnvParam('hosts');
|
$hosts = $this->runtime->getEnvOption('hosts');
|
||||||
if (count($hosts) == 0) {
|
if (count($hosts) == 0) {
|
||||||
$output->writeln(sprintf(' No hosts defined, skipping %s tasks', $this->getStageName()));
|
$output->writeln(sprintf(' No hosts defined, skipping %s tasks', $this->getStageName()));
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
|
|
@ -58,25 +58,25 @@ class ListCommand extends AbstractCommand
|
||||||
try {
|
try {
|
||||||
$this->runtime->setEnvironment($input->getArgument('environment'));
|
$this->runtime->setEnvironment($input->getArgument('environment'));
|
||||||
|
|
||||||
if (!$this->runtime->getEnvParam('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new RuntimeException('Releases are not enabled', 70);
|
throw new RuntimeException('Releases are not enabled', 70);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
|
$output->writeln(sprintf(' Environment: <fg=green>%s</>', $this->runtime->getEnvironment()));
|
||||||
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
|
$this->log(sprintf('Environment: %s', $this->runtime->getEnvironment()));
|
||||||
|
|
||||||
if ($this->runtime->getConfigOptions('log_file', false)) {
|
if ($this->runtime->getConfigOption('log_file', false)) {
|
||||||
$output->writeln(sprintf(' Logfile: <fg=green>%s</>', $this->runtime->getConfigOptions('log_file')));
|
$output->writeln(sprintf(' Logfile: <fg=green>%s</>', $this->runtime->getConfigOption('log_file')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
|
|
||||||
$hosts = $this->runtime->getEnvParam('hosts');
|
$hosts = $this->runtime->getEnvOption('hosts');
|
||||||
if (count($hosts) == 0) {
|
if (count($hosts) == 0) {
|
||||||
$output->writeln('No hosts defined');
|
$output->writeln('No hosts defined');
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
} else {
|
} else {
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
|
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
$this->runtime->setWorkingHost($host);
|
$this->runtime->setWorkingHost($host);
|
||||||
|
|
|
@ -61,7 +61,7 @@ class RollbackCommand extends DeployCommand
|
||||||
$strategy = $this->runtime->guessStrategy();
|
$strategy = $this->runtime->guessStrategy();
|
||||||
$this->taskFactory = new TaskFactory($this->runtime);
|
$this->taskFactory = new TaskFactory($this->runtime);
|
||||||
|
|
||||||
if (!$this->runtime->getEnvParam('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new RuntimeException('Releases are not enabled', 70);
|
throw new RuntimeException('Releases are not enabled', 70);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,8 @@ class RollbackCommand extends DeployCommand
|
||||||
$output->writeln(sprintf(' Rollback to Release Id: <fg=green>%s</>', $this->runtime->getReleaseId()));
|
$output->writeln(sprintf(' Rollback to Release Id: <fg=green>%s</>', $this->runtime->getReleaseId()));
|
||||||
$this->log(sprintf('Release ID: %s', $this->runtime->getReleaseId()));
|
$this->log(sprintf('Release ID: %s', $this->runtime->getReleaseId()));
|
||||||
|
|
||||||
if ($this->runtime->getConfigOptions('log_file', false)) {
|
if ($this->runtime->getConfigOption('log_file', false)) {
|
||||||
$output->writeln(sprintf(' Logfile: <fg=green>%s</>', $this->runtime->getConfigOptions('log_file')));
|
$output->writeln(sprintf(' Logfile: <fg=green>%s</>', $this->runtime->getConfigOption('log_file')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$output->writeln(sprintf(' Strategy: <fg=green>%s</>', $strategy->getName()));
|
$output->writeln(sprintf(' Strategy: <fg=green>%s</>', $strategy->getName()));
|
||||||
|
@ -104,8 +104,8 @@ class RollbackCommand extends DeployCommand
|
||||||
*/
|
*/
|
||||||
protected function checkReleaseAvailability($releaseToRollback)
|
protected function checkReleaseAvailability($releaseToRollback)
|
||||||
{
|
{
|
||||||
$hosts = $this->runtime->getEnvParam('hosts');
|
$hosts = $this->runtime->getEnvOption('hosts');
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
|
|
||||||
$availableInHosts = 0;
|
$availableInHosts = 0;
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
|
|
|
@ -8,11 +8,10 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mage\Deploy\Strategy\Releases;
|
namespace Mage\Deploy\Strategy;
|
||||||
|
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\Runtime;
|
||||||
use Mage\Deploy\Strategy\StrategyInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy for Deployment with Releases, using TarGz and SCP
|
* Strategy for Deployment with Releases, using TarGz and SCP
|
|
@ -8,11 +8,10 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Mage\Deploy\Strategy\Rsync;
|
namespace Mage\Deploy\Strategy;
|
||||||
|
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\Runtime;
|
||||||
use Mage\Deploy\Strategy\StrategyInterface;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy for Deployment with Rsync
|
* Strategy for Deployment with Rsync
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
namespace Mage\Runtime;
|
namespace Mage\Runtime;
|
||||||
|
|
||||||
use Mage\Deploy\Strategy\Releases\ReleasesStrategy;
|
use Mage\Deploy\Strategy\ReleasesStrategy;
|
||||||
use Mage\Deploy\Strategy\Rsync\RsyncStrategy;
|
use Mage\Deploy\Strategy\RsyncStrategy;
|
||||||
use Mage\Deploy\Strategy\StrategyInterface;
|
use Mage\Deploy\Strategy\StrategyInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\LogLevel;
|
use Psr\Log\LogLevel;
|
||||||
|
@ -190,13 +190,13 @@ class Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the Configuration options for a specific section in the configuration
|
* Retrieves the Configuration Option for a specific section in the configuration
|
||||||
*
|
*
|
||||||
* @param string $key Section name
|
* @param string $key Section name
|
||||||
* @param mixed $default Default value
|
* @param mixed $default Default value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getConfigOptions($key, $default = null)
|
public function getConfigOption($key, $default = null)
|
||||||
{
|
{
|
||||||
if (array_key_exists($key, $this->configuration)) {
|
if (array_key_exists($key, $this->configuration)) {
|
||||||
return $this->configuration[$key];
|
return $this->configuration[$key];
|
||||||
|
@ -206,31 +206,13 @@ class Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration for the current Environment
|
* Returns the Configuration Option for a specific section the current Environment
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getEnvironmentConfig()
|
|
||||||
{
|
|
||||||
if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!array_key_exists($this->environment, $this->configuration['environments'])) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->configuration['environments'][$this->environment];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the configuration parameter for the current Environment
|
|
||||||
*
|
*
|
||||||
* @param string $key Section/Parameter name
|
* @param string $key Section/Parameter name
|
||||||
* @param mixed $default Default value
|
* @param mixed $default Default value
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function getEnvParam($key, $default = null)
|
public function getEnvOption($key, $default = null)
|
||||||
{
|
{
|
||||||
if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) {
|
if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) {
|
||||||
return $default;
|
return $default;
|
||||||
|
@ -248,13 +230,13 @@ class Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites an Environment configuration option
|
* Overwrites an Environment Configuration Option
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return Runtime
|
* @return Runtime
|
||||||
*/
|
*/
|
||||||
public function setEnvironmentConfig($key, $value)
|
public function setEnvOption($key, $value)
|
||||||
{
|
{
|
||||||
if (array_key_exists('environments', $this->configuration) && is_array($this->configuration['environments'])) {
|
if (array_key_exists('environments', $this->configuration) && is_array($this->configuration['environments'])) {
|
||||||
if (array_key_exists($this->environment, $this->configuration['environments'])) {
|
if (array_key_exists($this->environment, $this->configuration['environments'])) {
|
||||||
|
@ -321,10 +303,17 @@ class Runtime
|
||||||
*/
|
*/
|
||||||
public function getTasks()
|
public function getTasks()
|
||||||
{
|
{
|
||||||
$config = $this->getEnvironmentConfig();
|
if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) {
|
||||||
if (array_key_exists($this->stage, $config)) {
|
return [];
|
||||||
if (is_array($config[$this->stage])) {
|
}
|
||||||
return $config[$this->stage];
|
|
||||||
|
if (!array_key_exists($this->environment, $this->configuration['environments'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists($this->stage, $this->configuration['environments'][$this->environment])) {
|
||||||
|
if (is_array($this->configuration['environments'][$this->environment][$this->stage])) {
|
||||||
|
return $this->configuration['environments'][$this->environment][$this->stage];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,8 +409,8 @@ class Runtime
|
||||||
*/
|
*/
|
||||||
public function runRemoteCommand($cmd, $jail, $timeout = 120)
|
public function runRemoteCommand($cmd, $jail, $timeout = 120)
|
||||||
{
|
{
|
||||||
$user = $this->getEnvParam('user');
|
$user = $this->getEnvOption('user');
|
||||||
$sudo = $this->getEnvParam('sudo', false);
|
$sudo = $this->getEnvOption('sudo', false);
|
||||||
$host = $this->getWorkingHost();
|
$host = $this->getWorkingHost();
|
||||||
$sshConfig = $this->getSSHConfig();
|
$sshConfig = $this->getSSHConfig();
|
||||||
|
|
||||||
|
@ -430,7 +419,7 @@ class Runtime
|
||||||
$cmdDelegate = sprintf('sudo %s', $cmd);
|
$cmdDelegate = sprintf('sudo %s', $cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hostPath = rtrim($this->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->getEnvOption('host_path'), '/');
|
||||||
if ($jail && $this->getReleaseId()) {
|
if ($jail && $this->getReleaseId()) {
|
||||||
$cmdDelegate = sprintf('cd %s/releases/%s && %s', $hostPath, $this->getReleaseId(), $cmdDelegate);
|
$cmdDelegate = sprintf('cd %s/releases/%s && %s', $hostPath, $this->getReleaseId(), $cmdDelegate);
|
||||||
} elseif ($jail) {
|
} elseif ($jail) {
|
||||||
|
@ -450,7 +439,7 @@ class Runtime
|
||||||
*/
|
*/
|
||||||
public function getSSHConfig()
|
public function getSSHConfig()
|
||||||
{
|
{
|
||||||
$sshConfig = $this->getEnvParam('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 (!array_key_exists('port', $sshConfig)) {
|
if (!array_key_exists('port', $sshConfig)) {
|
||||||
$sshConfig['port'] = '22';
|
$sshConfig['port'] = '22';
|
||||||
|
@ -491,7 +480,7 @@ class Runtime
|
||||||
*/
|
*/
|
||||||
public function getBranch()
|
public function getBranch()
|
||||||
{
|
{
|
||||||
return $this->getEnvParam('branch', false);
|
return $this->getEnvOption('branch', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -503,7 +492,7 @@ class Runtime
|
||||||
{
|
{
|
||||||
$strategy = new RsyncStrategy();
|
$strategy = new RsyncStrategy();
|
||||||
|
|
||||||
if ($this->getEnvParam('releases', false)) {
|
if ($this->getEnvOption('releases', false)) {
|
||||||
$strategy = new ReleasesStrategy();
|
$strategy = new ReleasesStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class DumpAutoloadTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$userOptions = $this->runtime->getConfigOptions('composer', []);
|
$userOptions = $this->runtime->getConfigOption('composer', []);
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['path' => 'composer', 'flags' => '--optimize'],
|
['path' => 'composer', 'flags' => '--optimize'],
|
||||||
(is_array($userOptions) ? $userOptions : []),
|
(is_array($userOptions) ? $userOptions : []),
|
||||||
|
|
|
@ -43,7 +43,7 @@ class InstallTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$userOptions = $this->runtime->getConfigOptions('composer', []);
|
$userOptions = $this->runtime->getConfigOption('composer', []);
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['path' => 'composer', 'flags' => '--optimize-autoloader'],
|
['path' => 'composer', 'flags' => '--optimize-autoloader'],
|
||||||
(is_array($userOptions) ? $userOptions : []),
|
(is_array($userOptions) ? $userOptions : []),
|
||||||
|
|
|
@ -32,9 +32,9 @@ class CleanupTask extends AbstractTask
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$currentReleaseId = $this->runtime->getReleaseId();
|
$currentReleaseId = $this->runtime->getReleaseId();
|
||||||
$maxReleases = $this->runtime->getEnvParam('releases');
|
$maxReleases = $this->runtime->getEnvOption('releases');
|
||||||
|
|
||||||
$cmdListReleases = sprintf('ls -1 %s/releases', $hostPath);
|
$cmdListReleases = sprintf('ls -1 %s/releases', $hostPath);
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class PrepareTask extends AbstractTask
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
|
|
||||||
$cmdMakeDir = sprintf('mkdir -p %s/releases/%s', $hostPath, $this->runtime->getReleaseId());
|
$cmdMakeDir = sprintf('mkdir -p %s/releases/%s', $hostPath, $this->runtime->getReleaseId());
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,11 @@ class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvParam('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$releaseId = $this->runtime->getReleaseId();
|
$releaseId = $this->runtime->getReleaseId();
|
||||||
|
|
||||||
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s current', $hostPath, $releaseId);
|
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s current', $hostPath, $releaseId);
|
||||||
|
|
|
@ -33,14 +33,14 @@ class RsyncTask extends AbstractTask
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
$flags = $this->runtime->getConfigOptions('rsync', '-avz');
|
$flags = $this->runtime->getConfigOption('rsync', '-avz');
|
||||||
$sshConfig = $this->runtime->getSSHConfig();
|
$sshConfig = $this->runtime->getSSHConfig();
|
||||||
$user = $this->runtime->getEnvParam('user', $this->runtime->getCurrentUser());
|
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
||||||
$host = $this->runtime->getWorkingHost();
|
$host = $this->runtime->getWorkingHost();
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$targetDir = rtrim($hostPath, '/');
|
$targetDir = rtrim($hostPath, '/');
|
||||||
|
|
||||||
if ($this->runtime->getEnvParam('releases', false)) {
|
if ($this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('Can\'t be used with Releases, use "deploy/targz/copy"');
|
throw new ErrorException('Can\'t be used with Releases, use "deploy/targz/copy"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class RsyncTask extends AbstractTask
|
||||||
|
|
||||||
protected function getExcludes()
|
protected function getExcludes()
|
||||||
{
|
{
|
||||||
$excludes = $this->runtime->getEnvParam('exclude', []);
|
$excludes = $this->runtime->getEnvOption('exclude', []);
|
||||||
$excludes = array_merge(['.git'], $excludes);
|
$excludes = array_merge(['.git'], $excludes);
|
||||||
|
|
||||||
foreach ($excludes as &$exclude) {
|
foreach ($excludes as &$exclude) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ class CleanupTask extends AbstractTask
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvParam('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,14 @@ class CopyTask extends AbstractTask
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvParam('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->runtime->getEnvParam('user', $this->runtime->getCurrentUser());
|
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
||||||
$host = $this->runtime->getWorkingHost();
|
$host = $this->runtime->getWorkingHost();
|
||||||
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
|
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
|
||||||
$hostPath = rtrim($this->runtime->getEnvParam('host_path'), '/');
|
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||||
$currentReleaseId = $this->runtime->getReleaseId();
|
$currentReleaseId = $this->runtime->getReleaseId();
|
||||||
|
|
||||||
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
|
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
|
||||||
|
|
|
@ -33,7 +33,7 @@ class PrepareTask extends AbstractTask
|
||||||
|
|
||||||
public function execute()
|
public function execute()
|
||||||
{
|
{
|
||||||
if (!$this->runtime->getEnvParam('releases', false)) {
|
if (!$this->runtime->getEnvOption('releases', false)) {
|
||||||
throw new ErrorException('This task is only available with releases enabled', 40);
|
throw new ErrorException('This task is only available with releases enabled', 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ class PrepareTask extends AbstractTask
|
||||||
|
|
||||||
protected function getExcludes()
|
protected function getExcludes()
|
||||||
{
|
{
|
||||||
$excludes = $this->runtime->getEnvParam('exclude', []);
|
$excludes = $this->runtime->getEnvOption('exclude', []);
|
||||||
$excludes = array_merge(['.git'], $excludes);
|
$excludes = array_merge(['.git'], $excludes);
|
||||||
|
|
||||||
foreach ($excludes as &$exclude) {
|
foreach ($excludes as &$exclude) {
|
||||||
|
|
|
@ -70,7 +70,7 @@ class ChangeBranchTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$branch = $this->runtime->getEnvParam('branch', 'master');
|
$branch = $this->runtime->getEnvOption('branch', 'master');
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['path' => 'git', 'branch' => $branch],
|
['path' => 'git', 'branch' => $branch],
|
||||||
$this->options
|
$this->options
|
||||||
|
|
|
@ -43,7 +43,7 @@ class UpdateTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$branch = $this->runtime->getEnvParam('branch', 'master');
|
$branch = $this->runtime->getEnvOption('branch', 'master');
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['path' => 'git', 'branch' => $branch],
|
['path' => 'git', 'branch' => $branch],
|
||||||
$this->options
|
$this->options
|
||||||
|
|
|
@ -43,8 +43,8 @@ class AsseticDumpTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$userGlobalOptions = $this->runtime->getConfigOptions('symfony', []);
|
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||||
$userEnvOptions = $this->runtime->getEnvParam('symfony', []);
|
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||||
|
|
|
@ -43,8 +43,8 @@ class AssetsInstallTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$userGlobalOptions = $this->runtime->getConfigOptions('symfony', []);
|
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||||
$userEnvOptions = $this->runtime->getEnvParam('symfony', []);
|
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
|
['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||||
|
|
|
@ -43,8 +43,8 @@ class CacheClearTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$userGlobalOptions = $this->runtime->getConfigOptions('symfony', []);
|
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||||
$userEnvOptions = $this->runtime->getEnvParam('symfony', []);
|
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||||
|
|
|
@ -43,8 +43,8 @@ class CacheWarmupTask extends AbstractTask
|
||||||
|
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$userGlobalOptions = $this->runtime->getConfigOptions('symfony', []);
|
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||||
$userEnvOptions = $this->runtime->getEnvParam('symfony', []);
|
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
namespace Mage\Tests\Deploy;
|
namespace Mage\Tests\Deploy;
|
||||||
|
|
||||||
use Mage\Deploy\Strategy\Releases\ReleasesStrategy;
|
use Mage\Deploy\Strategy\ReleasesStrategy;
|
||||||
use Mage\Deploy\Strategy\Rsync\RsyncStrategy;
|
use Mage\Deploy\Strategy\RsyncStrategy;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\Runtime;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
|
@ -40,26 +40,6 @@ class RuntimeTest extends TestCase
|
||||||
$this->assertLessThanOrEqual(2, $dateDiff->s);
|
$this->assertLessThanOrEqual(2, $dateDiff->s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyEnvironmentConfig()
|
|
||||||
{
|
|
||||||
$runtime = new Runtime();
|
|
||||||
$config = $runtime->getEnvironmentConfig();
|
|
||||||
|
|
||||||
$this->assertTrue(is_array($config));
|
|
||||||
$this->assertEquals(0, count($config));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testInvalidEnvironmentConfig()
|
|
||||||
{
|
|
||||||
$runtime = new RuntimeMockup();
|
|
||||||
$runtime->setConfiguration(['environments' => ['valid' => []]]);
|
|
||||||
$runtime->setInvalidEnvironment('invalid');
|
|
||||||
$config = $runtime->getEnvironmentConfig();
|
|
||||||
|
|
||||||
$this->assertTrue(is_array($config));
|
|
||||||
$this->assertEquals(0, count($config));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testInvalidEnvironments()
|
public function testInvalidEnvironments()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue