Skip to content

Commit 26d1c92

Browse files
Merge pull request #247 from magento/small-refactoring
Improved Builder logic
2 parents 0ed588a + 6d28c78 commit 26d1c92

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

src/Compose/ProductionBuilder.php

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,37 +217,17 @@ public function build(Config $config): Manager
217217
$this->addDbService($manager, $config, self::SERVICE_DB_SALES, $dbVersion, $volumesMount);
218218
}
219219

220-
$esEnvVars = $config->get(SourceInterface::SERVICES_ES_VARS);
221-
222220
foreach (self::$standaloneServices as $service) {
223221
if (!$config->hasServiceEnabled($service)) {
224222
continue;
225223
}
226224

227-
switch ($service) {
228-
case self::SERVICE_REDIS:
229-
$serviceConfig = [self::SERVICE_HEALTHCHECK => [
230-
'test'=> 'redis-cli ping || exit 1',
231-
'interval'=> '30s',
232-
'timeout'=> '30s',
233-
'retries'=> 3
234-
]];
235-
break;
236-
237-
case self::SERVICE_ELASTICSEARCH:
238-
$serviceConfig = !empty($esEnvVars) ? ['environment' => $esEnvVars] : [];
239-
break;
240-
241-
default:
242-
$serviceConfig = [];
243-
}
244-
245225
$manager->addService(
246226
$service,
247227
$this->serviceFactory->create(
248228
(string)$service,
249229
(string)$config->getServiceVersion($service),
250-
$serviceConfig
230+
$this->getServiceConfig($service, $config)
251231
),
252232
[self::NETWORK_MAGENTO],
253233
[]
@@ -586,6 +566,36 @@ private function addDbService(
586566
);
587567
}
588568

569+
/**
570+
* @param string $service
571+
* @param Config $config
572+
* @return array
573+
* @throws ConfigurationMismatchException
574+
*/
575+
private function getServiceConfig(string $service, Config $config): array
576+
{
577+
switch ($service) {
578+
case self::SERVICE_REDIS:
579+
$serviceConfig = [self::SERVICE_HEALTHCHECK => [
580+
'test'=> 'redis-cli ping || exit 1',
581+
'interval'=> '30s',
582+
'timeout'=> '30s',
583+
'retries'=> 3
584+
]];
585+
break;
586+
587+
case self::SERVICE_ELASTICSEARCH:
588+
$esEnvVars = $config->get(SourceInterface::SERVICES_ES_VARS);
589+
$serviceConfig = !empty($esEnvVars) ? ['environment' => $esEnvVars] : [];
590+
break;
591+
592+
default:
593+
$serviceConfig = [];
594+
}
595+
596+
return $serviceConfig;
597+
}
598+
589599
/**
590600
* @param string $device
591601
* @return array

0 commit comments

Comments
 (0)