Skip to content

Commit 7b2fc1b

Browse files
MAGECLOUD-2887-2841: Update RabbitMQ and EalsticSearch (#375)
1 parent 85ea231 commit 7b2fc1b

17 files changed

+263
-149
lines changed

src/Command/Docker/Build.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class Build extends Command
2727
const OPTION_PHP = 'php';
2828
const OPTION_NGINX = 'nginx';
2929
const OPTION_DB = 'db';
30+
const OPTION_ES = 'es';
31+
const OPTION_RABBIT_MQ = 'rmq';
32+
3033
const OPTION_IS_TEST = 'test';
3134

3235
/**
@@ -95,12 +98,26 @@ protected function configure()
9598
'DB version',
9699
BuilderInterface::DEFAULT_DB_VERSION
97100
)->addOption(
98-
self::OPTION_IS_TEST,
101+
self::OPTION_ES,
99102
null,
100-
InputOption::VALUE_NONE,
101-
'Generates ECE-Tools testing configuration (internal usage only)'
103+
InputOption::VALUE_OPTIONAL,
104+
'ElasticSearch version',
105+
BuilderInterface::DEFAULT_ES_VERSION
106+
)->addOption(
107+
self::OPTION_RABBIT_MQ,
108+
null,
109+
InputOption::VALUE_OPTIONAL,
110+
'RabbitMQ version',
111+
BuilderInterface::DEFAULT_RABBIT_MQ_VERSION
102112
);
103113

114+
$this->addOption(
115+
self::OPTION_IS_TEST,
116+
null,
117+
InputOption::VALUE_NONE,
118+
'Generates ECE-Tools testing configuration (internal usage only)'
119+
);
120+
104121
parent::configure();
105122
}
106123

@@ -134,6 +151,14 @@ public function execute(InputInterface $input, OutputInterface $output)
134151
$builder->setDbVersion($dbVersion);
135152
}
136153

154+
if ($esVersion = $input->getOption(self::OPTION_ES)) {
155+
$builder->setESVersion($esVersion);
156+
}
157+
158+
if ($rabbitMQVersion = $input->getOption(self::OPTION_RABBIT_MQ)) {
159+
$builder->setRabbitMQVersion($rabbitMQVersion);
160+
}
161+
137162
$config = Yaml::dump($builder->build(), 4, 2);
138163

139164
$this->file->filePutContents($path, $config);

src/Docker/BuilderInterface.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@
1010
*/
1111
interface BuilderInterface
1212
{
13+
const PHP_VERSIONS = ['7.0', '7.1', '7.2',];
1314
const DEFAULT_PHP_VERSION = '7.1';
14-
const PHP_VERSIONS = [
15-
'7.0',
16-
'7.1',
17-
'7.2',
18-
];
15+
16+
const ES_VERSIONS = ['1.7', '2.4', '5.2'];
17+
const DEFAULT_ES_VERSION = '2.4';
18+
19+
const RABBIT_MQ_VERSIONS = ['3.5', '3.7'];
20+
const DEFAULT_RABBIT_MQ_VERSION = '3.5';
1921

2022
const DEFAULT_NGINX_VERSION = 'latest';
2123
const DEFAULT_DB_VERSION = '10';
2224

2325
const PHP_VERSION = 'php.version';
2426
const NGINX_VERSION = 'nginx.version';
2527
const DB_VERSION = 'db.version';
28+
const ES_VERSION = 'es.version';
29+
const RABBIT_MQ_VERSION = 'rmq.version';
2630

2731
/**
2832
* @return array
@@ -46,4 +50,16 @@ public function setNginxVersion(string $version);
4650
* @throws ConfigurationMismatchException
4751
*/
4852
public function setDbVersion(string $version);
53+
54+
/**
55+
* @param string $version
56+
* @throws ConfigurationMismatchException
57+
*/
58+
public function setESVersion(string $version);
59+
60+
/**
61+
* @param string $version
62+
* @throws ConfigurationMismatchException
63+
*/
64+
public function setRabbitMQVersion(string $version);
4965
}

src/Docker/DevBuilder.php

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ public function setDbVersion(string $version)
6363
]);
6464
}
6565

