Skip to content

Commit d423e5a

Browse files
MCLOUD-6424: Database directories are not creating automatically (#251)
1 parent ec7cedd commit d423e5a

File tree

8 files changed

+115
-51
lines changed

8 files changed

+115
-51
lines changed

src/Command/BuildCompose.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ protected function configure(): void
106106
null,
107107
InputOption::VALUE_REQUIRED,
108108
'DB image'
109-
)
110-
->addOption(
109+
)->addOption(
111110
Source\CliSource::OPTION_EXPOSE_DB_PORT,
112111
null,
113112
InputOption::VALUE_REQUIRED,
@@ -122,6 +121,16 @@ protected function configure(): void
122121
null,
123122
InputOption::VALUE_REQUIRED,
124123
'Expose port for DB quote'
124+
)->addOption(
125+
Source\CliSource::OPTION_WITH_ENTRYPOINT,
126+
null,
127+
InputOption::VALUE_NONE,
128+
'Add DB entrypoint volume'
129+
)->addOption(
130+
Source\CliSource::OPTION_WITH_MARIADB_CONF,
131+
null,
132+
InputOption::VALUE_NONE,
133+
'Add MariaDb config volume'
125134
)->addOption(
126135
Source\CliSource::OPTION_REDIS,
127136
null,

src/Compose/DeveloperBuilder.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ public function __construct(
7979
}
8080

8181
/**
82-
* @inheritDoc
82+
* {@inheritDoc}
83+
*
84+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8385
*/
8486
public function build(Config $config): Manager
8587
{
86-
$volumePrefix = $config->getName() . '-';
88+
$volumePrefix = $config->getName() . '-';
8789

8890
$manager = $this->builderFactory
8991
->create(BuilderFactory::BUILDER_PRODUCTION)
@@ -106,24 +108,32 @@ public function build(Config $config): Manager
106108
];
107109
}
108110

109-
$manager->setVolumes([
111+
$volumesList = [
110112
$volumePrefix . self::VOLUME_MAGENTO_SYNC => $syncConfig,
111-
$volumePrefix . self::VOLUME_MAGENTO_DB => [],
112-
$volumePrefix . self::VOLUME_MARIADB_CONF => [
113+
$volumePrefix . self::VOLUME_MAGENTO_DB => []
114+
];
115+
116+
if ($config->hasMariaDbConf()) {
117+
$volumesList[$volumePrefix . self::VOLUME_MARIADB_CONF] = [
113118
'driver_opts' => [
114119
'type' => 'none',
115120
'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'),
116121
'o' => 'bind',
117122
],
118-
],
119-
self::VOLUME_DOCKER_ETRYPOINT => [
123+
];
124+
}
125+
126+
if ($config->hasDbEntrypoint()) {
127+
$volumesList[self::VOLUME_DOCKER_ETRYPOINT] = [
120128
'driver_opts' => [
121129
'type' => 'none',
122130
'device' => $this->resolver->getRootPath('/.docker/mysql/docker-entrypoint-initdb.d'),
123131
'o' => 'bind'
124132
]
125-
]
126-
]);
133+
];
134+
}
135+
136+
$manager->setVolumes($volumesList);
127137

