Skip to content

Commit fde5777

Browse files
author
Yevhen Miroshnychenko
authored
MCLOUD-3059: [Spike] Investigate issue with elasticsearch image on AWS (#174)
1 parent 50af85a commit fde5777

File tree

10 files changed

+148
-11
lines changed

10 files changed

+148
-11
lines changed

images/elasticsearch/1.7/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ RUN plugin --install elasticsearch/elasticsearch-analysis-icu/2.7.0 && \
66

77
ADD docker-healthcheck.sh /docker-healthcheck.sh
88

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

1111
EXPOSE 9200 9300

images/elasticsearch/2.4/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
FROM elasticsearch:2.4
22

3+
RUN apt update -y && \
4+
apt install procps -y
5+
36
RUN echo "xpack.security.enabled: false" >> /usr/share/elasticsearch/config/elasticsearch.yml
47
RUN bin/plugin install analysis-icu && \
58
bin/plugin install analysis-phonetic
69

710
ADD docker-healthcheck.sh /docker-healthcheck.sh
811

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

1114
EXPOSE 9200 9300

images/elasticsearch/5.2/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ RUN bin/elasticsearch-plugin install analysis-icu && \
66

77
ADD docker-healthcheck.sh /docker-healthcheck.sh
88

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

1111
EXPOSE 9200 9300

images/elasticsearch/6.5/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ RUN bin/elasticsearch-plugin install analysis-icu && \
66

77
ADD docker-healthcheck.sh /docker-healthcheck.sh
88

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

1111
EXPOSE 9200 9300

images/elasticsearch/7.5/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ RUN bin/elasticsearch-plugin install -b analysis-icu && \
77

88
ADD docker-healthcheck.sh /docker-healthcheck.sh
99

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

1212
EXPOSE 9200 9300

src/Command/BuildCompose.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ protected function configure(): void
235235
null,
236236
InputOption::VALUE_OPTIONAL,
237237
'Port'
238+
)
239+
->addOption(
240+
Source\CliSource::OPTION_ES_ENVIRONMENT_VARIABLE,
241+
null,
242+
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
243+
'Environment variable for elasticsearch service'
238244
);
239245

240246
parent::configure();

src/Compose/ProductionBuilder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\CloudDocker\Compose\ProductionBuilder\VolumeResolver;
1414
use Magento\CloudDocker\Config\Config;
1515
use Magento\CloudDocker\Config\Environment\Converter;
16+
use Magento\CloudDocker\Config\Source\SourceInterface;
1617
use Magento\CloudDocker\Filesystem\FileList;
1718
use Magento\CloudDocker\Service\ServiceFactory;
1819
use Magento\CloudDocker\Service\ServiceInterface;
@@ -209,14 +210,22 @@ public function build(Config $config): Manager
209210
$this->addDbService(self::SERVICE_DB_SALES, $manager, $dbVersion, $volumesMount, $config);
210211
}
211212

