mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-26 02:12:14 +02:00
Refactor Runtime to allow custom implementation
This commit is contained in:
parent
05130cb7bc
commit
74c60f55ef
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace Mage\Command;
|
namespace Mage\Command;
|
||||||
|
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\RuntimeInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\LogLevel;
|
use Psr\Log\LogLevel;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
@ -23,55 +23,31 @@ use Symfony\Component\Console\Command\Command;
|
||||||
abstract class AbstractCommand extends Command
|
abstract class AbstractCommand extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Runtime Current Runtime instance
|
* @var RuntimeInterface Current Runtime instance
|
||||||
*/
|
*/
|
||||||
protected $runtime;
|
protected $runtime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var LoggerInterface|null The instance of the logger, it's optional
|
* Set the Runtime configuration
|
||||||
*/
|
|
||||||
private $logger = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure the Command and create the Runtime configuration
|
|
||||||
*
|
*
|
||||||
* @param array $configuration Magallanes configuration
|
* @param RuntimeInterface $runtime Runtime container
|
||||||
* @return AbstractCommand
|
* @return AbstractCommand
|
||||||
*/
|
*/
|
||||||
public function setConfiguration($configuration)
|
public function setRuntime(RuntimeInterface $runtime)
|
||||||
{
|
{
|
||||||
$this->runtime = new Runtime();
|
$this->runtime = $runtime;
|
||||||
$this->runtime->setConfiguration($configuration);
|
|
||||||
$this->runtime->setLogger($this->logger);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the logger
|
* Logs a message
|
||||||
*
|
|
||||||
* @param LoggerInterface $logger
|
|
||||||
* @return AbstractCommand
|
|
||||||
*/
|
|
||||||
public function setLogger(LoggerInterface $logger = null)
|
|
||||||
{
|
|
||||||
$this->logger = $logger;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs a message, if logger is valid instance
|
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param string $level
|
* @param string $level
|
||||||
* @return AbstractCommand
|
|
||||||
*/
|
*/
|
||||||
public function log($message, $level = LogLevel::DEBUG)
|
public function log($message, $level = LogLevel::DEBUG)
|
||||||
{
|
{
|
||||||
if ($this->logger instanceof LoggerInterface) {
|
$this->runtime->log($message, $level);
|
||||||
$this->logger->log($level, $message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Mage\Command\BuiltIn;
|
||||||
use Mage\Runtime\Exception\DeploymentException;
|
use Mage\Runtime\Exception\DeploymentException;
|
||||||
use Mage\Runtime\Exception\InvalidEnvironmentException;
|
use Mage\Runtime\Exception\InvalidEnvironmentException;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\RuntimeInterface;
|
||||||
use Mage\Task\ErrorException;
|
use Mage\Task\ErrorException;
|
||||||
use Mage\Task\ExecuteOnRollbackInterface;
|
use Mage\Task\ExecuteOnRollbackInterface;
|
||||||
use Mage\Task\AbstractTask;
|
use Mage\Task\AbstractTask;
|
||||||
|
@ -105,7 +105,7 @@ class DeployCommand extends AbstractCommand
|
||||||
protected function runDeployment(OutputInterface $output)
|
protected function runDeployment(OutputInterface $output)
|
||||||
{
|
{
|
||||||
// Run Pre Deploy Tasks
|
// Run Pre Deploy Tasks
|
||||||
$this->runtime->setStage(Runtime::PRE_DEPLOY);
|
$this->runtime->setStage(RuntimeInterface::PRE_DEPLOY);
|
||||||
$preDeployTasks = $this->runtime->getTasks();
|
$preDeployTasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getEnvironmentConfig('branch', false) && !$this->runtime->inRollback()) {
|
if ($this->runtime->getEnvironmentConfig('branch', false) && !$this->runtime->inRollback()) {
|
||||||
|
@ -130,7 +130,7 @@ class DeployCommand extends AbstractCommand
|
||||||
$output->writeln(' No hosts defined, skipping On Deploy tasks');
|
$output->writeln(' No hosts defined, skipping On Deploy tasks');
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
} else {
|
} else {
|
||||||
$this->runtime->setStage(Runtime::ON_DEPLOY);
|
$this->runtime->setStage(RuntimeInterface::ON_DEPLOY);
|
||||||
$onDeployTasks = $this->runtime->getTasks();
|
$onDeployTasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
||||||
|
@ -164,7 +164,7 @@ class DeployCommand extends AbstractCommand
|
||||||
$output->writeln(' No hosts defined, skipping On Release tasks');
|
$output->writeln(' No hosts defined, skipping On Release tasks');
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
} else {
|
} else {
|
||||||
$this->runtime->setStage(Runtime::ON_RELEASE);
|
$this->runtime->setStage(RuntimeInterface::ON_RELEASE);
|
||||||
$onReleaseTasks = $this->runtime->getTasks();
|
$onReleaseTasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getEnvironmentConfig('releases', false)) {
|
if ($this->runtime->getEnvironmentConfig('releases', false)) {
|
||||||
|
@ -188,7 +188,7 @@ class DeployCommand extends AbstractCommand
|
||||||
$output->writeln(' No hosts defined, skipping Post Release tasks');
|
$output->writeln(' No hosts defined, skipping Post Release tasks');
|
||||||
$output->writeln('');
|
$output->writeln('');
|
||||||
} else {
|
} else {
|
||||||
$this->runtime->setStage(Runtime::POST_RELEASE);
|
$this->runtime->setStage(RuntimeInterface::POST_RELEASE);
|
||||||
$postReleaseTasks = $this->runtime->getTasks();
|
$postReleaseTasks = $this->runtime->getTasks();
|
||||||
|
|
||||||
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
||||||
|
@ -207,7 +207,7 @@ class DeployCommand extends AbstractCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run Post Deploy Tasks
|
// Run Post Deploy Tasks
|
||||||
$this->runtime->setStage(Runtime::POST_DEPLOY);
|
$this->runtime->setStage(RuntimeInterface::POST_DEPLOY);
|
||||||
$postDeployTasks = $this->runtime->getTasks();
|
$postDeployTasks = $this->runtime->getTasks();
|
||||||
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
||||||
if (!in_array('deploy/targz/cleanup', $postDeployTasks)) {
|
if (!in_array('deploy/targz/cleanup', $postDeployTasks)) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
namespace Mage;
|
namespace Mage;
|
||||||
|
|
||||||
use Mage\Command\AbstractCommand;
|
use Mage\Command\AbstractCommand;
|
||||||
|
use Mage\Runtime\Runtime;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
|
@ -28,8 +29,7 @@ use Mage\Runtime\Exception\RuntimeException;
|
||||||
*/
|
*/
|
||||||
class MageApplication extends Application
|
class MageApplication extends Application
|
||||||
{
|
{
|
||||||
private $configuration;
|
protected $runtime;
|
||||||
protected $logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure the Magallanes Application
|
* Configure the Magallanes Application
|
||||||
|
@ -46,14 +46,18 @@ class MageApplication extends Application
|
||||||
|
|
||||||
$config = Yaml::parse(file_get_contents($file));
|
$config = Yaml::parse(file_get_contents($file));
|
||||||
if (array_key_exists('magephp', $config)) {
|
if (array_key_exists('magephp', $config)) {
|
||||||
$this->configuration = $config['magephp'];
|
$config = $config['magephp'];
|
||||||
|
|
||||||
if (array_key_exists('log_dir', $this->configuration)) {
|
if (array_key_exists('log_dir', $config)) {
|
||||||
$logfile = sprintf('%s/%s.log', $this->configuration['log_dir'], date('Ymd_His'));
|
$logfile = sprintf('%s/%s.log', $config['log_dir'], date('Ymd_His'));
|
||||||
$this->configuration['log_file'] = $logfile;
|
$config['log_file'] = $logfile;
|
||||||
|
|
||||||
$this->logger = new Logger('magephp');
|
$logger = new Logger('magephp');
|
||||||
$this->logger->pushHandler(new StreamHandler($logfile));
|
$logger->pushHandler(new StreamHandler($logfile));
|
||||||
|
|
||||||
|
$this->runtime = new Runtime();
|
||||||
|
$this->runtime->setConfiguration($config);
|
||||||
|
$this->runtime->setLogger($logger);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $file));
|
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $file));
|
||||||
|
@ -89,8 +93,7 @@ class MageApplication extends Application
|
||||||
$command = new $class();
|
$command = new $class();
|
||||||
|
|
||||||
if ($command instanceof AbstractCommand) {
|
if ($command instanceof AbstractCommand) {
|
||||||
$command->setLogger($this->logger);
|
$command->setRuntime($this->runtime);
|
||||||
$command->setConfiguration($this->configuration);
|
|
||||||
$this->add($command);
|
$this->add($command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,8 @@ use Mage\Runtime\Exception\InvalidEnvironmentException;
|
||||||
*
|
*
|
||||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
*/
|
*/
|
||||||
class Runtime
|
class Runtime implements RuntimeInterface
|
||||||
{
|
{
|
||||||
const PRE_DEPLOY = 'pre-deploy';
|
|
||||||
const ON_DEPLOY = 'on-deploy';
|
|
||||||
const POST_DEPLOY = 'post-deploy';
|
|
||||||
const ON_RELEASE = 'on-release';
|
|
||||||
const POST_RELEASE = 'post-release';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Magallanes configuration
|
* @var array Magallanes configuration
|
||||||
*/
|
*/
|
||||||
|
@ -72,7 +66,7 @@ class Runtime
|
||||||
* Sets the Release ID
|
* Sets the Release ID
|
||||||
*
|
*
|
||||||
* @param string $releaseId Release ID
|
* @param string $releaseId Release ID
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setReleaseId($releaseId)
|
public function setReleaseId($releaseId)
|
||||||
{
|
{
|
||||||
|
@ -94,7 +88,7 @@ class Runtime
|
||||||
* Sets the Runtime in Rollback mode On or Off
|
* Sets the Runtime in Rollback mode On or Off
|
||||||
*
|
*
|
||||||
* @param bool $inRollback
|
* @param bool $inRollback
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setRollback($inRollback)
|
public function setRollback($inRollback)
|
||||||
{
|
{
|
||||||
|
@ -117,7 +111,7 @@ class Runtime
|
||||||
*
|
*
|
||||||
* @param mixed $key Variable name
|
* @param mixed $key Variable name
|
||||||
* @param mixed $value Variable value
|
* @param mixed $value Variable value
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setVar($key, $value)
|
public function setVar($key, $value)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +139,7 @@ class Runtime
|
||||||
* Sets the Logger instance
|
* Sets the Logger instance
|
||||||
*
|
*
|
||||||
* @param LoggerInterface $logger Logger instance
|
* @param LoggerInterface $logger Logger instance
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setLogger(LoggerInterface $logger = null)
|
public function setLogger(LoggerInterface $logger = null)
|
||||||
{
|
{
|
||||||
|
@ -157,7 +151,7 @@ class Runtime
|
||||||
* Sets the Magallanes Configuration to the Runtime
|
* Sets the Magallanes Configuration to the Runtime
|
||||||
*
|
*
|
||||||
* @param array $configuration Configuration
|
* @param array $configuration Configuration
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setConfiguration($configuration)
|
public function setConfiguration($configuration)
|
||||||
{
|
{
|
||||||
|
@ -223,7 +217,7 @@ class Runtime
|
||||||
* Sets the working Environment
|
* Sets the working Environment
|
||||||
*
|
*
|
||||||
* @param string $environment Environment name
|
* @param string $environment Environment name
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
* @throws InvalidEnvironmentException
|
* @throws InvalidEnvironmentException
|
||||||
*/
|
*/
|
||||||
public function setEnvironment($environment)
|
public function setEnvironment($environment)
|
||||||
|
@ -250,7 +244,7 @@ class Runtime
|
||||||
* Sets the working stage
|
* Sets the working stage
|
||||||
*
|
*
|
||||||
* @param string $stage Stage code
|
* @param string $stage Stage code
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setStage($stage)
|
public function setStage($stage)
|
||||||
{
|
{
|
||||||
|
@ -290,7 +284,7 @@ class Runtime
|
||||||
* Sets the working Host
|
* Sets the working Host
|
||||||
*
|
*
|
||||||
* @param string $host Host name
|
* @param string $host Host name
|
||||||
* @return Runtime
|
* @return RuntimeInterface
|
||||||
*/
|
*/
|
||||||
public function setWorkingHost($host)
|
public function setWorkingHost($host)
|
||||||
{
|
{
|
||||||
|
@ -331,9 +325,9 @@ class Runtime
|
||||||
public function runCommand($cmd, $timeout = 120)
|
public function runCommand($cmd, $timeout = 120)
|
||||||
{
|
{
|
||||||
switch ($this->getStage()) {
|
switch ($this->getStage()) {
|
||||||
case self::ON_DEPLOY:
|
case RuntimeInterface::ON_DEPLOY:
|
||||||
case self::ON_RELEASE:
|
case RuntimeInterface::ON_RELEASE:
|
||||||
case self::POST_RELEASE:
|
case RuntimeInterface::POST_RELEASE:
|
||||||
return $this->runRemoteCommand($cmd, true, $timeout);
|
return $this->runRemoteCommand($cmd, true, $timeout);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -396,6 +390,11 @@ class Runtime
|
||||||
return $this->runLocalCommand($cmdLocal, $timeout);
|
return $this->runLocalCommand($cmdLocal, $timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SSH configuration based on the environment
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function getSSHConfig()
|
public function getSSHConfig()
|
||||||
{
|
{
|
||||||
$sshConfig = $this->getEnvironmentConfig('ssh', ['port' => '22', 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
|
$sshConfig = $this->getEnvironmentConfig('ssh', ['port' => '22', 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
|
||||||
|
|
220
src/Mage/Runtime/RuntimeInterface.php
Normal file
220
src/Mage/Runtime/RuntimeInterface.php
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
<?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\Runtime;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\LogLevel;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
use Mage\Runtime\Exception\InvalidEnvironmentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the Runtime container
|
||||||
|
*
|
||||||
|
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||||
|
*/
|
||||||
|
interface RuntimeInterface
|
||||||
|
{
|
||||||
|
const PRE_DEPLOY = 'pre-deploy';
|
||||||
|
const ON_DEPLOY = 'on-deploy';
|
||||||
|
const POST_DEPLOY = 'post-deploy';
|
||||||
|
const ON_RELEASE = 'on-release';
|
||||||
|
const POST_RELEASE = 'post-release';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Release ID
|
||||||
|
*
|
||||||
|
* @param string $releaseId Release ID
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setReleaseId($releaseId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current Release ID
|
||||||
|
*
|
||||||
|
* @return null|string Release ID
|
||||||
|
*/
|
||||||
|
public function getReleaseId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Runtime in Rollback mode On or Off
|
||||||
|
*
|
||||||
|
* @param bool $inRollback
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setRollback($inRollback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if Runtime is in rollback
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function inRollback();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value in the Vars bag
|
||||||
|
*
|
||||||
|
* @param mixed $key Variable name
|
||||||
|
* @param mixed $value Variable value
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setVar($key, $value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a value from the Vars bag
|
||||||
|
*
|
||||||
|
* @param mixed $key Variable name
|
||||||
|
* @param mixed $default Variable default value, returned if not found
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getVar($key, $default = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Logger instance
|
||||||
|
*
|
||||||
|
* @param LoggerInterface $logger Logger instance
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setLogger(LoggerInterface $logger = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the Magallanes Configuration to the Runtime
|
||||||
|
*
|
||||||
|
* @param array $configuration Configuration
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setConfiguration($configuration);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the Configuration
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getConfiguration();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the Configuration options for a specific section in the configuration
|
||||||
|
*
|
||||||
|
* @param mixed $key Section name
|
||||||
|
* @param mixed $default Default value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getConfigOptions($key, $default = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the configuration for the current Environment
|
||||||
|
* If $key is provided, it will be returned only that section, if not found the default value will be returned,
|
||||||
|
* if $key is not provided, the whole Environment's configuration will be returned
|
||||||
|
*
|
||||||
|
* @param mixed $key Section name
|
||||||
|
* @param mixed $default Default value
|
||||||
|
* @return mixed
|
||||||
|
* @throws InvalidEnvironmentException
|
||||||
|
*/
|
||||||
|
public function getEnvironmentConfig($key = null, $default = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the working Environment
|
||||||
|
*
|
||||||
|
* @param string $environment Environment name
|
||||||
|
* @return RuntimeInterface
|
||||||
|
* @throws InvalidEnvironmentException
|
||||||
|
*/
|
||||||
|
public function setEnvironment($environment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current working Environment
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function getEnvironment();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the working stage
|
||||||
|
*
|
||||||
|
* @param string $stage Stage code
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setStage($stage);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the current wokring Stage
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the defined Tasks for the current Environment and Stage
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws InvalidEnvironmentException
|
||||||
|
*/
|
||||||
|
public function getTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the working Host
|
||||||
|
*
|
||||||
|
* @param string $host Host name
|
||||||
|
* @return RuntimeInterface
|
||||||
|
*/
|
||||||
|
public function setWorkingHost($host);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the working Host
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
public function getWorkingHost();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs a Message into the Logger
|
||||||
|
*
|
||||||
|
* @param string $message Log message
|
||||||
|
* @param string $level Log Level
|
||||||
|
*/
|
||||||
|
public function log($message, $level = LogLevel::DEBUG);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a command, it will be run Locally or Remotely based on the working Stage
|
||||||
|
*
|
||||||
|
* @param string $cmd Command to execute
|
||||||
|
* @param int $timeout Seconds to wait
|
||||||
|
* @return Process
|
||||||
|
*/
|
||||||
|
public function runCommand($cmd, $timeout = 120);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute a command locally
|
||||||
|
*
|
||||||
|
* @param string $cmd Command to execute
|
||||||
|
* @param int $timeout Seconds to wait
|
||||||
|
* @return Process
|
||||||
|
*/
|
||||||
|
public function runLocalCommand($cmd, $timeout = 120);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a command remotely, if jail is true, it will run inside the Host Path and the Release (if available)
|
||||||
|
*
|
||||||
|
* @param string $cmd Command to execute
|
||||||
|
* @param bool $jail Jail the command
|
||||||
|
* @param int $timeout Seconds to wait
|
||||||
|
* @return Process
|
||||||
|
* @throws InvalidEnvironmentException
|
||||||
|
*/
|
||||||
|
public function runRemoteCommand($cmd, $jail = true, $timeout = 120);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the SSH configuration based on the environment
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSSHConfig();
|
||||||
|
}
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace Mage\Task;
|
namespace Mage\Task;
|
||||||
|
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\RuntimeInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for Magallanes Tasks
|
* Abstract base class for Magallanes Tasks
|
||||||
|
@ -25,7 +25,7 @@ abstract class AbstractTask
|
||||||
protected $options = [];
|
protected $options = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Runtime
|
* @var RuntimeInterface
|
||||||
*/
|
*/
|
||||||
protected $runtime;
|
protected $runtime;
|
||||||
|
|
||||||
|
@ -68,10 +68,10 @@ abstract class AbstractTask
|
||||||
/**
|
/**
|
||||||
* Set the Runtime instance
|
* Set the Runtime instance
|
||||||
*
|
*
|
||||||
* @param Runtime $runtime
|
* @param RuntimeInterface $runtime
|
||||||
* @return AbstractTask
|
* @return AbstractTask
|
||||||
*/
|
*/
|
||||||
public function setRuntime(Runtime $runtime)
|
public function setRuntime(RuntimeInterface $runtime)
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
return $this;
|
return $this;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace Mage\Task;
|
namespace Mage\Task;
|
||||||
|
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\RuntimeInterface;
|
||||||
use Mage\Runtime\Exception\RuntimeException;
|
use Mage\Runtime\Exception\RuntimeException;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
use Symfony\Component\Finder\SplFileInfo;
|
use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
@ -23,7 +23,7 @@ use Symfony\Component\Finder\SplFileInfo;
|
||||||
class TaskFactory
|
class TaskFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Runtime
|
* @var RuntimeInterface
|
||||||
*/
|
*/
|
||||||
protected $runtime;
|
protected $runtime;
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ class TaskFactory
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param Runtime $runtime
|
* @param RuntimeInterface $runtime
|
||||||
*/
|
*/
|
||||||
public function __construct(Runtime $runtime)
|
public function __construct(RuntimeInterface $runtime)
|
||||||
{
|
{
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
$this->loadBuiltInTasks();
|
$this->loadBuiltInTasks();
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
namespace Mage;
|
namespace Mage;
|
||||||
|
|
||||||
use Mage\Runtime\Runtime;
|
use Mage\Runtime\RuntimeInterface;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,23 +29,23 @@ class Utils
|
||||||
public static function getStageName($stage)
|
public static function getStageName($stage)
|
||||||
{
|
{
|
||||||
switch ($stage) {
|
switch ($stage) {
|
||||||
case Runtime::PRE_DEPLOY:
|
case RuntimeInterface::PRE_DEPLOY:
|
||||||
return 'Pre Deployment';
|
return 'Pre Deployment';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Runtime::ON_DEPLOY:
|
case RuntimeInterface::ON_DEPLOY:
|
||||||
return 'On Deployment';
|
return 'On Deployment';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Runtime::POST_DEPLOY:
|
case RuntimeInterface::POST_DEPLOY:
|
||||||
return 'Post Deployment';
|
return 'Post Deployment';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Runtime::ON_RELEASE:
|
case RuntimeInterface::ON_RELEASE:
|
||||||
return 'On Release';
|
return 'On Release';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Runtime::POST_RELEASE:
|
case RuntimeInterface::POST_RELEASE:
|
||||||
return 'Post Release';
|
return 'Post Release';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue