|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheAentMachine\AentDockerCompose\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
10
|
|
|
|
|
11
|
|
|
class NewDockerServiceInfoCommand extends Command |
|
12
|
|
|
{ |
|
13
|
|
|
protected function configure() |
|
14
|
|
|
{ |
|
15
|
|
|
$this |
|
16
|
|
|
->setName(Cst::NEW_DOCKER_SERVICE_INFO_EVENT) |
|
17
|
|
|
->setDescription('Add a docker service to the docker-compose.yml') |
|
18
|
|
|
->setHelp('TODO') |
|
19
|
|
|
->addArgument('payload', InputArgument::OPTIONAL, 'The payload of the event'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
23
|
|
|
{ |
|
24
|
|
|
$payload = $input->getArgument('payload'); |
|
25
|
|
|
$formattedPayload = Utils::parsePayload($payload, $output); |
|
26
|
|
|
|
|
27
|
|
|
$yml = Yaml::dump($formattedPayload, 256, 4, Yaml::DUMP_OBJECT_AS_MAP); |
|
28
|
|
|
file_put_contents(Cst::TMP_YML_PATH, $yml); |
|
29
|
|
|
|
|
30
|
|
|
$dockerComposePath = getenv('PHEROMONE_CONTAINER_PROJECT_DIR') . '/docker-compose.yml'; |
|
31
|
|
|
|
|
32
|
|
|
$yamlToolsCmd = array("yaml-tools", "merge", "-i", $dockerComposePath, Cst::TMP_YML_PATH, "-o", $dockerComposePath); |
|
33
|
|
|
$process = Utils::runAndGetProcess($yamlToolsCmd, $output); |
|
34
|
|
|
if (!$process->isSuccessful()) { |
|
35
|
|
|
exit($process->getExitCode()); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
unlink(Cst::TMP_YML_PATH); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.