66+
/**
67+
* @inheritdoc
68+
*/
69+
public function setESVersion(string $version)
70+
{
71+
$this->setVersion(self::ES_VERSION, $version, self::ES_VERSIONS);
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function setRabbitMQVersion(string $version)
78+
{
79+
$this->setVersion(self::RABBIT_MQ_VERSION, $version, self::RABBIT_MQ_VERSIONS);
80+
}
81+
6682
/**
6783
* @param string $key
6884
* @param string $version
@@ -95,8 +111,8 @@ public function build(): array
95111
'services' => [
96112
'varnish' => $this->serviceFactory->create(ServiceFactory::SERVICE_VARNISH)->get(),
97113
'redis' => $this->serviceFactory->create(ServiceFactory::SERVICE_REDIS)->get(),
98-
'elasticsearch' => $this->serviceFactory->create(ServiceFactory::SERVICE_ELASTICSEARCH)->get(),
99-
'rabbitmq' => $this->serviceFactory->create(ServiceFactory::SERVICE_RABBITMQ)->get(),
114+
'elasticsearch' => $this->getElasticSearchService(),
115+
'rabbitmq' => $this->getRabbitMQService(),
100116
'fpm' => $this->getFpmService(),
101117
/** For backward compatibility. */
102118
'cli' => $this->getCliService(false),
@@ -116,17 +132,34 @@ public function build(): array
116132
'/var/www/magento/app/etc',
117133
],
118134
],
119-
'dbdata' => [
120-
'image' => 'tianon/true',
121-
'volumes' => [
122-
'/var/lib/mysql',
123-
'./docker/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d',
124-
],
125-
],
126135
],
127136
];
128137
}
129138

139+
/**
140+
* @return array
141+
*/
142+
private function getElasticSearchService(): array
143+
{
144+
$version = $this->config->get(self::ES_VERSION, self::DEFAULT_ES_VERSION);
145+
146+
return [
147+
'image' => sprintf('%s:%s', 'magento/magento-cloud-docker-elasticsearch', $version),
148+
];
149+
}
150+
151+
/**
152+
* @return array
153+
*/
154+
private function getRabbitMQService(): array
155+
{
156+
$version = $this->config->get(self::RABBIT_MQ_VERSION, self::DEFAULT_RABBIT_MQ_VERSION);
157+
158+
return [
159+
'image' => sprintf('rabbitmq:%s', $version)
160+
];
161+
}
162+
130163
/**
131164
* @param bool $isReadOnly
132165
* @return string
@@ -153,7 +186,7 @@ private function getFpmService(): array
153186
'ports' => [
154187
9000,
155188
],
156-
'links' => [
189+
'depends_on' => [
157190
'db',
158191
],
159192
'volumes_from' => [
@@ -186,9 +219,10 @@ private function getCliService(bool $isReadOnly): array
186219
'magento/magento-cloud-docker-php:%s-cli',
187220
$this->config->get(self::PHP_VERSION, self::DEFAULT_PHP_VERSION)
188221
),
189-
'links' => [
222+
'depends_on' => [
190223
'db',
191224
'redis',
225+
'elasticsearch'
192226
],
193227
'volumes' => [
194228
$composeCacheDirectory . ':/root/.composer/cache',
@@ -217,8 +251,9 @@ private function getDbService(): array
217251
'ports' => [
218252
3306,
219253
],
220-
'volumes_from' => [
221-
'dbdata',
254+
'volumes' => [
255+
'/var/lib/mysql',
256+
'./docker/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d',
222257
],
223258
'environment' => [
224259
'MYSQL_ROOT_PASSWORD=magento2',
@@ -243,7 +278,7 @@ private function getWebService(): array
243278
'8080:80',
244279
'443:443',
245280
],
246-
'links' => [
281+
'depends_on' => [
247282
'fpm',
248283
'db',
249284
],

src/Docker/IntegrationBuilder.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,17 @@ public function setPhpVersion(string $version)
3737
/**
3838
* @inheritdoc
3939
*/
40-
public function setNginxVersion(string $version)
40+
public function setRabbitMQVersion(string $version)
4141
{
42-
$this->setVersion(self::NGINX_VERSION, $version, [
43-
'1.9',
44-
self::DEFAULT_NGINX_VERSION,
45-
]);
42+
$this->setVersion(self::RABBIT_MQ_VERSION, $version, self::RABBIT_MQ_VERSIONS);
43+
}
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
public function setESVersion(string $version)
49+
{
50+
$this->setVersion(self::ES_VERSION, $version, self::ES_VERSIONS);
4651
}
4752

