Skip to content

Commit

Permalink
Merge pull request #15 from Ph3nol/es-head
Browse files Browse the repository at this point in the history
Mobz Elasticsearch Head tool added
  • Loading branch information
Ph3nol authored Sep 20, 2017
2 parents 1dfcb2d + 69165b7 commit 05dc2e2
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 20 deletions.
Binary file modified dist/docker-arch.phar
Binary file not shown.
3 changes: 1 addition & 2 deletions src/Application/DockerContainer/CerebroDockerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* @author Cédric Dugat <[email protected]>
* @see https://hub.docker.com/r/yannart/cerebro
*/
class CerebroDockerContainer extends DockerContainer
{
Expand Down Expand Up @@ -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([
Expand Down
10 changes: 8 additions & 2 deletions src/Application/DockerContainer/ElasticsearchDockerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Ph3\DockerArch\Application\DockerContainer;

use Ph3\DockerArch\Domain\DockerContainer\Model\DockerContainer;
use Ph3\DockerArch\Domain\DockerContainer\Model\DockerContainerInterface;
use Ph3\DockerArch\Domain\TemplatedFile\Model\TemplatedFile;

/**
* @author Cédric Dugat <[email protected]>
*/
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',
]);
}
}
10 changes: 0 additions & 10 deletions src/Application/Service/CerebroService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
24 changes: 24 additions & 0 deletions src/Application/Service/ElasticsearchHeadService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Ph3\DockerArch\Application\Service;

use Ph3\DockerArch\Domain\Service\Model\AbstractService;
use Ph3\DockerArch\Domain\Service\Model\ServiceInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Cédric Dugat <[email protected]>
*/
class ElasticsearchHeadService extends AbstractService implements HasParentServiceInterface
{
use ParentServiceTrait;

/**
* {@inheritdoc}
*/
public function getOptionsResolver(): Options
{
return new OptionsResolver();
}
}
11 changes: 5 additions & 6 deletions src/Domain/Service/Model/AbstractService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}
Expand Down

0 comments on commit 05dc2e2

Please sign in to comment.