diff --git a/src/EventSubscriber/Platform/PlatformSubscriberDefaults.php b/src/EventSubscriber/Platform/PlatformSubscriberDefaults.php index c51f107..ab917f7 100644 --- a/src/EventSubscriber/Platform/PlatformSubscriberDefaults.php +++ b/src/EventSubscriber/Platform/PlatformSubscriberDefaults.php @@ -6,6 +6,7 @@ use EclipseGc\CommonConsole\Event\GetPlatformTypeEvent; use EclipseGc\CommonConsole\Event\GetPlatformTypesEvent; use EclipseGc\CommonConsole\Platform\DdevPlatform; +use EclipseGc\CommonConsole\Platform\DockerStackPlatform; use EclipseGc\CommonConsole\Platform\SshPlatform; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -20,6 +21,7 @@ public static function getSubscribedEvents() { public function onGetPlatformTypes(GetPlatformTypesEvent $event) { $event->addPlatformType(SshPlatform::getPlatformId()); $event->addPlatformType(DdevPlatform::getPlatformId()); + $event->addPlatformType(DockerStackPlatform::getPlatformId()); } public function onGetPlatformType(GetPlatformTypeEvent $event) { @@ -33,6 +35,11 @@ public function onGetPlatformType(GetPlatformTypeEvent $event) { $event->stopPropagation(); return; } + + if ($event->getPlatformType() === DockerStackPlatform::getPlatformId()) { + $event->addClass(DockerStackPlatform::class); + $event->stopPropagation(); + } } } diff --git a/src/Platform/DockerStackPlatform.php b/src/Platform/DockerStackPlatform.php new file mode 100644 index 0000000..41bb447 --- /dev/null +++ b/src/Platform/DockerStackPlatform.php @@ -0,0 +1,81 @@ + new Question("Docker Service Names (spearate them with colon): "), + static::CONFIG_COMPOSE_FILE_PATH => new Question("Location of docker-compose file: "), + ]; + } + + /** + * {@inheritdoc} + * + * This implementation relies on the hostname. Overwrite the method for + * custom site retrieving logic. + */ + public function getPlatformSites(): array { + $services = explode(',', $this->get(static::CONFIG_SERVICES)); + $location = $this->get(static::CONFIG_COMPOSE_FILE_PATH); + $sites = []; + foreach ($services as $service) { + $uriProcess = Process::fromShellCommandline("cd $location; docker-compose config | grep -A 11 $service | grep hostname | grep -v database | awk '{print $2}'"); + $uriProcess->run(); + $uri = trim($uriProcess->getOutput()); + $sites[trim($service)] = $uri; + } + + return $sites; + } + + /** + * {@inheritdoc} + */ + public function execute(Command $command, InputInterface $input, OutputInterface $output) : void { + $location = $this->get(static::CONFIG_COMPOSE_FILE_PATH); + $services = explode(',', $this->get(static::CONFIG_SERVICES)); + $sites = $this->getPlatformSites(); + foreach ($services as $service) { + $output->writeln("Executed on '$service'"); + $process = Process::fromShellCommandline("cd $location; docker-compose exec -T $service ./vendor/bin/commoncli --uri {$sites[$service]} {$input->__toString()}"); + $this->runner->run($process, $this, $output); + } + } + +}