Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion images/elasticsearch/1.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RUN plugin --install elasticsearch/elasticsearch-analysis-icu/2.7.0 && \

ADD docker-healthcheck.sh /docker-healthcheck.sh

HEALTHCHECK --retries=3 CMD ["sh", "/docker-healthcheck.sh"]
HEALTHCHECK --retries=3 CMD ["bash", "/docker-healthcheck.sh"]

EXPOSE 9200 9300
5 changes: 4 additions & 1 deletion images/elasticsearch/2.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM elasticsearch:2.4

RUN apt update -y && \
apt install procps -y

RUN echo "xpack.security.enabled: false" >> /usr/share/elasticsearch/config/elasticsearch.yml
RUN bin/plugin install analysis-icu && \
bin/plugin install analysis-phonetic

ADD docker-healthcheck.sh /docker-healthcheck.sh

HEALTHCHECK --retries=3 CMD ["sh", "/docker-healthcheck.sh"]
HEALTHCHECK --retries=3 CMD ["bash", "/docker-healthcheck.sh"]

EXPOSE 9200 9300
2 changes: 1 addition & 1 deletion images/elasticsearch/5.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RUN bin/elasticsearch-plugin install analysis-icu && \

ADD docker-healthcheck.sh /docker-healthcheck.sh

HEALTHCHECK --retries=3 CMD ["sh", "/docker-healthcheck.sh"]
HEALTHCHECK --retries=3 CMD ["bash", "/docker-healthcheck.sh"]

EXPOSE 9200 9300
2 changes: 1 addition & 1 deletion images/elasticsearch/6.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RUN bin/elasticsearch-plugin install analysis-icu && \

ADD docker-healthcheck.sh /docker-healthcheck.sh

HEALTHCHECK --retries=3 CMD ["sh", "/docker-healthcheck.sh"]
HEALTHCHECK --retries=3 CMD ["bash", "/docker-healthcheck.sh"]

EXPOSE 9200 9300
2 changes: 1 addition & 1 deletion images/elasticsearch/7.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ RUN bin/elasticsearch-plugin install -b analysis-icu && \

ADD docker-healthcheck.sh /docker-healthcheck.sh

HEALTHCHECK --retries=3 CMD ["sh", "/docker-healthcheck.sh"]
HEALTHCHECK --retries=3 CMD ["bash", "/docker-healthcheck.sh"]

EXPOSE 9200 9300
6 changes: 6 additions & 0 deletions src/Command/BuildCompose.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ protected function configure(): void
null,
InputOption::VALUE_OPTIONAL,
'Port'
)
->addOption(
Source\CliSource::OPTION_ES_ENVIRONMENT_VARIABLE,
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Environment variable for elasticsearch service'
);

parent::configure();
Expand Down
11 changes: 10 additions & 1 deletion src/Compose/ProductionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\CloudDocker\Compose\ProductionBuilder\VolumeResolver;
use Magento\CloudDocker\Config\Config;
use Magento\CloudDocker\Config\Environment\Converter;
use Magento\CloudDocker\Config\Source\SourceInterface;
use Magento\CloudDocker\Filesystem\FileList;
use Magento\CloudDocker\Service\ServiceFactory;
use Magento\CloudDocker\Service\ServiceInterface;
Expand Down Expand Up @@ -207,14 +208,22 @@ public function build(Config $config): Manager
$this->addDbService(self::SERVICE_DB_SALES, $manager, $dbVersion, $volumesMount, $config);
}

$esEnvVars = $config->get(SourceInterface::SERVICES_ES_VARS);

