Skip to content

Commit ba49061

Browse files
MCLOUD-5691: Add support for MySQL #189 (#206)
1 parent 7df89c1 commit ba49061

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

src/Command/BuildCompose.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ protected function configure(): void
102102
InputOption::VALUE_REQUIRED,
103103
'DB version'
104104
)->addOption(
105+
Source\CliSource::OPTION_DB_IMAGE,
106+
null,
107+
InputOption::VALUE_REQUIRED,
108+
'DB image'
109+
)
110+
->addOption(
105111
Source\CliSource::OPTION_EXPOSE_DB_PORT,
106112
null,
107113
InputOption::VALUE_REQUIRED,

src/Compose/ProductionBuilder.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,16 @@ public function build(Config $config): Manager
205205
$this->getVolumeConfig('/.docker/mysql/mariadb.conf.d')
206206
);
207207

208-
$this->addDbService(self::SERVICE_DB, $manager, $dbVersion, $volumesMount, $config);
208+
$this->addDbService($manager, $config, self::SERVICE_DB, $dbVersion, $volumesMount);
209209

210210
if ($config->hasServiceEnabled(ServiceInterface::SERVICE_DB_QUOTE)) {
211211
$cliDepends = array_merge($cliDepends, [self::SERVICE_DB_QUOTE => ['condition' => 'service_started']]);
212-
$this->addDbService(self::SERVICE_DB_QUOTE, $manager, $dbVersion, $volumesMount, $config);
212+
$this->addDbService($manager, $config, self::SERVICE_DB_QUOTE, $dbVersion, $volumesMount);
213213
}
214214

215215
if ($config->hasServiceEnabled(ServiceInterface::SERVICE_DB_SALES)) {
216216
$cliDepends = array_merge($cliDepends, [self::SERVICE_DB_SALES => ['condition' => 'service_started']]);
217-
$this->addDbService(self::SERVICE_DB_SALES, $manager, $dbVersion, $volumesMount, $config);
217+
$this->addDbService($manager, $config, self::SERVICE_DB_SALES, $dbVersion, $volumesMount);
218218
}
219219

220220
$esEnvVars = $config->get(SourceInterface::SERVICES_ES_VARS);
@@ -463,11 +463,11 @@ public function getPath(): string
463463
* @throws GenericException
464464
*/
465465
private function addDbService(
466-
string $service,
467466
Manager $manager,
467+
Config $config,
468+
string $service,
468469
string $version,
469-
array $mounts,
470-
Config $config
470+
array $mounts
471471
): void {
472472
$volumePrefix = $config->getNameWithPrefix();
473473
$mounts[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
@@ -548,7 +548,8 @@ private function addDbService(
548548
$this->serviceFactory->create(
549549
$serviceType,
550550
$version,
551-
$dbConfig
551+
$dbConfig,
552+
$config->getServiceImage(ServiceInterface::SERVICE_DB)
552553
),
553554
[self::NETWORK_MAGENTO],
554555
[]

src/Config/Source/CliSource.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CliSource implements SourceInterface
2121
public const OPTION_PHP = 'php';
2222
public const OPTION_NGINX = 'nginx';
2323
public const OPTION_DB = 'db';
24+
public const OPTION_DB_IMAGE = 'db-image';
2425
public const OPTION_EXPOSE_DB_PORT = 'expose-db-port';
2526
public const OPTION_EXPOSE_DB_QUOTE_PORT = 'expose-db-quote-port';
2627
public const OPTION_EXPOSE_DB_SALES_PORT = 'expose-db-sales-port';
@@ -166,6 +167,12 @@ public function read(): Repository
166167
]);
167168
}
168169

170+
if ($dbImage = $this->input->getOption(self::OPTION_DB_IMAGE)) {
171+
$repository->set([
172+
self::SERVICES_DB_IMAGE => $dbImage
173+
]);
174+
}
175+
169176
if ($this->input->getOption(self::OPTION_NO_TMP_MOUNTS)) {
170177
$repository->set(self::SYSTEM_TMP_MOUNTS, false);
171178
}

src/Config/Source/CloudSource.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ private function addRelationships(Repository $repository, array $relationships):
174174
continue;
175175
}
176176

177-
if ($repository->has(self::SERVICES . '.' . $service) && $service != ServiceInterface::SERVICE_DB) {
177+
if ($service !== ServiceInterface::SERVICE_DB
178+
&& $repository->has(self::SERVICES . '.' . $service)
179+
) {
178180
throw new SourceException(sprintf(
179181
'Only one instance of service "%s" supported',
180182
$service
@@ -185,9 +187,7 @@ private function addRelationships(Repository $repository, array $relationships):
185187
$repository->set([
186188
self::SERVICES . '.' . $service . '.enabled' => true,
187189
self::SERVICES . '.' . $service . '.version' => $version,
188-
self::SERVICES . '.' . $service . '.image' => $this->serviceFactory->getDefaultImage(
189-
$service
190-
)
190+
self::SERVICES . '.' . $service . '.image' => $this->serviceFactory->getDefaultImage($service)
191191
]);
192192
} catch (ConfigurationMismatchException $exception) {
193193
throw new SourceException($exception->getMessage(), $exception->getCode(), $exception);

src/Config/Source/SourceInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ interface SourceInterface
4848
* DB
4949
*/
5050
public const SERVICES_DB = self::SERVICES . '.' . ServiceInterface::SERVICE_DB;
51+
public const SERVICES_DB_IMAGE = self::SERVICES_DB . '.image';
5152

5253
/**
5354
* DB quote

src/Test/Integration/BuildCustomComposeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function buildDataProvider(): array
9797
],
9898
'mysql' => [
9999
'version' => '10.0',
100+
'image' => 'mariadb',
100101
'enabled' => true,
101102
],
102103
],

0 commit comments

Comments
 (0)