Skip to content

Commit 50af85a

Browse files
authored
Fix for conflicting volumes - #43 (#168)
1 parent 41c7e34 commit 50af85a

File tree

8 files changed

+62
-19
lines changed

8 files changed

+62
-19
lines changed

src/Compose/DeveloperBuilder.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function __construct(
8383
*/
8484
public function build(Config $config): Manager
8585
{
86+
$volumePrefix = $config->getName() . '-';
87+
8688
$manager = $this->builderFactory
8789
->create(BuilderFactory::BUILDER_PRODUCTION)
8890
->build($config);
@@ -105,9 +107,9 @@ public function build(Config $config): Manager
105107
}
106108

107109
$manager->setVolumes([
108-
self::VOLUME_MAGENTO_SYNC => $syncConfig,
109-
self::VOLUME_MAGENTO_DB => [],
110-
self::VOLUME_MARIADB_CONF => [
110+
$volumePrefix . self::VOLUME_MAGENTO_SYNC => $syncConfig,
111+
$volumePrefix . self::VOLUME_MAGENTO_DB => [],
112+
$volumePrefix . self::VOLUME_MARIADB_CONF => [
111113
'driver_opts' => [
112114
'type' => 'none',
113115
'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'),
@@ -145,9 +147,9 @@ public function build(Config $config): Manager
145147
'volumes' => array_merge(
146148
$volumes,
147149
[
148-
self::VOLUME_MAGENTO_DB . ':/var/lib/mysql',
150+
$volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql',
149151
self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d',
150-
self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d',
152+
$volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d',
151153
]
152154
)
153155
]);
@@ -176,14 +178,16 @@ public function getPath(): string
176178
*/
177179
private function getMagentoVolumes(Config $config): array
178180
{
181+
$volumePrefix = $config->getName() . '-';
182+
179183
if ($config->getSyncEngine() !== self::SYNC_ENGINE_NATIVE) {
180184
return [
181-
self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy'
185+
$volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy'
182186
];
183187
}
184188

185189
return [
186-
self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':delegated',
190+
$volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':delegated',
187191
];
188192
}
189193
}

src/Compose/ProductionBuilder.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,10 @@ public function build(Config $config): Manager
190190
$this->volumeResolver->getMountVolumes($hasTmpMounts)
191191
);
192192

193+
$volumePrefix = $config->getName() . '-';
194+
193195
$manager->addVolume(
194-
self::VOLUME_MARIADB_CONF,
196+
$volumePrefix . self::VOLUME_MARIADB_CONF,
195197
$this->getVolumeConfig('/.docker/mysql/mariadb.conf.d')
196198
);
197199

@@ -440,19 +442,20 @@ private function addDbService(
440442
array $mounts,
441443
Config $config
442444
) {
443-
$mounts[] = self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
445+
$volumePrefix = $config->getName() . '-';
446+
$mounts[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d';
444447

445448
switch ($service) {
446449
case self::SERVICE_DB:
447450
$port = $config->getDbPortsExpose();
448451

449-
$manager->addVolume(self::VOLUME_MAGENTO_DB, []);
452+
$manager->addVolume($volumePrefix . self::VOLUME_MAGENTO_DB, []);
450453
$manager->addVolume(
451454
self::VOLUME_DOCKER_ETRYPOINT,
452455
$this->getVolumeConfig('/.docker/mysql/docker-entrypoint-initdb.d')
453456
);
454457

455-
$mounts[] = self::VOLUME_MAGENTO_DB . ':/var/lib/mysql';
458+
$mounts[] = $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql';
456459
$mounts[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d';
457460
$serviceType = ServiceInterface::SERVICE_DB;
458461
break;

src/Config/Config.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,13 @@ public function getPort(): string
331331
{
332332
return $this->get(SourceInterface::CONFIG_PORT);
333333
}
334+
335+
/**
336+
* @return String
337+
* @throws ConfigurationMismatchException
338+
*/
339+
public function getName(): String
340+
{
341+
return $this->all()->get(SourceInterface::NAME);
342+
}
334343
}

src/Config/Source/CloudSource.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public function read(): Repository
9191
throw new SourceException('Relationships could not be parsed.');
9292
}
9393

94+
if (!isset($appConfig['name'])) {
95+
throw new SourceException('Name could not be parsed.');
96+
}
97+
9498
[$type, $version] = explode(':', $appConfig['type']);
9599
/**
96100
* RC versions are not supported
@@ -128,6 +132,10 @@ public function read(): Repository
128132
$repository,
129133
$appConfig['relationships'] ?? []
130134
);
135+
$repository = $this->addName(
136+
$repository,
137+
$appConfig['name']
138+
);
131139

132140
return $repository;
133141
}
@@ -290,4 +298,18 @@ private function addMounts(Repository $repository, array $mounts): Repository
290298

291299
return $repository;
292300
}
301+
302+
/**
303+
* @param Repository $repository
304+
* @param string $name
305+
* @return Repository
306+
*/
307+
private function addName(Repository $repository, string $name): Repository
308+
{
309+
$repository->set([
310+
self::NAME => $name,
311+
]);
312+
313+
return $repository;
314+
}
293315
}

src/Config/Source/ConfigSource.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public function read(): Repository
5050
if ($this->filesystem->exists($configFile)) {
5151
$config = Yaml::parseFile($configFile);
5252

53+
if (!isset($config['name'])) {
54+
throw new SourceException('Name could not be parsed.');
55+
}
56+
5357
/**
5458
* Enable services which were added from the file by default
5559
*/

src/Config/Source/SourceInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface SourceInterface
1818
public const DIR_MAGENTO = '/app';
1919

2020
public const MOUNTS = 'mounts';
21+
public const NAME = 'name';
2122

2223
/**
2324
* Services

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ services:
1212
- '3306'
1313
volumes:
1414
- 'docker-mnt:/mnt:delegated'
15-
- 'mariadb-conf:/etc/mysql/mariadb.conf.d'
16-
- 'magento-db:/var/lib/mysql'
15+
- 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d'
16+
- 'mymagento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
1818
networks:
1919
magento:
@@ -175,12 +175,12 @@ volumes:
175175
magento-app-etc: { }
176176
magento-pub-media: { }
177177
magento-pub-static: { }
178-
mariadb-conf:
178+
mymagento-mariadb-conf:
179179
driver_opts:
180180
type: none
181181
device: '${PWD}/.docker/mysql/mariadb.conf.d'
182182
o: bind
183-
magento-db: { }
183+
mymagento-magento-db: { }
184184
docker-entrypoint:
185185
driver_opts:
186186
type: none

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ services:
1212
- '3306'
1313
volumes:
1414
- 'docker-mnt:/mnt:delegated'
15-
- 'mariadb-conf:/etc/mysql/mariadb.conf.d'
16-
- 'magento-db:/var/lib/mysql'
15+
- 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d'
16+
- 'mymagento-magento-db:/var/lib/mysql'
1717
- 'docker-entrypoint:/docker-entrypoint-initdb.d'
1818
networks:
1919
magento:
@@ -271,12 +271,12 @@ volumes:
271271
magento-pub-media: { }
272272
magento-pub-static: { }
273273
magento-dev: { }
274-
mariadb-conf:
274+
mymagento-mariadb-conf:
275275
driver_opts:
276276
type: none
277277
device: '${PWD}/.docker/mysql/mariadb.conf.d'
278278
o: bind
279-
magento-db: { }
279+
mymagento-magento-db: { }
280280
docker-entrypoint:
281281
driver_opts:
282282
type: none

0 commit comments

Comments
 (0)