Skip to content

Commit

Permalink
feat: add option to docker:create command to configure project
Browse files Browse the repository at this point in the history
  • Loading branch information
carlalexander committed Sep 6, 2021
1 parent 102b2dd commit 3e6a20f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/Command/Docker/CreateDockerfileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Filesystem\Filesystem;
use Ymir\Cli\ApiClient;
use Ymir\Cli\CliConfiguration;
Expand Down Expand Up @@ -73,7 +74,8 @@ protected function configure()
$this
->setName(self::NAME)
->setDescription('Create a new Dockerfile')
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to create the Dockerfile for');
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to create the Dockerfile for')
->addOption('configure-project', null, InputOption::VALUE_NONE, 'Configure project\'s ymir.yml file');
}

/**
Expand Down Expand Up @@ -108,5 +110,15 @@ protected function perform(InputInterface $input, ConsoleOutput $output)
}

$output->info($message);

if (!$this->getBooleanOption($input, 'configure-project') && !$output->confirm('Would you like to configure your project for container image deployment?')) {
return;
}

$options = [
'deployment' => 'image',
];

empty($environment) ? $this->projectConfiguration->addOptionsToEnvironments($options) : $this->projectConfiguration->addOptionsToEnvironment($environment, $options);
}
}
6 changes: 1 addition & 5 deletions src/Command/Project/InitializeProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,7 @@ protected function perform(InputInterface $input, ConsoleOutput $output)
}

if ($output->confirm('Will you deploy this project using a container image?', false)) {
$this->invoke($output, CreateDockerfileCommand::NAME);

$this->projectConfiguration->addOptionsToEnvironments([
'deployment' => 'image',
]);
$this->invoke($output, CreateDockerfileCommand::NAME, ['--configure-project']);
}
}, 'Do you want to try creating a project again?', $output);
}
Expand Down
12 changes: 10 additions & 2 deletions src/ProjectConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ public function addEnvironment(string $name, ?array $options = null)
$this->configuration['environments'][$name] = $options;
}

/**
* Add the given options to the given project environment.
*/
public function addOptionsToEnvironment(string $environment, array $options)
{
$this->configuration['environments'][$environment] = array_merge((array) $this->configuration['environments'][$environment], $options);
}

/**
* Add the given options to all project environments.
*/
public function addOptionsToEnvironments(array $options)
{
foreach ($this->configuration['environments'] as $name => $environment) {
$this->configuration['environments'][$name] = array_merge((array) $environment, $options);
foreach ($this->getEnvironments() as $environment) {
$this->addOptionsToEnvironment($environment, $options);
}
}

Expand Down

0 comments on commit 3e6a20f

Please sign in to comment.