diff --git a/dist/docker-arch.phar b/dist/docker-arch.phar index 8a1129c..9d6e728 100755 Binary files a/dist/docker-arch.phar and b/dist/docker-arch.phar differ diff --git a/src/Application/DockerContainer/CerebroDockerContainer.php b/src/Application/DockerContainer/CerebroDockerContainer.php index ff9bc2f..39b78ac 100644 --- a/src/Application/DockerContainer/CerebroDockerContainer.php +++ b/src/Application/DockerContainer/CerebroDockerContainer.php @@ -8,7 +8,6 @@ /** * @author Cédric Dugat - * @see https://hub.docker.com/r/yannart/cerebro */ class CerebroDockerContainer extends DockerContainer { @@ -56,7 +55,7 @@ public function init(): void ->setEntryPoint(['/usr/share/cerebro/bin/cerebro']); // Ports. - $port = $this->addEnvPort('CEREBRO', ['from' => '8021', 'to' => '9000']); + $port = $this->addEnvPort('ELASTIC_SEARCH_CEREBRO', ['from' => '8021', 'to' => '9000']); // UI. $service->getParentService()->addUIAccess([ diff --git a/src/Application/DockerContainer/ElasticsearchDockerContainer.php b/src/Application/DockerContainer/ElasticsearchDockerContainer.php index 352d512..228a366 100644 --- a/src/Application/DockerContainer/ElasticsearchDockerContainer.php +++ b/src/Application/DockerContainer/ElasticsearchDockerContainer.php @@ -3,6 +3,7 @@ namespace Ph3\DockerArch\Application\DockerContainer; use Ph3\DockerArch\Application\Service\CerebroService; +use Ph3\DockerArch\Application\Service\ElasticsearchHeadService; use Ph3\DockerArch\Domain\DockerContainer\Model\DockerContainer; use Ph3\DockerArch\Domain\DockerContainer\Model\DockerContainerInterface; @@ -27,8 +28,13 @@ public function init(): void // Commands. if (true === $service->getOptions()['with_management']) { - $cerebroService = CerebroService::getInstanceForParentService($this->getService()); - $project->addService($cerebroService); + $this + ->addCommand('echo "http.cors.enabled: true" >> /usr/share/elasticsearch/config/elasticsearch.yml') + ->addCommand('echo "http.cors.allow-origin: \\"*\\"" >> /usr/share/elasticsearch/config/elasticsearch.yml'); + + $project + ->addService(CerebroService::getInstanceForParentService($this->getService())) + ->addService(ElasticsearchHeadService::getInstanceForParentService($this->getService())); } // Ports. diff --git a/src/Application/DockerContainer/ElasticsearchHeadDockerContainer.php b/src/Application/DockerContainer/ElasticsearchHeadDockerContainer.php new file mode 100644 index 0000000..51eac83 --- /dev/null +++ b/src/Application/DockerContainer/ElasticsearchHeadDockerContainer.php @@ -0,0 +1,40 @@ + + */ +class ElasticsearchHeadDockerContainer extends DockerContainer +{ + /** + * {@inheritdoc} + */ + public function init(): void + { + $this->setPackageManager(DockerContainerInterface::PACKAGE_MANAGER_TYPE_APK); + + parent::init(); + + $service = $this->getService(); + + $this->setFrom('mobz/elasticsearch-head:5-alpine'); + + // Ports. + $port = $this->addEnvPort('ELASTIC_SEARCH_HEAD', ['from' => '8022', 'to' => '9100']); + + // UI. + $elasticSearchPorts = $service->getParentService()->getDockerContainer()->getPorts(); + $elasticSearchPort = reset($elasticSearchPorts)['from']; + $service->getParentService()->addUIAccess([ + 'url' => 'localhost', + 'uri' => '?base_uri=http://localhost:'.$elasticSearchPort.'/', + 'port' => $port['from'], + 'label' => 'Mobz Head', + ]); + } +} diff --git a/src/Application/Service/CerebroService.php b/src/Application/Service/CerebroService.php index 2de4a18..bbe107b 100644 --- a/src/Application/Service/CerebroService.php +++ b/src/Application/Service/CerebroService.php @@ -21,14 +21,4 @@ public function getOptionsResolver(): Options { return new OptionsResolver(); } - - /** - * {@inheritdoc} - */ - public static function getInstanceForParentService(ServiceInterface $service): ServiceInterface - { - $instance = parent::getInstanceForParentService($service); - - return $instance; - } } diff --git a/src/Application/Service/ElasticsearchHeadService.php b/src/Application/Service/ElasticsearchHeadService.php new file mode 100644 index 0000000..5173cd4 --- /dev/null +++ b/src/Application/Service/ElasticsearchHeadService.php @@ -0,0 +1,24 @@ + + */ +class ElasticsearchHeadService extends AbstractService implements HasParentServiceInterface +{ + use ParentServiceTrait; + + /** + * {@inheritdoc} + */ + public function getOptionsResolver(): Options + { + return new OptionsResolver(); + } +} diff --git a/src/Domain/Service/Model/AbstractService.php b/src/Domain/Service/Model/AbstractService.php index 6bce14e..5efe510 100644 --- a/src/Domain/Service/Model/AbstractService.php +++ b/src/Domain/Service/Model/AbstractService.php @@ -295,7 +295,7 @@ public function getUIAccesses(): array /** * {@inheritdoc} */ - protected static function getInstanceForParentService(ServiceInterface $service): ServiceInterface + public static function getInstanceForParentService(ServiceInterface $service): ServiceInterface { $instance = new static( $service->getProject() @@ -306,14 +306,13 @@ protected static function getInstanceForParentService(ServiceInterface $service) } $dockerContainer = new $dockerContainerFqcn($instance); + $identifier = sprintf('%s-%s', $instance->getName(), $service->getIdentifier()); + $identifier = (new Slugify())->slugify($identifier, '-'); + $instance ->setParentService($service) ->setDockerContainer($dockerContainer) - ->setIdentifier(sprintf( - '%s-%s', - $instance->getName(), - $service->getIdentifier() - )); + ->setIdentifier($identifier); return $instance; }