Skip to content

Commit

Permalink
Merge pull request #53 from ByteInternet/run-task-server-build-config…
Browse files Browse the repository at this point in the history
…uration

feat: Allow `run-task` command to configure server / build stage
  • Loading branch information
Fgruntjes authored Sep 21, 2022
2 parents 7c74c30 + 658dfdb commit e64014e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Command/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->deployRunner->run($output, 'build', DeployRunner::TASK_BUILD);
return $this->deployRunner->run($output, 'build', DeployRunner::TASK_BUILD, true, false);
}
}
2 changes: 1 addition & 1 deletion src/Command/ComposerAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->deployRunner->run($output, 'build', 'deploy:vendors:auth');
return $this->deployRunner->run($output, 'build', 'deploy:vendors:auth', false, false);
}
}
2 changes: 1 addition & 1 deletion src/Command/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$result = $this->deployRunner->run($output, $input->getArgument('stage'), DeployRunner::TASK_DEPLOY);
$result = $this->deployRunner->run($output, $input->getArgument('stage'), DeployRunner::TASK_DEPLOY, false, true);

if ($result === 0) {
$this->reportWriter->write($this->deployRunner->getDeploymentReport());
Expand Down
20 changes: 17 additions & 3 deletions src/Command/RunTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

class RunTask extends Command
{
private const ARGUMENT_STAGE = 'stage';
private const ARGUMENT_TASK = 'task';
private const OPTION_CONFIGURE_BUILD_STAGE = 'configure-build-stage';
private const OPTION_CONFIGURE_SERVERS = 'configure-servers';

/**
* @var DeployRunner
*/
Expand All @@ -27,15 +33,23 @@ protected function configure()
parent::configure();
$this->setName('run-task');
$this->setDescription('Run a seperate deployer task');
$this->addArgument('stage', InputArgument::REQUIRED, 'Stage');
$this->addArgument('task', InputArgument::REQUIRED, 'Task to run');
$this->addArgument(self::ARGUMENT_STAGE, InputArgument::REQUIRED, 'Stage');
$this->addArgument(self::ARGUMENT_TASK, InputArgument::REQUIRED, 'Task to run');
$this->addOption(self::OPTION_CONFIGURE_BUILD_STAGE, 'b', InputOption::VALUE_NONE, 'Configure build stage before running task');
$this->addOption(self::OPTION_CONFIGURE_SERVERS, 's', InputOption::VALUE_NONE, 'Configure servers before running task');
}

/**
* @throws Throwable
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->deployRunner->run($output, $input->getArgument('stage'), $input->getArgument('task'));
return $this->deployRunner->run(
$output,
$input->getArgument(self::ARGUMENT_STAGE),
$input->getArgument(self::ARGUMENT_TASK),
$input->getOption(self::OPTION_CONFIGURE_BUILD_STAGE),
$input->getOption(self::OPTION_CONFIGURE_SERVERS),
);
}
}
29 changes: 15 additions & 14 deletions src/DeployRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(
* @throws Throwable
* @throws Exception
*/
public function run(OutputInterface $output, string $stage, string $task = self::TASK_DEPLOY): int
public function run(OutputInterface $output, string $stage, string $task, bool $configureBuildStage, bool $configureServers): int
{
$console = new Application();
$deployer = new Deployer($console);
Expand All @@ -87,7 +87,7 @@ public function run(OutputInterface $output, string $stage, string $task = self:
);

try {
$this->initializeDeployer($deployer, $task);
$this->initializeDeployer($deployer, $configureBuildStage, $configureServers);
} catch (InvalidConfigurationException $e) {
$output->write($e->getMessage());
return 1;
Expand All @@ -104,13 +104,20 @@ public function run(OutputInterface $output, string $stage, string $task = self:
* @throws Throwable
* @throws InvalidConfigurationException
*/
private function initializeDeployer(Deployer $deployer, string $task): void
private function initializeDeployer(Deployer $deployer, bool $configureBuildStage, bool $configureServers): void
{
$this->recipeLoader->load('common.php');
$tasks = $this->taskFactory->loadAll();
$config = $this->getConfiguration($deployer);
$config->setLogger($this->log);
$this->configureStages($config, $task);

if ($configureBuildStage) {
$this->initializeBuildStage($config);
}

if ($configureServers) {
$this->configureServers($config);
}

foreach ($tasks as $task) {
$task->configure($config);
Expand Down Expand Up @@ -180,17 +187,11 @@ private function getConfiguration(Deployer $deployer): Configuration
}
}

private function configureStages(Configuration $config, string $task): void
private function configureServers(Configuration $config): void
{
if ($task === self::TASK_BUILD) {
$this->initializeBuildStage($config);
}

if ($task === self::TASK_DEPLOY) {
foreach ($config->getStages() as $stage) {
foreach ($stage->getServers() as $server) {
$this->configureStageServer($stage, $server, $config);
}
foreach ($config->getStages() as $stage) {
foreach ($stage->getServers() as $server) {
$this->configureStageServer($stage, $server, $config);
}
}
}
Expand Down

0 comments on commit e64014e

Please sign in to comment.