From 79a57dba9e409d53e97adc155f358a61c70c4a87 Mon Sep 17 00:00:00 2001 From: Arvind Date: Mon, 9 Mar 2020 18:18:29 +0530 Subject: [PATCH 01/11] Multiple Volume issue, Prefixed Volume name with app name --- src/Compose/DeveloperBuilder.php | 31 ++++++++++++++++++++++--------- src/Compose/ProductionBuilder.php | 20 +++++++++++++++----- src/Config/Source/CloudSource.php | 26 ++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/Compose/DeveloperBuilder.php b/src/Compose/DeveloperBuilder.php index 445aee04..09ab5ab8 100644 --- a/src/Compose/DeveloperBuilder.php +++ b/src/Compose/DeveloperBuilder.php @@ -12,6 +12,7 @@ use Magento\CloudDocker\Config\Config; use Magento\CloudDocker\Config\Environment\Converter; use Magento\CloudDocker\Filesystem\FileList; +use Magento\CloudDocker\Config\Source\CloudSource; /** * Developer compose configuration. @@ -57,25 +58,33 @@ class DeveloperBuilder implements BuilderInterface */ private $extensionResolver; + /** + * @var CloudSource + */ + private $cloudSource; + /** * @param BuilderFactory $builderFactory * @param FileList $fileList * @param Resolver $resolver * @param Converter $converter * @param ExtensionResolver $extensionResolver + * @param CloudSource $cloudSource */ public function __construct( BuilderFactory $builderFactory, FileList $fileList, Resolver $resolver, Converter $converter, - ExtensionResolver $extensionResolver + ExtensionResolver $extensionResolver, + CloudSource $cloudSource ) { $this->builderFactory = $builderFactory; $this->fileList = $fileList; $this->resolver = $resolver; $this->converter = $converter; $this->extensionResolver = $extensionResolver; + $this->cloudSource = $cloudSource; } /** @@ -105,9 +114,9 @@ public function build(Config $config): Manager } $manager->setVolumes([ - self::VOLUME_MAGENTO_SYNC => $syncConfig, - self::VOLUME_MAGENTO_DB => [], - self::VOLUME_MARIADB_CONF => [ + $this->cloudSource->read()->get('name') . '-' . self::VOLUME_MAGENTO_SYNC => $syncConfig, + $this->cloudSource->read()->get('name') . '-' . self::VOLUME_MAGENTO_DB => [], + $this->cloudSource->read()->get('name') . '-' . self::VOLUME_MARIADB_CONF => [ 'driver_opts' => [ 'type' => 'none', 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), @@ -145,9 +154,11 @@ public function build(Config $config): Manager 'volumes' => array_merge( $volumes, [ - self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', - self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', - self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', + $this->cloudSource->read()->get('name').'-'.self::VOLUME_DOCKER_ETRYPOINT . + ':/docker-entrypoint-initdb.d', + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MARIADB_CONF . + ':/etc/mysql/mariadb.conf.d', ] ) ]); @@ -178,12 +189,14 @@ private function getMagentoVolumes(Config $config): array { if ($config->getSyncEngine() !== self::SYNC_ENGINE_NATIVE) { return [ - self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy' + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_SYNC . ':' . + self::DIR_MAGENTO . ':nocopy' ]; } return [ - self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':delegated', + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_SYNC . ':' . + self::DIR_MAGENTO . ':delegated', ]; } } diff --git a/src/Compose/ProductionBuilder.php b/src/Compose/ProductionBuilder.php index bd43a639..4793e48f 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -15,6 +15,7 @@ use Magento\CloudDocker\Filesystem\FileList; use Magento\CloudDocker\Service\ServiceFactory; use Magento\CloudDocker\Service\ServiceInterface; +use Magento\CloudDocker\Config\Source\CloudSource; /** * Production compose configuration. @@ -98,6 +99,11 @@ class ProductionBuilder implements BuilderInterface */ private $volumeResolver; + /** + * @var CloudSource + */ + private $cloudSource; + /** * @param ServiceFactory $serviceFactory * @param FileList $fileList @@ -106,6 +112,7 @@ class ProductionBuilder implements BuilderInterface * @param ManagerFactory $managerFactory * @param Resolver $resolver * @param VolumeResolver $volumeResolver + * @param CloudSource $cloudSource */ public function __construct( ServiceFactory $serviceFactory, @@ -114,7 +121,8 @@ public function __construct( ExtensionResolver $phpExtension, ManagerFactory $managerFactory, Resolver $resolver, - VolumeResolver $volumeResolver + VolumeResolver $volumeResolver, + CloudSource $cloudSource ) { $this->serviceFactory = $serviceFactory; $this->fileList = $fileList; @@ -123,6 +131,7 @@ public function __construct( $this->managerFactory = $managerFactory; $this->resolver = $resolver; $this->volumeResolver = $volumeResolver; + $this->cloudSource = $cloudSource; } /** @@ -152,8 +161,8 @@ public function build(Config $config): Manager 'o' => 'bind' ] ], - self::VOLUME_MAGENTO_DB => [], - self::VOLUME_MARIADB_CONF => [ + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_DB => [], + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MARIADB_CONF => [ 'driver_opts' => [ 'type' => 'none', 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), @@ -240,9 +249,10 @@ public function build(Config $config): Manager 'ports' => [$dbPorts], 'volumes' => array_merge( [ - self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', - self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', + $this->cloudSource->read()->get('name').'-'.self::VOLUME_MARIADB_CONF . + ':/etc/mysql/mariadb.conf.d', ], $volumesMount ) diff --git a/src/Config/Source/CloudSource.php b/src/Config/Source/CloudSource.php index 3ac32cee..11c907f6 100644 --- a/src/Config/Source/CloudSource.php +++ b/src/Config/Source/CloudSource.php @@ -126,6 +126,10 @@ public function read(): Repository $repository, $appConfig['relationships'] ?? [] ); + $repository = $this->addName( + $repository, + $appConfig['name'] ?? [] + ); return $repository; } @@ -189,14 +193,14 @@ private function addRelationships(Repository $repository, array $relationships): /** * @param Repository $repository - * @param string $version + * @param String $version * @param array $extensions * @param array $disabledExtensions * @return Repository */ private function addPhp( Repository $repository, - string $version, + String $version, array $extensions, array $disabledExtensions ): Repository { @@ -218,11 +222,11 @@ private function addPhp( /** * @param Repository $repository - * @param string $version + * @param String $version * @return Repository * @throws SourceException */ - private function addXdebug(Repository $repository, string $version): Repository + private function addXdebug(Repository $repository, String $version): Repository { try { $repository->set([ @@ -288,4 +292,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([ + "name" => $name, + ]); + + return $repository; + } } From af79a37e8065438958c01618d967f9e7dcf2d05a Mon Sep 17 00:00:00 2001 From: Arvind Date: Mon, 9 Mar 2020 20:04:06 +0530 Subject: [PATCH 02/11] removed Cloud source direct usage --- src/Compose/DeveloperBuilder.php | 34 ++++++++++----------------- src/Compose/ProductionBuilder.php | 21 ++++++----------- src/Config/Source/CloudSource.php | 2 +- src/Config/Source/SourceInterface.php | 1 + 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/Compose/DeveloperBuilder.php b/src/Compose/DeveloperBuilder.php index 09ab5ab8..7f3502e5 100644 --- a/src/Compose/DeveloperBuilder.php +++ b/src/Compose/DeveloperBuilder.php @@ -12,7 +12,6 @@ use Magento\CloudDocker\Config\Config; use Magento\CloudDocker\Config\Environment\Converter; use Magento\CloudDocker\Filesystem\FileList; -use Magento\CloudDocker\Config\Source\CloudSource; /** * Developer compose configuration. @@ -58,10 +57,6 @@ class DeveloperBuilder implements BuilderInterface */ private $extensionResolver; - /** - * @var CloudSource - */ - private $cloudSource; /** * @param BuilderFactory $builderFactory @@ -69,22 +64,19 @@ class DeveloperBuilder implements BuilderInterface * @param Resolver $resolver * @param Converter $converter * @param ExtensionResolver $extensionResolver - * @param CloudSource $cloudSource */ public function __construct( BuilderFactory $builderFactory, FileList $fileList, Resolver $resolver, Converter $converter, - ExtensionResolver $extensionResolver, - CloudSource $cloudSource + ExtensionResolver $extensionResolver ) { $this->builderFactory = $builderFactory; $this->fileList = $fileList; $this->resolver = $resolver; $this->converter = $converter; $this->extensionResolver = $extensionResolver; - $this->cloudSource = $cloudSource; } /** @@ -92,6 +84,8 @@ public function __construct( */ public function build(Config $config): Manager { + $volumePrefix = $config->getName() . '-'; + $manager = $this->builderFactory ->create(BuilderFactory::BUILDER_PRODUCTION) ->build($config); @@ -114,9 +108,9 @@ public function build(Config $config): Manager } $manager->setVolumes([ - $this->cloudSource->read()->get('name') . '-' . self::VOLUME_MAGENTO_SYNC => $syncConfig, - $this->cloudSource->read()->get('name') . '-' . self::VOLUME_MAGENTO_DB => [], - $this->cloudSource->read()->get('name') . '-' . 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'), @@ -154,11 +148,9 @@ public function build(Config $config): Manager 'volumes' => array_merge( $volumes, [ - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', - $this->cloudSource->read()->get('name').'-'.self::VOLUME_DOCKER_ETRYPOINT . - ':/docker-entrypoint-initdb.d', - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MARIADB_CONF . - ':/etc/mysql/mariadb.conf.d', + $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', + $volumePrefix . self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', + $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', ] ) ]); @@ -187,16 +179,16 @@ public function getPath(): string */ private function getMagentoVolumes(Config $config): array { + $volumePrefix = $config->getName() . '-'; + if ($config->getSyncEngine() !== self::SYNC_ENGINE_NATIVE) { return [ - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_SYNC . ':' . - self::DIR_MAGENTO . ':nocopy' + $volumePrefix . self::VOLUME_MAGENTO_SYNC . ':' . self::DIR_MAGENTO . ':nocopy' ]; } return [ - $this->cloudSource->read()->get('name').'-'.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 4793e48f..7de8ff47 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -15,7 +15,6 @@ use Magento\CloudDocker\Filesystem\FileList; use Magento\CloudDocker\Service\ServiceFactory; use Magento\CloudDocker\Service\ServiceInterface; -use Magento\CloudDocker\Config\Source\CloudSource; /** * Production compose configuration. @@ -99,10 +98,6 @@ class ProductionBuilder implements BuilderInterface */ private $volumeResolver; - /** - * @var CloudSource - */ - private $cloudSource; /** * @param ServiceFactory $serviceFactory @@ -112,7 +107,6 @@ class ProductionBuilder implements BuilderInterface * @param ManagerFactory $managerFactory * @param Resolver $resolver * @param VolumeResolver $volumeResolver - * @param CloudSource $cloudSource */ public function __construct( ServiceFactory $serviceFactory, @@ -121,8 +115,7 @@ public function __construct( ExtensionResolver $phpExtension, ManagerFactory $managerFactory, Resolver $resolver, - VolumeResolver $volumeResolver, - CloudSource $cloudSource + VolumeResolver $volumeResolver ) { $this->serviceFactory = $serviceFactory; $this->fileList = $fileList; @@ -131,7 +124,6 @@ public function __construct( $this->managerFactory = $managerFactory; $this->resolver = $resolver; $this->volumeResolver = $volumeResolver; - $this->cloudSource = $cloudSource; } /** @@ -143,6 +135,8 @@ public function __construct( */ public function build(Config $config): Manager { + $volumePrefix = $config->getName() . '-'; + $manager = $this->managerFactory->create(); $phpVersion = $config->getServiceVersion(ServiceInterface::SERVICE_PHP); @@ -161,8 +155,8 @@ public function build(Config $config): Manager 'o' => 'bind' ] ], - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_DB => [], - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MARIADB_CONF => [ + $volumePrefix . self::VOLUME_MAGENTO_DB => [], + $volumePrefix . self::VOLUME_MARIADB_CONF => [ 'driver_opts' => [ 'type' => 'none', 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), @@ -249,10 +243,9 @@ public function build(Config $config): Manager 'ports' => [$dbPorts], 'volumes' => array_merge( [ - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', + $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', - $this->cloudSource->read()->get('name').'-'.self::VOLUME_MARIADB_CONF . - ':/etc/mysql/mariadb.conf.d', + $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', ], $volumesMount ) diff --git a/src/Config/Source/CloudSource.php b/src/Config/Source/CloudSource.php index 11c907f6..f5d00588 100644 --- a/src/Config/Source/CloudSource.php +++ b/src/Config/Source/CloudSource.php @@ -301,7 +301,7 @@ private function addMounts(Repository $repository, array $mounts): Repository private function addName(Repository $repository, String $name): Repository { $repository->set([ - "name" => $name, + self::NAME => $name, ]); return $repository; diff --git a/src/Config/Source/SourceInterface.php b/src/Config/Source/SourceInterface.php index 5535370a..b1ecc8be 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 From 894868fcc373ec41e8bb88f225100462668f4e54 Mon Sep 17 00:00:00 2001 From: Arvind Date: Tue, 10 Mar 2020 11:21:38 +0530 Subject: [PATCH 03/11] added config file --- src/Config/Config.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Config/Config.php b/src/Config/Config.php index 02e0ff39..64dbe20b 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -292,4 +292,13 @@ public function getVariables(): array return $config->get(SourceInterface::VARIABLES); } + + /** + * @return String + * @throws ConfigurationMismatchException + */ + public function getName(): String + { + return $this->all()->get(SourceInterface::NAME); + } } From e359fec20994cecb64054a37035d33597d1ad834 Mon Sep 17 00:00:00 2001 From: Arvind Date: Tue, 10 Mar 2020 19:29:59 +0530 Subject: [PATCH 04/11] made name as required field --- src/Config/Source/CloudSource.php | 4 ++++ src/Config/Source/ConfigSource.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Config/Source/CloudSource.php b/src/Config/Source/CloudSource.php index f5d00588..bc728fd9 100644 --- a/src/Config/Source/CloudSource.php +++ b/src/Config/Source/CloudSource.php @@ -89,6 +89,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 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 */ From 1357d88d8abd98e5b7119d52b05aa86a170ab869 Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 12 Mar 2020 12:49:07 +0530 Subject: [PATCH 05/11] used string instead of String --- src/Config/Source/CloudSource.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Config/Source/CloudSource.php b/src/Config/Source/CloudSource.php index bc728fd9..b2504b6f 100644 --- a/src/Config/Source/CloudSource.php +++ b/src/Config/Source/CloudSource.php @@ -197,14 +197,14 @@ private function addRelationships(Repository $repository, array $relationships): /** * @param Repository $repository - * @param String $version + * @param string $version * @param array $extensions * @param array $disabledExtensions * @return Repository */ private function addPhp( Repository $repository, - String $version, + string $version, array $extensions, array $disabledExtensions ): Repository { @@ -226,11 +226,11 @@ private function addPhp( /** * @param Repository $repository - * @param String $version + * @param string $version * @return Repository * @throws SourceException */ - private function addXdebug(Repository $repository, String $version): Repository + private function addXdebug(Repository $repository, string $version): Repository { try { $repository->set([ @@ -299,10 +299,10 @@ private function addMounts(Repository $repository, array $mounts): Repository /** * @param Repository $repository - * @param String $name + * @param string $name * @return Repository */ - private function addName(Repository $repository, String $name): Repository + private function addName(Repository $repository, string $name): Repository { $repository->set([ self::NAME => $name, From 74bbca79a67c9806f6910967d9e13b8d204c7a2d Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 12 Mar 2020 12:55:25 +0530 Subject: [PATCH 06/11] removed null validation on name --- src/Config/Source/CloudSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/Source/CloudSource.php b/src/Config/Source/CloudSource.php index b2504b6f..8880f87e 100644 --- a/src/Config/Source/CloudSource.php +++ b/src/Config/Source/CloudSource.php @@ -132,7 +132,7 @@ public function read(): Repository ); $repository = $this->addName( $repository, - $appConfig['name'] ?? [] + $appConfig['name'] ); return $repository; From c52756d8ed2fd9fcb318f108e5f44f5dbc89b14d Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 12 Mar 2020 13:33:35 +0530 Subject: [PATCH 07/11] resolved conflicts --- src/Compose/ProductionBuilder.php | 9 ++++----- src/Config/Config.php | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Compose/ProductionBuilder.php b/src/Compose/ProductionBuilder.php index 7de8ff47..2503b4cd 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -98,7 +98,6 @@ class ProductionBuilder implements BuilderInterface */ private $volumeResolver; - /** * @param ServiceFactory $serviceFactory * @param FileList $fileList @@ -108,6 +107,7 @@ class ProductionBuilder implements BuilderInterface * @param Resolver $resolver * @param VolumeResolver $volumeResolver */ + public function __construct( ServiceFactory $serviceFactory, FileList $fileList, @@ -125,7 +125,6 @@ public function __construct( $this->resolver = $resolver; $this->volumeResolver = $volumeResolver; } - /** * {@inheritdoc} * @@ -135,9 +134,7 @@ public function __construct( */ public function build(Config $config): Manager { - $volumePrefix = $config->getName() . '-'; - - $manager = $this->managerFactory->create(); + $manager = $this->managerFactory->create($config); $phpVersion = $config->getServiceVersion(ServiceInterface::SERVICE_PHP); $dbVersion = $config->getServiceVersion(ServiceInterface::SERVICE_DB); @@ -147,6 +144,8 @@ public function build(Config $config): Manager $manager->addNetwork(self::NETWORK_MAGENTO, ['driver' => 'bridge']); $manager->addNetwork(self::NETWORK_MAGENTO_BUILD, ['driver' => 'bridge']); + $volumePrefix = $config->getName() . '-'; + $volumes = [ self::VOLUME_MAGENTO => [ 'driver_opts' => [ diff --git a/src/Config/Config.php b/src/Config/Config.php index 64dbe20b..cceafc0c 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -12,7 +12,6 @@ use Magento\CloudDocker\Compose\BuilderFactory; use Magento\CloudDocker\Compose\DeveloperBuilder; use Magento\CloudDocker\Compose\ProductionBuilder; -use Magento\CloudDocker\Config\Source\CliSource; use Magento\CloudDocker\Config\Source\SourceException; use Magento\CloudDocker\Config\Source\SourceInterface; use Magento\CloudDocker\Service\ServiceInterface; @@ -294,11 +293,22 @@ public function getVariables(): array } /** - * @return String - * @throws ConfigurationMismatchException + * Returns host value or default if host not set + * + * @return string + */ + public function getHost(): string + { + return $this->get(SourceInterface::CONFIG_HOST); + } + + /** + * Returns port value or default if port not set + * + * @return string */ - public function getName(): String + public function getPort(): string { - return $this->all()->get(SourceInterface::NAME); + return $this->get(SourceInterface::CONFIG_PORT); } } From ac520925904884d8fd00e1995f8e27f9058d7feb Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 12 Mar 2020 13:46:28 +0530 Subject: [PATCH 08/11] added get name to Config --- src/Config/Config.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Config/Config.php b/src/Config/Config.php index cceafc0c..b4455450 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -311,4 +311,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); + } } From 73b25082028687b6cbb8d213203a1fdc36429a90 Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 12 Mar 2020 13:55:50 +0530 Subject: [PATCH 09/11] empty space removed --- src/Compose/DeveloperBuilder.php | 1 - src/Compose/ProductionBuilder.php | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Compose/DeveloperBuilder.php b/src/Compose/DeveloperBuilder.php index 7f3502e5..2240abf2 100644 --- a/src/Compose/DeveloperBuilder.php +++ b/src/Compose/DeveloperBuilder.php @@ -57,7 +57,6 @@ class DeveloperBuilder implements BuilderInterface */ private $extensionResolver; - /** * @param BuilderFactory $builderFactory * @param FileList $fileList diff --git a/src/Compose/ProductionBuilder.php b/src/Compose/ProductionBuilder.php index f1ce3c1c..7bd2f5b3 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -107,7 +107,6 @@ class ProductionBuilder implements BuilderInterface * @param Resolver $resolver * @param VolumeResolver $volumeResolver */ - public function __construct( ServiceFactory $serviceFactory, FileList $fileList, @@ -125,6 +124,7 @@ public function __construct( $this->resolver = $resolver; $this->volumeResolver = $volumeResolver; } + /** * {@inheritdoc} * @@ -144,8 +144,6 @@ public function build(Config $config): Manager $manager->addNetwork(self::NETWORK_MAGENTO, ['driver' => 'bridge']); $manager->addNetwork(self::NETWORK_MAGENTO_BUILD, ['driver' => 'bridge']); - $volumePrefix = $config->getName() . '-'; - $volumes = [ self::VOLUME_MAGENTO => [ 'driver_opts' => [ @@ -154,8 +152,8 @@ public function build(Config $config): Manager 'o' => 'bind' ] ], - $volumePrefix . self::VOLUME_MAGENTO_DB => [], - $volumePrefix . self::VOLUME_MARIADB_CONF => [ + self::VOLUME_MAGENTO_DB => [], + self::VOLUME_MARIADB_CONF => [ 'driver_opts' => [ 'type' => 'none', 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), @@ -242,9 +240,9 @@ public function build(Config $config): Manager 'ports' => [$dbPorts], 'volumes' => array_merge( [ - $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', + self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', - $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', + self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', ], $volumesMount ) From 1a9695e1cfd143f359aae364c0a7ce884a95ba94 Mon Sep 17 00:00:00 2001 From: Arvind Date: Fri, 13 Mar 2020 20:15:53 +0530 Subject: [PATCH 10/11] support for production mode modified .exp files --- src/Compose/ProductionBuilder.php | 10 ++++++---- .../_files/cloud_base/docker-compose.exp.yml | 8 ++++---- .../_files/cloud_base_mftf/docker-compose.exp.yml | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Compose/ProductionBuilder.php b/src/Compose/ProductionBuilder.php index 7bd2f5b3..b2455053 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -144,6 +144,8 @@ public function build(Config $config): Manager $manager->addNetwork(self::NETWORK_MAGENTO, ['driver' => 'bridge']); $manager->addNetwork(self::NETWORK_MAGENTO_BUILD, ['driver' => 'bridge']); + $volumePrefix = $config->getName() . '-'; + $volumes = [ self::VOLUME_MAGENTO => [ 'driver_opts' => [ @@ -152,8 +154,8 @@ public function build(Config $config): Manager 'o' => 'bind' ] ], - self::VOLUME_MAGENTO_DB => [], - self::VOLUME_MARIADB_CONF => [ + $volumePrefix . self::VOLUME_MAGENTO_DB => [], + $volumePrefix . self::VOLUME_MARIADB_CONF => [ 'driver_opts' => [ 'type' => 'none', 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), @@ -240,9 +242,9 @@ public function build(Config $config): Manager 'ports' => [$dbPorts], 'volumes' => array_merge( [ - 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', ], $volumesMount ) 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 d5c26df8..f0fe32f3 100644 --- a/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml +++ b/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml @@ -11,9 +11,9 @@ services: ports: - '3306' volumes: - - 'magento-db:/var/lib/mysql' + - 'mymagento-magento-db:/var/lib/mysql' - 'docker-entrypoint:/docker-entrypoint-initdb.d' - - 'mariadb-conf:/etc/mysql/mariadb.conf.d' + - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' - 'docker-mnt:/mnt:delegated' networks: magento: @@ -164,8 +164,8 @@ volumes: type: none device: '${PWD}/' o: bind - magento-db: { } - mariadb-conf: + mymagento-magento-db: { } + mymagento-mariadb-conf: driver_opts: type: none device: '${PWD}/.docker/mysql/mariadb.conf.d' 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 0b8bd7f1..0d552793 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 @@ -11,9 +11,9 @@ services: ports: - '3306' volumes: - - 'magento-db:/var/lib/mysql' + - 'mymagento-magento-db:/var/lib/mysql' - 'docker-entrypoint:/docker-entrypoint-initdb.d' - - 'mariadb-conf:/etc/mysql/mariadb.conf.d' + - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' - 'docker-mnt:/mnt:delegated' networks: magento: @@ -259,8 +259,8 @@ volumes: type: none device: '${PWD}/' o: bind - magento-db: { } - mariadb-conf: + mymagento-magento-db: { } + mymagento-mariadb-conf: driver_opts: type: none device: '${PWD}/.docker/mysql/mariadb.conf.d' From f03d9d14ce042323d183bfb7f834cbbeb65bbfae Mon Sep 17 00:00:00 2001 From: Arvind Date: Thu, 19 Mar 2020 12:31:00 +0530 Subject: [PATCH 11/11] Updated the code from dev branch --- src/Compose/DeveloperBuilder.php | 2 +- src/Compose/ProductionBuilder.php | 192 +++++++++++------- .../_files/cloud_base/docker-compose.exp.yml | 26 +-- .../cloud_base_mftf/docker-compose.exp.yml | 26 +-- 4 files changed, 148 insertions(+), 98 deletions(-) diff --git a/src/Compose/DeveloperBuilder.php b/src/Compose/DeveloperBuilder.php index 2240abf2..71c52c84 100644 --- a/src/Compose/DeveloperBuilder.php +++ b/src/Compose/DeveloperBuilder.php @@ -148,7 +148,7 @@ public function build(Config $config): Manager $volumes, [ $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', - $volumePrefix . self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', + self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', ] ) diff --git a/src/Compose/ProductionBuilder.php b/src/Compose/ProductionBuilder.php index b2455053..4c464b3e 100644 --- a/src/Compose/ProductionBuilder.php +++ b/src/Compose/ProductionBuilder.php @@ -7,6 +7,7 @@ namespace Magento\CloudDocker\Compose; +use Magento\CloudDocker\App\GenericException; use Magento\CloudDocker\App\ConfigurationMismatchException; use Magento\CloudDocker\Compose\Php\ExtensionResolver; use Magento\CloudDocker\Compose\ProductionBuilder\VolumeResolver; @@ -138,38 +139,12 @@ public function build(Config $config): Manager $phpVersion = $config->getServiceVersion(ServiceInterface::SERVICE_PHP); $dbVersion = $config->getServiceVersion(ServiceInterface::SERVICE_DB); - $hostPort = $config->getDbPortsExpose(); - $dbPorts = $hostPort ? "$hostPort:3306" : '3306'; + $cliDepends = self::$cliDepends; $manager->addNetwork(self::NETWORK_MAGENTO, ['driver' => 'bridge']); $manager->addNetwork(self::NETWORK_MAGENTO_BUILD, ['driver' => 'bridge']); - $volumePrefix = $config->getName() . '-'; - - $volumes = [ - self::VOLUME_MAGENTO => [ - 'driver_opts' => [ - 'type' => 'none', - 'device' => $this->resolver->getRootPath(), - 'o' => 'bind' - ] - ], - $volumePrefix . self::VOLUME_MAGENTO_DB => [], - $volumePrefix . self::VOLUME_MARIADB_CONF => [ - 'driver_opts' => [ - 'type' => 'none', - 'device' => $this->resolver->getRootPath('/.docker/mysql/mariadb.conf.d'), - 'o' => 'bind', - ], - ], - self::VOLUME_DOCKER_ETRYPOINT => [ - 'driver_opts' => [ - 'type' => 'none', - 'device' => $this->resolver->getRootPath('/.docker/mysql/docker-entrypoint-initdb.d'), - 'o' => 'bind' - ] - ] - ]; + $volumes = [self::VOLUME_MAGENTO => $this->getVolumeConfig()]; if ($config->hasServiceEnabled(ServiceInterface::SERVICE_SELENIUM)) { $manager->addVolume(self::VOLUME_MAGENTO_DEV, []); @@ -180,38 +155,20 @@ public function build(Config $config): Manager $hasTmpMounts = $config->hasTmpMounts(); if ($hasTmpMounts) { - $volumes[self::VOLUME_DOCKER_MNT] = [ - 'driver_opts' => [ - 'type' => 'none', - 'device' => $this->resolver->getRootPath('/.docker/mnt'), - 'o' => 'bind' - ] - ]; + $volumes[self::VOLUME_DOCKER_MNT] = $this->getVolumeConfig('/.docker/mnt'); } foreach ($this->volumeResolver->getMagentoVolumes($mounts, false, $hasSelenium) as $volumeName => $volume) { $syncConfig = []; if (!empty($volume['volume']) && $config->getSyncEngine() === self::SYNC_ENGINE_NATIVE) { - $syncConfig = [ - 'driver_opts' => [ - 'type' => 'none', - 'device' => $this->resolver->getRootPath($volume['volume']), - 'o' => 'bind' - ] - ]; + $syncConfig = $this->getVolumeConfig($volume['volume']); } $volumes[$volumeName] = $syncConfig; } if ($config->getSyncEngine() === self::SYNC_ENGINE_MOUNT) { - $volumes[self::VOLUME_MAGENTO] = [ - 'driver_opts' => [ - 'type' => 'none', - 'device' => $this->resolver->getRootPath(), - 'o' => 'bind' - ] - ]; + $volumes[self::VOLUME_MAGENTO] = $this->getVolumeConfig(); } $manager->setVolumes($volumes); @@ -233,27 +190,25 @@ public function build(Config $config): Manager $this->volumeResolver->getMountVolumes($hasTmpMounts) ); - $manager->addService( - self::SERVICE_DB, - $this->serviceFactory->create( - ServiceInterface::SERVICE_DB, - $dbVersion, - [ - 'ports' => [$dbPorts], - 'volumes' => array_merge( - [ - $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql', - self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d', - $volumePrefix . self::VOLUME_MARIADB_CONF . ':/etc/mysql/mariadb.conf.d', - ], - $volumesMount - ) - ] - ), - [self::NETWORK_MAGENTO], - [] + $volumePrefix = $config->getName() . '-'; + + $manager->addVolume( + $volumePrefix . self::VOLUME_MARIADB_CONF, + $this->getVolumeConfig('/.docker/mysql/mariadb.conf.d') ); + $this->addDbService(self::SERVICE_DB, $manager, $dbVersion, $volumesMount, $config); + + if ($config->hasServiceEnabled(ServiceInterface::SERVICE_DB_QUOTE)) { + $cliDepends = array_merge($cliDepends, [self::SERVICE_DB_QUOTE => ['condition' => 'service_started']]); + $this->addDbService(self::SERVICE_DB_QUOTE, $manager, $dbVersion, $volumesMount, $config); + } + + if ($config->hasServiceEnabled(ServiceInterface::SERVICE_DB_SALES)) { + $cliDepends = array_merge($cliDepends, [self::SERVICE_DB_SALES => ['condition' => 'service_started']]); + $this->addDbService(self::SERVICE_DB_SALES, $manager, $dbVersion, $volumesMount, $config); + } + foreach (self::$standaloneServices as $service) { if (!$config->hasServiceEnabled($service)) { continue; @@ -363,7 +318,7 @@ public function build(Config $config): Manager ['volumes' => $volumesRw] ), [self::NETWORK_MAGENTO], - self::$cliDepends + $cliDepends ); } @@ -408,7 +363,7 @@ public function build(Config $config): Manager self::SERVICE_BUILD, $this->serviceFactory->create(ServiceInterface::SERVICE_PHP_CLI, $phpVersion, ['volumes' => $volumesBuild]), [self::NETWORK_MAGENTO_BUILD], - self::$cliDepends + $cliDepends ); $manager->addService( self::SERVICE_DEPLOY, @@ -425,7 +380,7 @@ public function build(Config $config): Manager ['volumes' => $volumesRo] ), [self::NETWORK_MAGENTO], - self::$cliDepends + $cliDepends ); } @@ -470,4 +425,99 @@ public function getPath(): string { return $this->fileList->getMagentoDockerCompose(); } + + /** + * @param string $service + * @param Manager $manager + * @param string $version + * @param array $mounts + * @param Config $config + * @throws ConfigurationMismatchException + * @throws GenericException + */ + private function addDbService( + string $service, + Manager $manager, + string $version, + array $mounts, + Config $config + ) { + $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($volumePrefix . self::VOLUME_MAGENTO_DB, []); + $manager->addVolume( + self::VOLUME_DOCKER_ETRYPOINT, + $this->getVolumeConfig('/.docker/mysql/docker-entrypoint-initdb.d') + ); + + $mounts[] = $volumePrefix . self::VOLUME_MAGENTO_DB . ':/var/lib/mysql'; + $mounts[] = self::VOLUME_DOCKER_ETRYPOINT . ':/docker-entrypoint-initdb.d'; + $serviceType = ServiceInterface::SERVICE_DB; + break; + case self::SERVICE_DB_QUOTE: + $port = $config->getDbQuotePortsExpose(); + + $manager->addVolume(self::VOLUME_MAGENTO_DB_QUOTE, []); + $manager->addVolume( + self::VOLUME_DOCKER_ETRYPOINT_QUOTE, + $this->getVolumeConfig('/.docker/mysql-quote/docker-entrypoint-initdb.d') + ); + + $mounts[] = self::VOLUME_MAGENTO_DB_QUOTE . ':/var/lib/mysql'; + $mounts[] = self::VOLUME_DOCKER_ETRYPOINT_QUOTE . ':/docker-entrypoint-initdb.d'; + $serviceType = ServiceInterface::SERVICE_DB_QUOTE; + break; + case self::SERVICE_DB_SALES: + $port = $config->getDbSalesPortsExpose(); + + $manager->addVolume(self::VOLUME_MAGENTO_DB_SALES, []); + $manager->addVolume( + self::VOLUME_DOCKER_ETRYPOINT_SALES, + $this->getVolumeConfig( + '/.docker/mysql-sales/docker-entrypoint-initdb.d' + ) + ); + + $mounts[] = self::VOLUME_MAGENTO_DB_SALES . ':/var/lib/mysql'; + $mounts[] = self::VOLUME_DOCKER_ETRYPOINT_SALES . ':/docker-entrypoint-initdb.d'; + $serviceType = ServiceInterface::SERVICE_DB_SALES; + break; + default: + throw new GenericException(sprintf('Configuration for %s service not exist', $service)); + } + + $manager->addService( + $service, + $this->serviceFactory->create( + $serviceType, + $version, + [ + 'ports' => [$port ? "$port:3306" : '3306'], + 'volumes' => $mounts, + ] + ), + [self::NETWORK_MAGENTO], + [] + ); + } + + /** + * @param string $device + * @return array + */ + private function getVolumeConfig(string $device = '/'): array + { + return [ + 'driver_opts' => [ + 'type' => 'none', + 'device' => $this->resolver->getRootPath($device), + 'o' => 'bind' + ] + ]; + } } 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 f0fe32f3..a41b2146 100644 --- a/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml +++ b/src/Test/Integration/_files/cloud_base/docker-compose.exp.yml @@ -11,10 +11,10 @@ services: ports: - '3306' volumes: + - 'docker-mnt:/mnt:delegated' + - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' - 'mymagento-magento-db:/var/lib/mysql' - 'docker-entrypoint:/docker-entrypoint-initdb.d' - - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' - - 'docker-mnt:/mnt:delegated' networks: magento: aliases: @@ -164,17 +164,6 @@ volumes: type: none device: '${PWD}/' o: bind - mymagento-magento-db: { } - mymagento-mariadb-conf: - driver_opts: - type: none - device: '${PWD}/.docker/mysql/mariadb.conf.d' - o: bind - docker-entrypoint: - driver_opts: - type: none - device: '${PWD}/.docker/mysql/docker-entrypoint-initdb.d' - o: bind docker-mnt: driver_opts: type: none @@ -186,6 +175,17 @@ volumes: magento-app-etc: { } magento-pub-media: { } magento-pub-static: { } + mymagento-mariadb-conf: + driver_opts: + type: none + device: '${PWD}/.docker/mysql/mariadb.conf.d' + o: bind + mymagento-magento-db: { } + docker-entrypoint: + driver_opts: + type: none + device: '${PWD}/.docker/mysql/docker-entrypoint-initdb.d' + o: bind networks: magento: driver: bridge 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 0d552793..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 @@ -11,10 +11,10 @@ services: ports: - '3306' volumes: + - 'docker-mnt:/mnt:delegated' + - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' - 'mymagento-magento-db:/var/lib/mysql' - 'docker-entrypoint:/docker-entrypoint-initdb.d' - - 'mymagento-mariadb-conf:/etc/mysql/mariadb.conf.d' - - 'docker-mnt:/mnt:delegated' networks: magento: aliases: @@ -259,17 +259,6 @@ volumes: type: none device: '${PWD}/' o: bind - mymagento-magento-db: { } - mymagento-mariadb-conf: - driver_opts: - type: none - device: '${PWD}/.docker/mysql/mariadb.conf.d' - o: bind - docker-entrypoint: - driver_opts: - type: none - device: '${PWD}/.docker/mysql/docker-entrypoint-initdb.d' - o: bind docker-mnt: driver_opts: type: none @@ -282,6 +271,17 @@ volumes: magento-pub-media: { } magento-pub-static: { } magento-dev: { } + mymagento-mariadb-conf: + driver_opts: + type: none + device: '${PWD}/.docker/mysql/mariadb.conf.d' + o: bind + mymagento-magento-db: { } + docker-entrypoint: + driver_opts: + type: none + device: '${PWD}/.docker/mysql/docker-entrypoint-initdb.d' + o: bind networks: magento: driver: bridge