Skip to content

Commit 3e6a20f

Browse files
committed
feat: add option to docker:create command to configure project
1 parent 102b2dd commit 3e6a20f

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/Command/Docker/CreateDockerfileCommand.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Exception\RuntimeException;
1717
use Symfony\Component\Console\Input\InputArgument;
1818
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Input\InputOption;
1920
use Symfony\Component\Filesystem\Filesystem;
2021
use Ymir\Cli\ApiClient;
2122
use Ymir\Cli\CliConfiguration;
@@ -73,7 +74,8 @@ protected function configure()
7374
$this
7475
->setName(self::NAME)
7576
->setDescription('Create a new Dockerfile')
76-
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to create the Dockerfile for');
77+
->addArgument('environment', InputArgument::OPTIONAL, 'The name of the environment to create the Dockerfile for')
78+
->addOption('configure-project', null, InputOption::VALUE_NONE, 'Configure project\'s ymir.yml file');
7779
}
7880

7981
/**
@@ -108,5 +110,15 @@ protected function perform(InputInterface $input, ConsoleOutput $output)
108110
}
109111

110112
$output->info($message);
113+
114+
if (!$this->getBooleanOption($input, 'configure-project') && !$output->confirm('Would you like to configure your project for container image deployment?')) {
115+
return;
116+
}
117+
118+
$options = [
119+
'deployment' => 'image',
120+
];
121+
122+
empty($environment) ? $this->projectConfiguration->addOptionsToEnvironments($options) : $this->projectConfiguration->addOptionsToEnvironment($environment, $options);
111123
}
112124
}

src/Command/Project/InitializeProjectCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ protected function perform(InputInterface $input, ConsoleOutput $output)
144144
}
145145

146146
if ($output->confirm('Will you deploy this project using a container image?', false)) {
147-
$this->invoke($output, CreateDockerfileCommand::NAME);
148-
149-
$this->projectConfiguration->addOptionsToEnvironments([
150-
'deployment' => 'image',
151-
]);
147+
$this->invoke($output, CreateDockerfileCommand::NAME, ['--configure-project']);
152148
}
153149
}, 'Do you want to try creating a project again?', $output);
154150
}

src/ProjectConfiguration.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,21 @@ public function addEnvironment(string $name, ?array $options = null)
7676
$this->configuration['environments'][$name] = $options;
7777
}
7878

79+
/**
80+
* Add the given options to the given project environment.
81+
*/
82+
public function addOptionsToEnvironment(string $environment, array $options)
83+
{
84+
$this->configuration['environments'][$environment] = array_merge((array) $this->configuration['environments'][$environment], $options);
85+
}
86+
7987
/**
8088
* Add the given options to all project environments.
8189
*/
8290
public function addOptionsToEnvironments(array $options)
8391
{
84-
foreach ($this->configuration['environments'] as $name => $environment) {
85-
$this->configuration['environments'][$name] = array_merge((array) $environment, $options);
92+
foreach ($this->getEnvironments() as $environment) {
93+
$this->addOptionsToEnvironment($environment, $options);
8694
}
8795
}
8896

0 commit comments

Comments
 (0)