128138
/**
129139
* Gather all services except DB with specific volumes.
@@ -143,14 +153,22 @@ public function build(Config $config): Manager
143153
$manager->updateService($sName, ['volumes' => $volumes]);
144154
}
145155

156+
$dbVolumes = [
157+
$volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql'
158+
];
159+
160+
if ($config->hasMariaDbConf()) {
161+
$dbVolumes[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
162+
}
163+
164+
if ($config->hasDbEntrypoint()) {
165+
$dbVolumes[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d';
166+
}
167+
146168
$manager->updateService(self::SERVICE_DB, [
147169
'volumes' => array_merge(
148170
$volumes,
149-
[
150-
$volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql',
151-
self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d',
152-
$volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d',
153-
]
171+
$dbVolumes
154172
)
155173
]);
156174
$manager->updateService(self::SERVICE_GENERIC, [
@@ -178,7 +196,7 @@ public function getPath(): string
178196
*/
179197
private function getMagentoVolumes(Config $config): array
180198
{
181-
$volumePrefix = $config->getName() . '-';
199+
$volumePrefix = $config->getName() . '-';
182200

183201
if ($config->getSyncEngine() !== self::SYNC_ENGINE_NATIVE) {
184202
return [

src/Compose/ProductionBuilder.php

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,12 @@ public function build(Config $config): Manager
200200

201201
$volumePrefix = $config->getNameWithPrefix();
202202

203-
$manager->addVolume(
204-
$volumePrefix . self::VOLUME_MARIADB_CONF,
205-
$this->getVolumeConfig('/.docker/mysql/mariadb.conf.d')
206-
);
203+
if ($config->hasMariaDbConf()) {
204+
$manager->addVolume(
205+
$volumePrefix . self::VOLUME_MARIADB_CONF,
206+
$this->getVolumeConfig('/.docker/mysql/mariadb.conf.d')
207+
);
208+
}
207209

208210
$this->addDbService($manager, $config, self::SERVICE_DB, $dbVersion, $volumesMount);
209211

@@ -471,6 +473,9 @@ public function getPath(): string
471473
* @param Config $config
472474
* @throws ConfigurationMismatchException
473475
* @throws GenericException
476+
*
477+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
478+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
474479
*/
475480
private function addDbService(
476481
Manager $manager,
@@ -480,21 +485,29 @@ private function addDbService(
480485
array $mounts
481486
): void {
482487
$volumePrefix = $config->getNameWithPrefix();
483-
$mounts[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
488+
489+
if ($config->hasMariaDbConf()) {
490+
$mounts[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
491+
}
492+
484493
$commands = [];
485494

486495
switch ($service) {
487496
case self::SERVICE_DB:
488497
$port = $config->getDbPortsExpose();
489498

490499
$manager->addVolume($volumePrefix . self::VOLUME_MAGENTO_DB, []);
491-
$manager->addVolume(
492-
self::VOLUME_DOCKER_ETRYPOINT,
493-
$this->getVolumeConfig('/.docker/mysql/docker-entrypoint-initdb.d')
494-
);
495500

496501
$mounts[] = $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql';
497-
$mounts[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d';
502+
503+
if ($config->hasDbEntrypoint()) {
504+
$manager->addVolume(
505+
self::VOLUME_DOCKER_ETRYPOINT,
506+
$this->getVolumeConfig('/.docker/mysql/docker-entrypoint-initdb.d')
507+
);
508+
$mounts[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d';
509+
}
510+
498511
$serviceType = ServiceInterface::SERVICE_DB;
499512

500513
if ($config->getDbIncrementIncrement() > 1) {
@@ -541,11 +554,11 @@ private function addDbService(
541554
$dbConfig = [
542555
'ports' => [$port ? "$port:3306" : '3306'],
543556
'volumes' => $mounts,
544-
self::SERVICE_HEALTHCHECK => [
545-
'test'=> 'mysqladmin ping -h localhost',
546-
'interval'=> '30s',
547-
'timeout'=> '30s',
548-
'retries'=> 3
557+
self::SERVICE_HEALTHCHECK => [
558+
'test' => 'mysqladmin ping -h localhost',
559+
'interval' => '30s',
560+
'timeout' => '30s',
561+
'retries' => 3
549562
],
550563
];
551564

@@ -576,12 +589,14 @@ private function getServiceConfig(string $service, Config $config): array
576589
{
577590
switch ($service) {
578591
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-
]];
592+
$serviceConfig = [
593+
self::SERVICE_HEALTHCHECK => [
594+
'test' => 'redis-cli ping || exit 1',
595+
'interval' => '30s',
596+
'timeout' => '30s',
597+
'retries' => 3
598+
]
599+
];
585600
break;
586601

587602
case self::SERVICE_ELASTICSEARCH:

src/Config/Config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ public function hasTmpMounts(): bool
248248
return (bool)$this->all()->get(SourceInterface::SYSTEM_TMP_MOUNTS);
249249
}
250250

251+
/**
252+
* @return bool
253+
* @throws ConfigurationMismatchException
254+
*/
255+
public function hasDbEntrypoint(): bool
256+
{
257+
return (bool)$this->all()->get(SourceInterface::SYSTEM_DB_ENTRYPOINT);
258+
}
259+
260+
/**
261+
* @return bool
262+
* @throws ConfigurationMismatchException
263+
*/
264+
public function hasMariaDbConf(): bool
265+
{
266+
return (bool)$this->all()->get(SourceInterface::SYSTEM_MARIADB_CONF);
267+
}
268+
251269
/**
252270
* @return array
253271
* @throws ConfigurationMismatchException

src/Config/Source/CliSource.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class CliSource implements SourceInterface
4444
public const OPTION_NO_TMP_MOUNTS = 'no-tmp-mounts';
4545
public const OPTION_SYNC_ENGINE = 'sync-engine';
4646
public const OPTION_WITH_XDEBUG = 'with-xdebug';
47+
public const OPTION_WITH_ENTRYPOINT = 'with-entrypoint';
48+
public const OPTION_WITH_MARIADB_CONF = 'with-mariadb-conf';
4749

4850
/**
4951
* Environment variables.
@@ -255,6 +257,14 @@ public function read(): Repository
255257
$repository->set(SourceInterface::SYSTEM_DB_INCREMENT_OFFSET, $incrementOffset);
256258
}
257259

260+
if ($this->input->getOption(self::OPTION_WITH_ENTRYPOINT)) {
261+
$repository->set(SourceInterface::SYSTEM_DB_ENTRYPOINT, true);
262+
}
263+
264+
if ($this->input->getOption(self::OPTION_WITH_MARIADB_CONF)) {
265+
$repository->set(SourceInterface::SYSTEM_MARIADB_CONF, true);
266+
}
267+
258268
return $repository;
259269
}
260270
}

src/Config/Source/SourceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ interface SourceInterface
129129
public const SYSTEM_EXPOSE_DB_PORTS = 'system.expose_db_ports';
130130
public const SYSTEM_EXPOSE_DB_QUOTE_PORTS = 'system.expose_db_quote_ports';
131131
public const SYSTEM_EXPOSE_DB_SALES_PORTS = 'system.expose_db_sales_ports';
132+
public const SYSTEM_DB_ENTRYPOINT = 'system.db_entrypoint';
133+
public const SYSTEM_MARIADB_CONF = 'system.mariadb_conf';
132134

133135
public const SYSTEM_DB_INCREMENT_INCREMENT = 'system.db.increment_increment';
134136
public const SYSTEM_DB_INCREMENT_OFFSET = 'system.db.increment_offset';

src/Test/Integration/BuildComposeTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ public function buildDataProvider(): array
7474
'cloud-base' => [
7575
__DIR__ . '/_files/cloud_base',
7676
[
77-
[CliSource::OPTION_MODE, BuilderFactory::BUILDER_PRODUCTION]
77+
[CliSource::OPTION_MODE, BuilderFactory::BUILDER_PRODUCTION],
78+
[CliSource::OPTION_WITH_ENTRYPOINT, true],
79+
[CliSource::OPTION_WITH_MARIADB_CONF, true]
7880
]
7981
],
8082
'cloud-base-mftf' => [
@@ -88,6 +90,8 @@ public function buildDataProvider(): array
8890
[CliSource::OPTION_NO_ES, true],
8991
[CliSource::OPTION_DB_INCREMENT_INCREMENT, 3],
9092
[CliSource::OPTION_DB_INCREMENT_OFFSET, 2],
93+
[CliSource::OPTION_WITH_ENTRYPOINT, true],
94+
[CliSource::OPTION_WITH_MARIADB_CONF, true]
9195
]
9296
]
9397
];

src/Test/Integration/_files/custom_cloud_base/docker-compose.exp.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ services:
1212
- '3306'
1313
volumes:
1414
- 'docker-mnt:/mnt:rw,delegated'
15-
- 'magento-mariadb-conf:/etc/mysql/mariadb.conf.d'
1615
- 'magento-magento-db:/var/lib/mysql'
17-
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
1816
healthcheck:
1917
test: 'mysqladmin ping -h localhost'
2018
interval: 30s
@@ -155,17 +153,7 @@ volumes:
155153
magento-app-etc: { }
156154
magento-pub-media: { }
157155
magento-pub-static: { }
158-
magento-mariadb-conf:
159-
driver_opts:
160-
type: none
161-
device: '${PWD}/.docker/mysql/mariadb.conf.d'
162-
o: bind
163156
magento-magento-db: { }
164-
docker-entrypoint:
165-
driver_opts:
166-
type: none
167-
device: '${PWD}/.docker/mysql/docker-entrypoint-initdb.d'
168-
o: bind
169157
networks:
170158
magento:
171159
driver: bridge

0 commit comments

Comments
 (0)