mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-09-08 14:28:57 +02:00
Refactor Runtime to allow custom implementation
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Mage\Command;
|
||||
|
||||
use Mage\Runtime\Runtime;
|
||||
use Mage\Runtime\RuntimeInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -23,55 +23,31 @@ use Symfony\Component\Console\Command\Command;
|
||||
abstract class AbstractCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var Runtime Current Runtime instance
|
||||
* @var RuntimeInterface Current Runtime instance
|
||||
*/
|
||||
protected $runtime;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface|null The instance of the logger, it's optional
|
||||
*/
|
||||
private $logger = null;
|
||||
|
||||
/**
|
||||
* Configure the Command and create the Runtime configuration
|
||||
* Set the Runtime configuration
|
||||
*
|
||||
* @param array $configuration Magallanes configuration
|
||||
* @param RuntimeInterface $runtime Runtime container
|
||||
* @return AbstractCommand
|
||||
*/
|
||||
public function setConfiguration($configuration)
|
||||
public function setRuntime(RuntimeInterface $runtime)
|
||||
{
|
||||
$this->runtime = new Runtime();
|
||||
$this->runtime->setConfiguration($configuration);
|
||||
$this->runtime->setLogger($this->logger);
|
||||
$this->runtime = $runtime;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the logger
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
* @return AbstractCommand
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger = null)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message, if logger is valid instance
|
||||
* Logs a message
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $level
|
||||
* @return AbstractCommand
|
||||
*/
|
||||
public function log($message, $level = LogLevel::DEBUG)
|
||||
{
|
||||
if ($this->logger instanceof LoggerInterface) {
|
||||
$this->logger->log($level, $message);
|
||||
}
|
||||
|
||||
return $this;
|
||||
$this->runtime->log($message, $level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Mage\Command\BuiltIn;
|
||||
use Mage\Runtime\Exception\DeploymentException;
|
||||
use Mage\Runtime\Exception\InvalidEnvironmentException;
|
||||
use Mage\Runtime\Exception\RuntimeException;
|
||||
use Mage\Runtime\Runtime;
|
||||
use Mage\Runtime\RuntimeInterface;
|
||||
use Mage\Task\ErrorException;
|
||||
use Mage\Task\ExecuteOnRollbackInterface;
|
||||
use Mage\Task\AbstractTask;
|
||||
@@ -105,7 +105,7 @@ class DeployCommand extends AbstractCommand
|
||||
protected function runDeployment(OutputInterface $output)
|
||||
{
|
||||
// Run Pre Deploy Tasks
|
||||
$this->runtime->setStage(Runtime::PRE_DEPLOY);
|
||||
$this->runtime->setStage(RuntimeInterface::PRE_DEPLOY);
|
||||
$preDeployTasks = $this->runtime->getTasks();
|
||||
|
||||
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('');
|
||||
} else {
|
||||
$this->runtime->setStage(Runtime::ON_DEPLOY);
|
||||
$this->runtime->setStage(RuntimeInterface::ON_DEPLOY);
|
||||
$onDeployTasks = $this->runtime->getTasks();
|
||||
|
||||
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('');
|
||||
} else {
|
||||
$this->runtime->setStage(Runtime::ON_RELEASE);
|
||||
$this->runtime->setStage(RuntimeInterface::ON_RELEASE);
|
||||
$onReleaseTasks = $this->runtime->getTasks();
|
||||
|
||||
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('');
|
||||
} else {
|
||||
$this->runtime->setStage(Runtime::POST_RELEASE);
|
||||
$this->runtime->setStage(RuntimeInterface::POST_RELEASE);
|
||||
$postReleaseTasks = $this->runtime->getTasks();
|
||||
|
||||
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
||||
@@ -207,7 +207,7 @@ class DeployCommand extends AbstractCommand
|
||||
}
|
||||
|
||||
// Run Post Deploy Tasks
|
||||
$this->runtime->setStage(Runtime::POST_DEPLOY);
|
||||
$this->runtime->setStage(RuntimeInterface::POST_DEPLOY);
|
||||
$postDeployTasks = $this->runtime->getTasks();
|
||||
if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) {
|
||||
if (!in_array('deploy/targz/cleanup', $postDeployTasks)) {
|
||||
|
||||
Reference in New Issue
Block a user