7
7
8
8
namespace Magento \CloudDocker \Compose ;
9
9
10
+ use Magento \CloudDocker \App \GenericException ;
10
11
use Magento \CloudDocker \App \ConfigurationMismatchException ;
11
12
use Magento \CloudDocker \Compose \Php \ExtensionResolver ;
12
13
use Magento \CloudDocker \Compose \ProductionBuilder \VolumeResolver ;
@@ -138,36 +139,12 @@ public function build(Config $config): Manager
138
139
139
140
$ phpVersion = $ config ->getServiceVersion (ServiceInterface::SERVICE_PHP );
140
141
$ dbVersion = $ config ->getServiceVersion (ServiceInterface::SERVICE_DB );
141
- $ hostPort = $ config ->getDbPortsExpose ();
142
- $ dbPorts = $ hostPort ? "$ hostPort:3306 " : '3306 ' ;
142
+ $ cliDepends = self ::$ cliDepends ;
143
143
144
144
$ manager ->addNetwork (self ::NETWORK_MAGENTO , ['driver ' => 'bridge ' ]);
145
145
$ manager ->addNetwork (self ::NETWORK_MAGENTO_BUILD , ['driver ' => 'bridge ' ]);
146
146
147
- $ volumes = [
148
- self ::VOLUME_MAGENTO => [
149
- 'driver_opts ' => [
150
- 'type ' => 'none ' ,
151
- 'device ' => $ this ->resolver ->getRootPath (),
152
- 'o ' => 'bind '
153
- ]
154
- ],
155
- self ::VOLUME_MAGENTO_DB => [],
156
- self ::VOLUME_MARIADB_CONF => [
157
- 'driver_opts ' => [
158
- 'type ' => 'none ' ,
159
- 'device ' => $ this ->resolver ->getRootPath ('/.docker/mysql/mariadb.conf.d ' ),
160
- 'o ' => 'bind ' ,
161
- ],
162
- ],
163
- self ::VOLUME_DOCKER_ETRYPOINT => [
164
- 'driver_opts ' => [
165
- 'type ' => 'none ' ,
166
- 'device ' => $ this ->resolver ->getRootPath ('/.docker/mysql/docker-entrypoint-initdb.d ' ),
167
- 'o ' => 'bind '
168
- ]
169
- ]
170
- ];
147
+ $ volumes = [self ::VOLUME_MAGENTO => $ this ->getVolumeConfig ()];
171
148
172
149
if ($ config ->hasServiceEnabled (ServiceInterface::SERVICE_SELENIUM )) {
173
150
$ manager ->addVolume (self ::VOLUME_MAGENTO_DEV , []);
@@ -178,38 +155,20 @@ public function build(Config $config): Manager
178
155
$ hasTmpMounts = $ config ->hasTmpMounts ();
179
156
180
157
if ($ hasTmpMounts ) {
181
- $ volumes [self ::VOLUME_DOCKER_MNT ] = [
182
- 'driver_opts ' => [
183
- 'type ' => 'none ' ,
184
- 'device ' => $ this ->resolver ->getRootPath ('/.docker/mnt ' ),
185
- 'o ' => 'bind '
186
- ]
187
- ];
158
+ $ volumes [self ::VOLUME_DOCKER_MNT ] = $ this ->getVolumeConfig ('/.docker/mnt ' );
188
159
}
189
160
190
161
foreach ($ this ->volumeResolver ->getMagentoVolumes ($ mounts , false , $ hasSelenium ) as $ volumeName => $ volume ) {
191
162
$ syncConfig = [];
192
163
193
164
if (!empty ($ volume ['volume ' ]) && $ config ->getSyncEngine () === self ::SYNC_ENGINE_NATIVE ) {
194
- $ syncConfig = [
195
- 'driver_opts ' => [
196
- 'type ' => 'none ' ,
197
- 'device ' => $ this ->resolver ->getRootPath ($ volume ['volume ' ]),
198
- 'o ' => 'bind '
199
- ]
200
- ];
165
+ $ syncConfig = $ this ->getVolumeConfig ($ volume ['volume ' ]);
201
166
}
202
167
$ volumes [$ volumeName ] = $ syncConfig ;
203
168
}
204
169
205
170
if ($ config ->getSyncEngine () === self ::SYNC_ENGINE_MOUNT ) {
206
- $ volumes [self ::VOLUME_MAGENTO ] = [
207
- 'driver_opts ' => [
208
- 'type ' => 'none ' ,
209
- 'device ' => $ this ->resolver ->getRootPath (),
210
- 'o ' => 'bind '
211
- ]
212
- ];
171
+ $ volumes [self ::VOLUME_MAGENTO ] = $ this ->getVolumeConfig ();
213
172
}
214
173
215
174
$ manager ->setVolumes ($ volumes );
@@ -231,27 +190,23 @@ public function build(Config $config): Manager
231
190
$ this ->volumeResolver ->getMountVolumes ($ hasTmpMounts )
232
191
);
233
192
234
- $ manager ->addService (
235
- self ::SERVICE_DB ,
236
- $ this ->serviceFactory ->create (
237
- ServiceInterface::SERVICE_DB ,
238
- $ dbVersion ,
239
- [
240
- 'ports ' => [$ dbPorts ],
241
- 'volumes ' => array_merge (
242
- [
243
- self ::VOLUME_MAGENTO_DB . ':/var/lib/mysql ' ,
244
- self ::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d ' ,
245
- self ::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d ' ,
246
- ],
247
- $ volumesMount
248
- )
249
- ]
250
- ),
251
- [self ::NETWORK_MAGENTO ],
252
- []
193
+ $ manager ->addVolume (
194
+ self ::VOLUME_MARIADB_CONF ,
195
+ $ this ->getVolumeConfig ('/.docker/mysql/mariadb.conf.d ' )
253
196
);
254
197
198
+ $ this ->addDbService (self ::SERVICE_DB , $ manager , $ dbVersion , $ volumesMount , $ config );
199
+
200
+ if ($ config ->hasServiceEnabled (ServiceInterface::SERVICE_DB_QUOTE )) {
201
+ $ cliDepends = array_merge ($ cliDepends , [self ::SERVICE_DB_QUOTE => ['condition ' => 'service_started ' ]]);
202
+ $ this ->addDbService (self ::SERVICE_DB_QUOTE , $ manager , $ dbVersion , $ volumesMount , $ config );
203
+ }
204
+
205
+ if ($ config ->hasServiceEnabled (ServiceInterface::SERVICE_DB_SALES )) {
206
+ $ cliDepends = array_merge ($ cliDepends , [self ::SERVICE_DB_SALES => ['condition ' => 'service_started ' ]]);
207
+ $ this ->addDbService (self ::SERVICE_DB_SALES , $ manager , $ dbVersion , $ volumesMount , $ config );
208
+ }
209
+
255
210
foreach (self ::$ standaloneServices as $ service ) {
256
211
if (!$ config ->hasServiceEnabled ($ service )) {
257
212
continue ;
@@ -361,7 +316,7 @@ public function build(Config $config): Manager
361
316
['volumes ' => $ volumesRw ]
362
317
),
363
318
[self ::NETWORK_MAGENTO ],
364
- self :: $ cliDepends
319
+ $ cliDepends
365
320
);
366
321
}
367
322
@@ -406,7 +361,7 @@ public function build(Config $config): Manager
406
361
self ::SERVICE_BUILD ,
407
362
$ this ->serviceFactory ->create (ServiceInterface::SERVICE_PHP_CLI , $ phpVersion , ['volumes ' => $ volumesBuild ]),
408
363
[self ::NETWORK_MAGENTO_BUILD ],
409
- self :: $ cliDepends
364
+ $ cliDepends
410
365
);
411
366
$ manager ->addService (
412
367
self ::SERVICE_DEPLOY ,
@@ -423,7 +378,7 @@ public function build(Config $config): Manager
423
378
['volumes ' => $ volumesRo ]
424
379
),
425
380
[self ::NETWORK_MAGENTO ],
426
- self :: $ cliDepends
381
+ $ cliDepends
427
382
);
428
383
}
429
384
@@ -468,4 +423,98 @@ public function getPath(): string
468
423
{
469
424
return $ this ->fileList ->getMagentoDockerCompose ();
470
425
}
426
+
427
+ /**
428
+ * @param string $service
429
+ * @param Manager $manager
430
+ * @param string $version
431
+ * @param array $mounts
432
+ * @param Config $config
433
+ * @throws ConfigurationMismatchException
434
+ * @throws GenericException
435
+ */
436
+ private function addDbService (
437
+ string $ service ,
438
+ Manager $ manager ,
439
+ string $ version ,
440
+ array $ mounts ,
441
+ Config $ config
442
+ ) {
443
+ $ mounts [] = self ::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d ' ;
444
+
445
+ switch ($ service ) {
446
+ case self ::SERVICE_DB :
447
+ $ port = $ config ->getDbPortsExpose ();
448
+
449
+ $ manager ->addVolume (self ::VOLUME_MAGENTO_DB , []);
450
+ $ manager ->addVolume (
451
+ self ::VOLUME_DOCKER_ETRYPOINT ,
452
+ $ this ->getVolumeConfig ('/.docker/mysql/docker-entrypoint-initdb.d ' )
453
+ );
454
+
455
+ $ mounts [] = self ::VOLUME_MAGENTO_DB . ':/var/lib/mysql ' ;
456
+ $ mounts [] = self ::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d ' ;
457
+ $ serviceType = ServiceInterface::SERVICE_DB ;
458
+ break ;
459
+ case self ::SERVICE_DB_QUOTE :
460
+ $ port = $ config ->getDbQuotePortsExpose ();
461
+
462
+ $ manager ->addVolume (self ::VOLUME_MAGENTO_DB_QUOTE , []);
463
+ $ manager ->addVolume (
464
+ self ::VOLUME_DOCKER_ETRYPOINT_QUOTE ,
465
+ $ this ->getVolumeConfig ('/.docker/mysql-quote/docker-entrypoint-initdb.d ' )
466
+ );
467
+
468
+ $ mounts [] = self ::VOLUME_MAGENTO_DB_QUOTE . ':/var/lib/mysql ' ;
469
+ $ mounts [] = self ::VOLUME_DOCKER_ETRYPOINT_QUOTE . ':/docker-entrypoint-initdb.d ' ;
470
+ $ serviceType = ServiceInterface::SERVICE_DB_QUOTE ;
471
+ break ;
472
+ case self ::SERVICE_DB_SALES :
473
+ $ port = $ config ->getDbSalesPortsExpose ();
474
+
475
+ $ manager ->addVolume (self ::VOLUME_MAGENTO_DB_SALES , []);
476
+ $ manager ->addVolume (
477
+ self ::VOLUME_DOCKER_ETRYPOINT_SALES ,
478
+ $ this ->getVolumeConfig (
479
+ '/.docker/mysql-sales/docker-entrypoint-initdb.d '
480
+ )
481
+ );
482
+
483
+ $ mounts [] = self ::VOLUME_MAGENTO_DB_SALES . ':/var/lib/mysql ' ;
484
+ $ mounts [] = self ::VOLUME_DOCKER_ETRYPOINT_SALES . ':/docker-entrypoint-initdb.d ' ;
485
+ $ serviceType = ServiceInterface::SERVICE_DB_SALES ;
486
+ break ;
487
+ default :
488
+ throw new GenericException (sprintf ('Configuration for %s service not exist ' , $ service ));
489
+ }
490
+
491
+ $ manager ->addService (
492
+ $ service ,
493
+ $ this ->serviceFactory ->create (
494
+ $ serviceType ,
495
+ $ version ,
496
+ [
497
+ 'ports ' => [$ port ? "$ port:3306 " : '3306 ' ],
498
+ 'volumes ' => $ mounts ,
499
+ ]
500
+ ),
501
+ [self ::NETWORK_MAGENTO ],
502
+ []
503
+ );
504
+ }
505
+
506
+ /**
507
+ * @param string $device
508
+ * @return array
509
+ */
510
+ private function getVolumeConfig (string $ device = '/ ' ): array
511
+ {
512
+ return [
513
+ 'driver_opts ' => [
514
+ 'type ' => 'none ' ,
515
+ 'device ' => $ this ->resolver ->getRootPath ($ device ),
516
+ 'o ' => 'bind '
517
+ ]
518
+ ];
519
+ }
471
520
}
0 commit comments