4853
/**
@@ -55,6 +60,17 @@ public function setDbVersion(string $version)
5560
]);
5661
}
5762

63+
/**
64+
* @inheritdoc
65+
*/
66+
public function setNginxVersion(string $version)
67+
{
68+
$this->setVersion(self::NGINX_VERSION, $version, [
69+
'1.9',
70+
self::DEFAULT_NGINX_VERSION,
71+
]);
72+
}
73+
5874
/**
5975
* @param string $key
6076
* @param string $version
@@ -96,12 +112,6 @@ public function build(): array
96112
'/var/www/magento',
97113
],
98114
],
99-
'dbdata' => [
100-
'image' => 'tianon/true',
101-
'volumes' => [
102-
'/var/lib/mysql',
103-
],
104-
],
105115
],
106116
];
107117
}
@@ -171,8 +181,8 @@ private function getDbService(): array
171181
'ports' => [
172182
3306,
173183
],
174-
'volumes_from' => [
175-
'dbdata',
184+
'volumes' => [
185+
'/var/lib/mysql',
176186
],
177187
'environment' => [
178188
'MYSQL_ROOT_PASSWORD=magento2',

src/Docker/Service/ElasticSearchService.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Docker/Service/RabbitMqService.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Docker/Service/ServiceFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class ServiceFactory
1414
{
1515
const SERVICE_VARNISH = 'varnish';
1616
const SERVICE_REDIS = 'redis';
17-
const SERVICE_ELASTICSEARCH = 'elasticsearch';
1817
const SERVICE_RABBITMQ = 'rabbitmq';
1918

2019
/**
@@ -23,7 +22,6 @@ class ServiceFactory
2322
private static $map = [
2423
self::SERVICE_VARNISH => VarnishService::class,
2524
self::SERVICE_REDIS => RedisService::class,
26-
self::SERVICE_ELASTICSEARCH => ElasticSearchService::class,
2725
self::SERVICE_RABBITMQ => RabbitMqService::class,
2826
];
2927

src/Docker/Service/VarnishService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function get(): array
2525
'ports' => [
2626
'80:80',
2727
],
28-
'links' => [
28+
'depends_on' => [
2929
'web',
3030
],
3131
];

src/Filesystem/Driver/File.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public function deleteFile(string $path): bool
262262
*
263263
* @param string $path
264264
* @return bool
265+
* @codeCoverageIgnore
265266
*/
266267
public function deleteDirectory(string $path): bool
267268
{
@@ -284,6 +285,7 @@ public function deleteDirectory(string $path): bool
284285
*
285286
* @param string $path
286287
* @return bool
288+
* @codeCoverageIgnore
287289
*/
288290
public function clearDirectory(string $path): bool
289291
{
@@ -311,6 +313,7 @@ public function clearDirectory(string $path): bool
311313
* @param string $path Path to flush
312314
* @param array $excludes
313315
* @return void
316+
* @codeCoverageIgnore
314317
*/
315318
public function backgroundClearDirectory(string $path, array $excludes = [])
316319
{

src/Test/Unit/Command/Docker/BuildTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public function testExecuteWithParams()
139139
[Build::OPTION_PHP, '7.1'],
140140
[Build::OPTION_DB, '10'],
141141
[Build::OPTION_NGINX, '1.9'],
142+
[Build::OPTION_ES, '2.4'],
143+
[Build::OPTION_RABBIT_MQ, '3.5'],
142144
[Build::OPTION_IS_TEST, false],
143145
]);
144146
$this->builderMock->expects($this->once())
@@ -150,6 +152,12 @@ public function testExecuteWithParams()
150152
$this->builderMock->expects($this->once())
151153
->method('setDbVersion')
152154
->with('10');
155+
$this->builderMock->expects($this->once())
156+
->method('setESVersion')
157+
->with('2.4');
158+
$this->builderMock->expects($this->once())
159+
->method('setRabbitMQVersion')
160+
->with('3.5');
153161

154162
$this->command->execute($inputMock, $outputMock);
155163
}

0 commit comments

Comments
 (0)