diff --git a/src/Compose/DeveloperBuilder.php b/src/Compose/DeveloperBuilder.php index 445aee04..71c52c84 100644 --- a/src/Compose/DeveloperBuilder.php +++ b/src/Compose/DeveloperBuilder.php @@ -83,6 +83,8 @@ public function __construct( */ public function build(Config $config): Manager { + $volumePrefix = $config->getName() . '-'; + $manager = $this->builderFactory ->create(BuilderFactory::BUILDER_PRODUCTION) ->build($config); @@ -105,9 +107,9 @@ public function build(Config $config): Manager } $manager->setVolumes([ - self::VOLUME_MAGENTO_SYNC => $syncConfig, - self::VOLUME_MAGENTO_DB => [], - self::VOLUME_MARIADB_CONF => [ + $volumePrefix . self::VOLUME_MAGENTO_SYNC => $syncConfig, + $volumePrefix . self::VOLUME_MAGENTO_DB => [], + $volumePrefix . self::VOLUME_MARIADB_CONF => [ 'driver_opts' => [ 'type' => 'none', 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), @@ -145,9 +147,9 @@ public function build(Config $config): Manager 'volumes' => array_merge( $volumes, [ - self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', + $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', - self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', + $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', ] ) ]); @@ -176,14 +178,16 @@ public function getPath(): string */ private function getMagentoVolumes(Config $config): array { + $volumePrefix = $config->getName() . '-'; + if ($config->getSyncEngine() !== self::SYNC_ENGINE_NATIVE) { return [ - self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy' + $volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy' ]; } return [ - self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':delegated', + $volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':delegated', ]; } } diff --git a/src/Compose/ProductionBuilder.php b/src/Compose/ProductionBuilder.php index e07602bc..4c464b3e 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -190,8 +190,10 @@ public function build(Config $config): Manager $this->volumeResolver->getMountVolumes($hasTmpMounts) ); + $volumePrefix = $config->getName() . '-'; + $manager->addVolume( - self::VOLUME_MARIADB_CONF, + $volumePrefix . self::VOLUME_MARIADB_CONF, $this->getVolumeConfig('/.docker/mysql/mariadb.conf.d') ); @@ -440,19 +442,20 @@ private function addDbService( array $mounts, Config $config ) { - $mounts[] = self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d'; + $volumePrefix = $config->getName() . '-'; + $mounts[] = $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d'; switch ($service) { case self::SERVICE_DB: $port = $config->getDbPortsExpose(); - $manager->addVolume(self::VOLUME_MAGENTO_DB, []); + $manager->addVolume($volumePrefix . self::VOLUME_MAGENTO_DB, []); $manager->addVolume( self::VOLUME_DOCKER_ETRYPOINT, $this->getVolumeConfig('/.docker/mysql/docker-entrypoint-initdb.d') ); - $mounts[] = self::VOLUME_MAGENTO_DB . ':/var/lib/mysql'; + $mounts[] = $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql'; $mounts[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d'; $serviceType = ServiceInterface::SERVICE_DB; break; diff --git a/src/Config/Config.php b/src/Config/Config.php index 512df912..6c43a4e7 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -331,4 +331,13 @@ public function getPort(): string { return $this->get(SourceInterface::CONFIG_PORT); } + + /** + * @return String + * @throws ConfigurationMismatchException + */ + public function getName(): String + { + return $this->all()->get(SourceInterface::NAME); + } } diff --git a/src/Config/Source/CloudSource.php b/src/Config/Source/CloudSource.php index f26cd005..31779966 100644 --- a/src/Config/Source/CloudSource.php +++ b/src/Config/Source/CloudSource.php @@ -91,6 +91,10 @@ public function read(): Repository throw new SourceException('Relationships could not be parsed.'); } + if (!isset($appConfig['name'])) { + throw new SourceException('Name could not be parsed.'); + } + [$type, $version] = explode(':', $appConfig['type']); /** * RC versions are not supported @@ -128,6 +132,10 @@ public function read(): Repository $repository, $appConfig['relationships'] ?? [] ); + $repository = $this->addName( + $repository, + $appConfig['name'] + ); return $repository; } @@ -290,4 +298,18 @@ private function addMounts(Repository $repository, array $mounts): Repository return $repository; } + + /** + * @param Repository $repository + * @param string $name + * @return Repository + */ + private function addName(Repository $repository, string $name): Repository + { + $repository->set([ + self::NAME => $name, + ]); + + return $repository; + } } diff --git a/src/Config/Source/ConfigSource.php b/src/Config/Source/ConfigSource.php index 66cc1fed..c574effc 100644 --- a/src/Config/Source/ConfigSource.php +++ b/src/Config/Source/ConfigSource.php @@ -50,6 +50,10 @@ public function read(): Repository if ($this->filesystem->exists($configFile)) { $config = Yaml::parseFile($configFile); + if (!isset($config['name'])) { + throw new SourceException('Name could not be parsed.'); + } + /** * Enable services which were added from the file by default */ diff --git a/src/Config/Source/SourceInterface.php b/src/Config/Source/SourceInterface.php index 1e726480..64a4cf13 100644 --- a/src/Config/Source/SourceInterface.php +++ b/src/Config/Source/SourceInterface.php @@ -18,6 +18,7 @@ interface SourceInterface public const DIR_MAGENTO = '/app'; public const MOUNTS = 'mounts'; + public const NAME = 'name'; /** * Services diff --git a/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml b/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml index ac804737..a41b2146 100644 --- a/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml +++ b/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml @@ -12,8 +12,8 @@ services: - '3306' volumes: - 'docker-mnt:/mnt:delegated' - - 'mariadb-conf:/etc/mysql/mariadb.conf.d' - - 'magento-db:/var/lib/mysql' + - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' + - 'mymagento-magento-db:/var/lib/mysql' - 'docker-entrypoint:/docker-entrypoint-initdb.d' networks: magento: @@ -175,12 +175,12 @@ volumes: magento-app-etc: { } magento-pub-media: { } magento-pub-static: { } - mariadb-conf: + mymagento-mariadb-conf: driver_opts: type: none device: '${PWD}/.docker/mysql/mariadb.conf.d' o: bind - magento-db: { } + mymagento-magento-db: { } docker-entrypoint: driver_opts: type: none diff --git a/src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml b/src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml index 55e4f139..c23326f5 100644 --- a/src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml +++ b/src/Test/Integration/_files/cloud_base_mftf/docker-compose.exp.yml @@ -12,8 +12,8 @@ services: - '3306' volumes: - 'docker-mnt:/mnt:delegated' - - 'mariadb-conf:/etc/mysql/mariadb.conf.d' - - 'magento-db:/var/lib/mysql' + - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' + - 'mymagento-magento-db:/var/lib/mysql' - 'docker-entrypoint:/docker-entrypoint-initdb.d' networks: magento: @@ -271,12 +271,12 @@ volumes: magento-pub-media: { } magento-pub-static: { } magento-dev: { } - mariadb-conf: + mymagento-mariadb-conf: driver_opts: type: none device: '${PWD}/.docker/mysql/mariadb.conf.d' o: bind - magento-db: { } + mymagento-magento-db: { } docker-entrypoint: driver_opts: type: none