Skip to content

Commit 3f17821

Browse files
authored
MCLOUD-7029: Refactor ProductionBuilder class (#3)
1 parent 2506a15 commit 3f17821

29 files changed

+2273
-535
lines changed

config/services.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,41 @@
1616
<argument key="production">Magento\CloudDocker\Compose\ProductionBuilder</argument>
1717
</argument>
1818
</service>
19+
<service id="Magento\CloudDocker\Compose\ProductionBuilder\ServicePool" autowire="false" />
20+
<service id="productionBuilderPool" class="Magento\CloudDocker\Compose\ProductionBuilder\ServicePool" lazy="true">
21+
<argument key="$services" type="collection">
22+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Database\Db" />
23+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Database\DbQuote" />
24+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Database\DbSales" />
25+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Redis" />
26+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\ElasticSearch" />
27+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Fpm" />
28+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Web" />
29+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Varnish" />
30+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Tls" />
31+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Selenium" />
32+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Test" />
33+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\FpmXdebug" />
34+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Generic" />
35+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Build" />
36+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Deploy" />
37+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\RabbitMq" />
38+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Node" />
39+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Mailhog" />
40+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Blackfire" />
41+
<argument type="service" id="Magento\CloudDocker\Compose\ProductionBuilder\Service\Cron" />
42+
</argument>
43+
</service>
44+
<service id="Magento\CloudDocker\Compose\ProductionBuilder" shared="false">
45+
<argument key="$servicePool" type="service" id="productionBuilderPool"/>
46+
</service>
1947
<service id="Magento\CloudDocker\Filesystem\DirectoryList" autowire="false"/>
2048
<service id="Magento\CloudDocker\Filesystem\FilesystemException" autowire="false"/>
2149
<service id="Magento\CloudDocker\Config\Source\SourceException" autowire="false"/>
2250
<service id="Magento\CloudDocker\Filesystem\FileNotFoundException" autowire="false"/>
2351
<service id="Magento\CloudDocker\App\ConfigurationMismatchException" autowire="false"/>
2452
<service id="Magento\CloudDocker\App\GenericException" autowire="false"/>
2553
<service id="Magento\CloudDocker\Compose\DeveloperBuilder" shared="false"/>
26-
<service id="Magento\CloudDocker\Compose\ProductionBuilder" shared="false"/>
2754
<service id="Magento\CloudDocker\Config\Config" autowire="false"/>
2855
<service id="Magento\CloudDocker\Config\Source\CliSource" autowire="false"/>
2956
<service id="Magento\CloudDocker\Config\Source\CustomSource" autowire="false"/>

src/Compose/BuilderInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface BuilderInterface
1515
{
1616
public const DIR_MAGENTO = '/app';
1717

18-
public const SERVICE_GENERIC = 'generic';
18+
public const SERVICE_GENERIC = ServiceInterface::SERVICE_GENERIC;
1919
public const SERVICE_DB = 'db';
2020
public const SERVICE_DB_QUOTE = 'db-quote';
2121
public const SERVICE_DB_SALES = 'db-sales';
@@ -24,17 +24,17 @@ interface BuilderInterface
2424
public const SERVICE_BUILD = 'build';
2525
public const SERVICE_DEPLOY = 'deploy';
2626
public const SERVICE_WEB = 'web';
27-
public const SERVICE_VARNISH = 'varnish';
28-
public const SERVICE_SELENIUM = 'selenium';
29-
public const SERVICE_TLS = 'tls';
27+
public const SERVICE_VARNISH = ServiceInterface::SERVICE_VARNISH;
28+
public const SERVICE_SELENIUM = ServiceInterface::SERVICE_SELENIUM;
29+
public const SERVICE_TLS = ServiceInterface::SERVICE_TLS;
3030
public const SERVICE_RABBITMQ = ServiceInterface::SERVICE_RABBITMQ;
3131
public const SERVICE_REDIS = ServiceInterface::SERVICE_REDIS;
3232
public const SERVICE_ELASTICSEARCH = ServiceInterface::SERVICE_ELASTICSEARCH;
33-
public const SERVICE_NODE = 'node';
33+
public const SERVICE_NODE = ServiceInterface::SERVICE_NODE;
3434
public const SERVICE_CRON = 'cron';
35-
public const SERVICE_TEST = 'test';
35+
public const SERVICE_TEST = ServiceInterface::SERVICE_TEST;
3636
public const SERVICE_HEALTHCHECK = 'healthcheck';
37-
public const SERVICE_MAILHOG = 'mailhog';
37+
public const SERVICE_MAILHOG = ServiceInterface::SERVICE_MAILHOG;
3838

3939
public const NETWORK_MAGENTO = 'magento';
4040
public const NETWORK_MAGENTO_BUILD = 'magento-build';

src/Compose/Manager.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\CloudDocker\Compose;
99

10+
use Magento\CloudDocker\App\ConfigurationMismatchException;
11+
use Magento\CloudDocker\Compose\ProductionBuilder\ServiceBuilderInterface;
1012
use Magento\CloudDocker\Config\Config;
1113

1214
/**
@@ -48,34 +50,32 @@ public function __construct(Config $config)
4850
}
4951

5052
/**
51-
* @param string $name
52-
* @param array $extConfig
53-
* @param array $networks
54-
* @param array $depends
53+
* @param ServiceBuilderInterface $service
54+
* @throws ConfigurationMismatchException
5555
*/
56-
public function addService(string $name, array $extConfig, array $networks, array $depends): void
56+
public function addService(ServiceBuilderInterface $service): void
5757
{
58-
$hostname = $name . '.' . $this->config->getHost();
58+
$hostname = $service->getName() . '.' . $this->config->getHost();
5959

60-
$config = [
60+
$serviceConfig = [
6161
'hostname' => $hostname,
6262
];
6363

64-
$config = array_replace($config, $extConfig);
64+
$serviceConfig = array_replace($serviceConfig, $service->getConfig($this->config));
6565

66-
foreach ($networks as $network) {
67-
if (!empty($config['networks'][$network]['aliases'])) {
66+
foreach ($service->getNetworks() as $network) {
67+
if (!empty($serviceConfig['networks'][$network]['aliases'])) {
6868
continue;
6969
}
7070

71-
$config['networks'][$network] = [
71+
$serviceConfig['networks'][$network] = [
7272
'aliases' => [$hostname]
7373
];
7474
}
7575

76-
$this->services[$name] = [
77-
'config' => $config,
78-
'depends_on' => $depends,
76+
$this->services[$service->getName()] = [
77+
'config' => $serviceConfig,
78+
'depends_on' => $service->getDependsOn($this->config),
7979
];
8080
}
8181

@@ -85,12 +85,6 @@ public function addService(string $name, array $extConfig, array $networks, arra
8585
*/
8686
public function updateService(string $name, array $extConfig): void
8787
{
88-
if (!isset($this->services[$name])) {
89-
$this->addService($name, $extConfig, [], []);
90-
91-
return;
92-
}
93-
9488
$this->services[$name]['config'] = array_replace(
9589
$this->services[$name]['config'],
9690
$extConfig

0 commit comments

Comments
 (0)