foreach (self::$standaloneServices as $service) {
if (!$config->hasServiceEnabled($service)) {
continue;
}

$manager->addService(
$service,
$this->serviceFactory->create((string)$service, (string)$config->getServiceVersion($service)),
$this->serviceFactory->create(
(string)$service,
(string)$config->getServiceVersion($service),
self::SERVICE_ELASTICSEARCH === $service && !empty($esEnvVars)
? ['environment' => $esEnvVars]
: []
),
[self::NETWORK_MAGENTO],
[]
);
Expand Down
21 changes: 16 additions & 5 deletions src/Config/Source/CliSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class CliSource implements SourceInterface
public const OPTION_HOST = 'host';
public const OPTION_PORT = 'port';

/**
* Environment variable for elasticsearch service.
*/
public const OPTION_ES_ENVIRONMENT_VARIABLE = 'es-env-var';

/**
* Option key to config name map
*
Expand Down Expand Up @@ -110,12 +115,14 @@ public function read(): Repository
]);
}

foreach (self::$optionsMap as $option => $service) {
foreach (self::$optionsMap as $option => $services) {
if ($value = $this->input->getOption($option)) {
$repository->set([
$service . '.enabled' => true,
$service . '.version' => $value
]);
foreach ($services as $service) {
$repository->set([
$service . '.enabled' => true,
$service . '.version' => $value
]);
}
}
}

Expand Down Expand Up @@ -185,6 +192,10 @@ public function read(): Repository
$repository->set(self::SYSTEM_EXPOSE_DB_SALES_PORTS, $port);
}

if ($esEnvVars = $this->input->getOption(self::OPTION_ES_ENVIRONMENT_VARIABLE)) {
$repository->set(self::SERVICES_ES_VARS, $esEnvVars);
}

return $repository;
}
}
5 changes: 5 additions & 0 deletions src/Config/Source/SourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ interface SourceInterface
*/
public const SERVICES_ES = self::SERVICES . '.' . ServiceInterface::SERVICE_ELASTICSEARCH;

/**
* ES environment variables
*/
public const SERVICES_ES_VARS = self::SERVICES_ES.'.'.'env-vars';

/**
* Node
*/
Expand Down
103 changes: 103 additions & 0 deletions src/Test/Functional/Acceptance/ElasticsearchCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CloudDocker\Test\Functional\Acceptance;

use CliTester;
use Codeception\Example;
use Robo\Exception\TaskException;

/**
* @group php73
*/
class ElasticsearchCest extends AbstractAcceptanceCest
{
/**
* Template version for testing
*/
protected const TEMPLATE_VERSION = '2.3.3';

/**
* @param CliTester $I
* @param Example $data
* @dataProvider dataProvider
* @return void
* @throws TaskException
*/
public function testElasticsearch(CliTester $I, Example $data)
{
$command = sprintf(
'build:compose --mode=production --es=%s --es-env-var=ES_JAVA_OPTS="-Xms%s -Xmx%s"',
$data['version'],
$data['xms'],
$data['xmx']
);

if (!empty($data['param'])) {
$command .= " --es-env-var={$data['param']['key']}={$data['param']['value']}";
}
$I->runEceDockerCommand($command);
$I->startEnvironment();
$I->runDockerComposeCommand('exec -T elasticsearch ps aux | grep elasticsearch');
$I->seeInOutput('-Xms' . $data['xms']);
$I->seeInOutput('-Xmx' . $data['xmx']);

if (!empty($data['param'])) {
$I->runDockerComposeCommand('exec -T elasticsearch curl http://localhost:9200/_nodes/settings');
$I->seeInOutput($data['param']['needle']);
}
}

/**
* @return array
*/
protected function dataProvider(): array
{
return [
[
'version' => '1.7',
'xms' => '512m',
'xmx' => '512m',
],
[
'version' => '2.4',
'xms' => '514m',
'xmx' => '514m',
],
[
'version' => '5.2',
'xms' => '516m',
'xmx' => '516m',
'param' => [
'key' => 'index.store.type',
'value' => 'fs',
'needle' => '"index":{"store":{"type":"fs"}}',
]
],
[
'version' => '6.5',
'xms' => '518m',
'xmx' => '518m',
'param' => [
'key' => 'node.store.allow_mmapfs',
'value' => 'false',
'needle' => '"store":{"allow_mmapfs":"false"}',
]
],
[
'version' => '7.5',
'xms' => '520m',
'xmx' => '520m',
'param' => [
'key' => 'node.store.allow_mmap',
'value' => 'false',
'needle' => '"store":{"allow_mmap":"false"}',
]
],
];
}
}