213+
$esEnvVars = $config->get(SourceInterface::SERVICES_ES_VARS);
214+
212215
foreach (self::$standaloneServices as $service) {
213216
if (!$config->hasServiceEnabled($service)) {
214217
continue;
215218
}
216219

217220
$manager->addService(
218221
$service,
219-
$this->serviceFactory->create((string)$service, (string)$config->getServiceVersion($service)),
222+
$this->serviceFactory->create(
223+
(string)$service,
224+
(string)$config->getServiceVersion($service),
225+
self::SERVICE_ELASTICSEARCH === $service && !empty($esEnvVars)
226+
? ['environment' => $esEnvVars]
227+
: []
228+
),
220229
[self::NETWORK_MAGENTO],
221230
[]
222231
);

src/Config/Source/CliSource.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class CliSource implements SourceInterface
5555
public const OPTION_HOST = 'host';
5656
public const OPTION_PORT = 'port';
5757

58+
/**
59+
* Environment variable for elasticsearch service.
60+
*/
61+
public const OPTION_ES_ENVIRONMENT_VARIABLE = 'es-env-var';
62+
5863
/**
5964
* Option key to config name map
6065
*
@@ -110,12 +115,14 @@ public function read(): Repository
110115
]);
111116
}
112117

113-
foreach (self::$optionsMap as $option => $service) {
118+
foreach (self::$optionsMap as $option => $services) {
114119
if ($value = $this->input->getOption($option)) {
115-
$repository->set([
116-
$service . '.enabled' => true,
117-
$service . '.version' => $value
118-
]);
120+
foreach ($services as $service) {
121+
$repository->set([
122+
$service . '.enabled' => true,
123+
$service . '.version' => $value
124+
]);
125+
}
119126
}
120127
}
121128

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

195+
if ($esEnvVars = $this->input->getOption(self::OPTION_ES_ENVIRONMENT_VARIABLE)) {
196+
$repository->set(self::SERVICES_ES_VARS, $esEnvVars);
197+
}
198+
188199
return $repository;
189200
}
190201
}

src/Config/Source/SourceInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ interface SourceInterface
7474
*/
7575
public const SERVICES_ES = self::SERVICES . '.' . ServiceInterface::SERVICE_ELASTICSEARCH;
7676

77+
/**
78+
* ES environment variables
79+
*/
80+
public const SERVICES_ES_VARS = self::SERVICES_ES.'.'.'env-vars';
81+
7782
/**
7883
* Node
7984
*/
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CloudDocker\Test\Functional\Acceptance;
9+
10+
use CliTester;
11+
use Codeception\Example;
12+
use Robo\Exception\TaskException;
13+
14+
/**
15+
* @group php73
16+
*/
17+
class ElasticsearchCest extends AbstractAcceptanceCest
18+
{
19+
/**
20+
* Template version for testing
21+
*/
22+
protected const TEMPLATE_VERSION = '2.3.3';
23+
24+
/**
25+
* @param CliTester $I
26+
* @param Example $data
27+
* @dataProvider dataProvider
28+
* @return void
29+
* @throws TaskException
30+
*/
31+
public function testElasticsearch(CliTester $I, Example $data)
32+
{
33+
$command = sprintf(
34+
'build:compose --mode=production --es=%s --es-env-var=ES_JAVA_OPTS="-Xms%s -Xmx%s"',
35+
$data['version'],
36+
$data['xms'],
37+
$data['xmx']
38+
);
39+
40+
if (!empty($data['param'])) {
41+
$command .= " --es-env-var={$data['param']['key']}={$data['param']['value']}";
42+
}
43+
$I->runEceDockerCommand($command);
44+
$I->startEnvironment();
45+
$I->runDockerComposeCommand('exec -T elasticsearch ps aux | grep elasticsearch');
46+
$I->seeInOutput('-Xms' . $data['xms']);
47+
$I->seeInOutput('-Xmx' . $data['xmx']);
48+
49+
if (!empty($data['param'])) {
50+
$I->runDockerComposeCommand('exec -T elasticsearch curl http://localhost:9200/_nodes/settings');
51+
$I->seeInOutput($data['param']['needle']);
52+
}
53+
}
54+
55+
/**
56+
* @return array
57+
*/
58+
protected function dataProvider(): array
59+
{
60+
return [
61+
[
62+
'version' => '1.7',
63+
'xms' => '512m',
64+
'xmx' => '512m',
65+
],
66+
[
67+
'version' => '2.4',
68+
'xms' => '514m',
69+
'xmx' => '514m',
70+
],
71+
[
72+
'version' => '5.2',
73+
'xms' => '516m',
74+
'xmx' => '516m',
75+
'param' => [
76+
'key' => 'index.store.type',
77+
'value' => 'fs',
78+
'needle' => '"index":{"store":{"type":"fs"}}',
79+
]
80+
],
81+
[
82+
'version' => '6.5',
83+
'xms' => '518m',
84+
'xmx' => '518m',
85+
'param' => [
86+
'key' => 'node.store.allow_mmapfs',
87+
'value' => 'false',
88+
'needle' => '"store":{"allow_mmapfs":"false"}',
89+
]
90+
],
91+
[
92+
'version' => '7.5',
93+
'xms' => '520m',
94+
'xmx' => '520m',
95+
'param' => [
96+
'key' => 'node.store.allow_mmap',
97+
'value' => 'false',
98+
'needle' => '"store":{"allow_mmap":"false"}',
99+
]
100+
],
101+
];
102+
}
103+
}

0 commit comments

Comments
 (0)