diff --git a/src/Command/Build.php b/src/Command/Build.php index f979b19..c8bceec 100644 --- a/src/Command/Build.php +++ b/src/Command/Build.php @@ -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); } } diff --git a/src/Command/ComposerAuth.php b/src/Command/ComposerAuth.php index 6b5ea07..1dd5caf 100644 --- a/src/Command/ComposerAuth.php +++ b/src/Command/ComposerAuth.php @@ -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); } } diff --git a/src/Command/Deploy.php b/src/Command/Deploy.php index e816d47..9b6031f 100644 --- a/src/Command/Deploy.php +++ b/src/Command/Deploy.php @@ -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()); diff --git a/src/Command/RunTask.php b/src/Command/RunTask.php index e7e42d7..93a303d 100644 --- a/src/Command/RunTask.php +++ b/src/Command/RunTask.php @@ -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 */ @@ -27,8 +33,10 @@ 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'); } /** @@ -36,6 +44,12 @@ protected function configure() */ 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), + ); } } diff --git a/src/DeployRunner.php b/src/DeployRunner.php index c4f8c8e..7b8753b 100644 --- a/src/DeployRunner.php +++ b/src/DeployRunner.php @@ -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); @@ -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; @@ -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); @@ -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); } } }