Skip to content

Commit fc190cc

Browse files
NadiyaSshiftedreality
authored andcommitted
MAGECLOUD-3251: Add Interactive Service Compatibility Validation (#472)
1 parent 25aa23a commit fc190cc

File tree

13 files changed

+839
-243
lines changed

13 files changed

+839
-243
lines changed

src/Command/Docker/Build.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
use Magento\MagentoCloud\Config\Environment;
1111
use Magento\MagentoCloud\Config\RepositoryFactory;
1212
use Magento\MagentoCloud\Docker\ComposeManagerFactory;
13-
use Magento\MagentoCloud\Docker\ComposeManagerInterface;
1413
use Magento\MagentoCloud\Docker\Config\DistGenerator;
1514
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
15+
use Magento\MagentoCloud\Docker\Service\Config;
16+
use Magento\MagentoCloud\Docker\Service\Version\Validator as VersionValidator;
1617
use Magento\MagentoCloud\Filesystem\Driver\File;
1718
use Magento\MagentoCloud\Filesystem\FileSystemException;
1819
use Symfony\Component\Console\Command\Command;
1920
use Symfony\Component\Console\Input\ArrayInput;
2021
use Symfony\Component\Console\Input\InputInterface;
2122
use Symfony\Component\Console\Input\InputOption;
2223
use Symfony\Component\Console\Output\OutputInterface;
24+
use Symfony\Component\Console\Question\ConfirmationQuestion;
2325
use Symfony\Component\Yaml\Yaml;
2426

2527
/**
@@ -30,6 +32,7 @@
3032
class Build extends Command
3133
{
3234
const NAME = 'docker:build';
35+
3336
const OPTION_PHP = 'php';
3437
const OPTION_NGINX = 'nginx';
3538
const OPTION_DB = 'db';
@@ -63,24 +66,40 @@ class Build extends Command
6366
*/
6467
private $distGenerator;
6568

69+
/**
70+
* @var Config
71+
*/
72+
private $serviceConfig;
73+
74+
/**
75+
* @var VersionValidator
76+
*/
77+
private $versionValidator;
78+
6679
/**
6780
* @param ComposeManagerFactory $builderFactory
6881
* @param File $file
6982
* @param Environment $environment
7083
* @param RepositoryFactory $configFactory
84+
* @param Config $serviceConfig
85+
* @param VersionValidator $versionValidator
7186
* @param DistGenerator $distGenerator
7287
*/
7388
public function __construct(
7489
ComposeManagerFactory $builderFactory,
7590
File $file,
7691
Environment $environment,
7792
RepositoryFactory $configFactory,
93+
Config $serviceConfig,
94+
VersionValidator $versionValidator,
7895
DistGenerator $distGenerator
7996
) {
8097
$this->builderFactory = $builderFactory;
8198
$this->file = $file;
8299
$this->environment = $environment;
83100
$this->configFactory = $configFactory;
101+
$this->serviceConfig = $serviceConfig;
102+
$this->versionValidator = $versionValidator;
84103
$this->distGenerator = $distGenerator;
85104

86105
parent::__construct();
@@ -140,8 +159,9 @@ protected function configure()
140159
/**
141160
* {@inheritdoc}
142161
*
143-
* @throws FileSystemException
144162
* @throws ConfigurationMismatchException
163+
* @throws FileSystemException
164+
* @throws \Magento\MagentoCloud\Package\UndefinedPackageException
145165
*/
146166
public function execute(InputInterface $input, OutputInterface $output)
147167
{
@@ -151,12 +171,12 @@ public function execute(InputInterface $input, OutputInterface $output)
151171
$config = $this->configFactory->create();
152172

153173
$map = [
154-
self::OPTION_PHP => ComposeManagerInterface::PHP_VERSION,
155-
self::OPTION_DB => ComposeManagerInterface::DB_VERSION,
156-
self::OPTION_NGINX => ComposeManagerInterface::NGINX_VERSION,
157-
self::OPTION_REDIS => ComposeManagerInterface::REDIS_VERSION,
158-
self::OPTION_ES => ComposeManagerInterface::ES_VERSION,
159-
self::OPTION_RABBIT_MQ => ComposeManagerInterface::RABBIT_MQ_VERSION,
174+
self::OPTION_PHP => Config::KEY_PHP,
175+
self::OPTION_DB => Config::KEY_DB,
176+
self::OPTION_NGINX => Config::KEY_NGINX,
177+
self::OPTION_REDIS => Config::KEY_REDIS,
178+
self::OPTION_ES => Config::KEY_ELASTICSEARCH,
179+
self::OPTION_RABBIT_MQ => Config::KEY_RABBITMQ,
160180
];
161181

162182
array_walk($map, static function ($key, $option) use ($config, $input) {
@@ -165,6 +185,22 @@ public function execute(InputInterface $input, OutputInterface $output)
165185
}
166186
});
167187

188+
$versionList = $this->serviceConfig->getAllServiceVersions($config);
189+
190+
$unsupportedErrorMsg = $this->versionValidator->validateVersions($versionList);
191+
192+
$helper = $this->getHelper('question');
193+
$question = new ConfirmationQuestion(
194+
'There are some service versions which are not supported'
195+
. ' by current Magento version:' . "\n" . implode("\n", $unsupportedErrorMsg) . "\n"
196+
. 'Do you want to continue?[y/N]',
197+
false
198+
);
199+
200+
if ($unsupportedErrorMsg && !$helper->ask($input, $output, $question) && $input->isInteractive()) {
201+
return null;
202+
}
203+
168204
$this->file->filePutContents(
169205
$builder->getConfigPath(),
170206
Yaml::dump($builder->build($config), 4, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK)

src/Docker/Compose/ProductionCompose.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Magento\MagentoCloud\Docker\Compose;
99

1010
use Illuminate\Contracts\Config\Repository;
11-
use Magento\MagentoCloud\Docker\Config;
11+
use Magento\MagentoCloud\Docker\Service\Config;
1212
use Magento\MagentoCloud\Docker\ComposeManagerInterface;
1313
use Magento\MagentoCloud\Docker\Config\Converter;
1414
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
@@ -75,8 +75,8 @@ public function __construct(
7575
*/
7676
public function build(Repository $config): array
7777
{
78-
$phpVersion = $config->get(self::PHP_VERSION, '') ?: $this->config->getPhpVersion();
79-
$dbVersion = $config->get(self::DB_VERSION, '') ?: $this->config->getServiceVersion(Config::KEY_DB);
78+
$phpVersion = $config->get(Config::KEY_PHP, '') ?: $this->config->getPhpVersion();
79+
$dbVersion = $config->get(Config::KEY_DB, '') ?: $this->config->getServiceVersion(Config::KEY_DB);
8080

8181
$services = [
8282
'db' => $this->serviceFactory->create(
@@ -98,7 +98,7 @@ public function build(Repository $config): array
9898
)
9999
];
100100

101-
$redisVersion = $config->get(self::REDIS_VERSION) ?: $this->config->getServiceVersion(Config::KEY_REDIS);
101+
$redisVersion = $config->get(Config::KEY_REDIS) ?: $this->config->getServiceVersion(Config::KEY_REDIS);
102102

103103
if ($redisVersion) {
104104
$services['redis'] = $this->serviceFactory->create(
@@ -107,7 +107,8 @@ public function build(Repository $config): array
107107
);
108108
}
109109

110-
$esVersion = $config->get(self::ES_VERSION) ?: $this->config->getServiceVersion(Config::KEY_ELASTICSEARCH);
110+
$esVersion = $config->get(Config::KEY_ELASTICSEARCH)
111+
?: $this->config->getServiceVersion(Config::KEY_ELASTICSEARCH);
111112

112113
if ($esVersion) {
113114
$services['elasticsearch'] = $this->serviceFactory->create(
@@ -116,8 +117,8 @@ public function build(Repository $config): array
116117
);
117118
}
118119

119-
$rabbitMQVersion = $config->get(self::RABBIT_MQ_VERSION)
120-
?: $this->config->getServiceVersion(Config::KEY_RABBIT_MQ);
120+
$rabbitMQVersion = $config->get(Config::KEY_RABBITMQ)
121+
?: $this->config->getServiceVersion(Config::KEY_RABBITMQ);
121122

122123
if ($rabbitMQVersion) {
123124
$services['rabbitmq'] = $this->serviceFactory->create(
@@ -142,7 +143,7 @@ public function build(Repository $config): array
142143
$services['deploy'] = $this->getCliService($phpVersion, true, $cliDepends, 'deploy.magento2.docker');
143144
$services['web'] = $this->serviceFactory->create(
144145
ServiceFactory::SERVICE_NGINX,
145-
$config->get(self::NGINX_VERSION, self::DEFAULT_NGINX_VERSION),
146+
$config->get(Config::KEY_NGINX, self::DEFAULT_NGINX_VERSION),
146147
[
147148
'depends_on' => ['fpm'],
148149
'extends' => 'generic',

src/Docker/Config.php

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/Docker/Config/Relationship.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\MagentoCloud\Docker\Config;
77

8-
use Magento\MagentoCloud\Docker\Config;
8+
use Magento\MagentoCloud\Docker\Service\Config;
99
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
1010

1111
/**

0 commit comments

Comments
 (0)