10
10
use Magento \MagentoCloud \Config \Environment ;
11
11
use Magento \MagentoCloud \Config \RepositoryFactory ;
12
12
use Magento \MagentoCloud \Docker \ComposeManagerFactory ;
13
- use Magento \MagentoCloud \Docker \ComposeManagerInterface ;
14
13
use Magento \MagentoCloud \Docker \Config \DistGenerator ;
15
14
use Magento \MagentoCloud \Docker \ConfigurationMismatchException ;
15
+ use Magento \MagentoCloud \Docker \Service \Config ;
16
+ use Magento \MagentoCloud \Docker \Service \Version \Validator as VersionValidator ;
16
17
use Magento \MagentoCloud \Filesystem \Driver \File ;
17
18
use Magento \MagentoCloud \Filesystem \FileSystemException ;
18
19
use Symfony \Component \Console \Command \Command ;
19
20
use Symfony \Component \Console \Input \ArrayInput ;
20
21
use Symfony \Component \Console \Input \InputInterface ;
21
22
use Symfony \Component \Console \Input \InputOption ;
22
23
use Symfony \Component \Console \Output \OutputInterface ;
24
+ use Symfony \Component \Console \Question \ConfirmationQuestion ;
23
25
use Symfony \Component \Yaml \Yaml ;
24
26
25
27
/**
30
32
class Build extends Command
31
33
{
32
34
const NAME = 'docker:build ' ;
35
+
33
36
const OPTION_PHP = 'php ' ;
34
37
const OPTION_NGINX = 'nginx ' ;
35
38
const OPTION_DB = 'db ' ;
@@ -63,24 +66,40 @@ class Build extends Command
63
66
*/
64
67
private $ distGenerator ;
65
68
69
+ /**
70
+ * @var Config
71
+ */
72
+ private $ serviceConfig ;
73
+
74
+ /**
75
+ * @var VersionValidator
76
+ */
77
+ private $ versionValidator ;
78
+
66
79
/**
67
80
* @param ComposeManagerFactory $builderFactory
68
81
* @param File $file
69
82
* @param Environment $environment
70
83
* @param RepositoryFactory $configFactory
84
+ * @param Config $serviceConfig
85
+ * @param VersionValidator $versionValidator
71
86
* @param DistGenerator $distGenerator
72
87
*/
73
88
public function __construct (
74
89
ComposeManagerFactory $ builderFactory ,
75
90
File $ file ,
76
91
Environment $ environment ,
77
92
RepositoryFactory $ configFactory ,
93
+ Config $ serviceConfig ,
94
+ VersionValidator $ versionValidator ,
78
95
DistGenerator $ distGenerator
79
96
) {
80
97
$ this ->builderFactory = $ builderFactory ;
81
98
$ this ->file = $ file ;
82
99
$ this ->environment = $ environment ;
83
100
$ this ->configFactory = $ configFactory ;
101
+ $ this ->serviceConfig = $ serviceConfig ;
102
+ $ this ->versionValidator = $ versionValidator ;
84
103
$ this ->distGenerator = $ distGenerator ;
85
104
86
105
parent ::__construct ();
@@ -140,8 +159,9 @@ protected function configure()
140
159
/**
141
160
* {@inheritdoc}
142
161
*
143
- * @throws FileSystemException
144
162
* @throws ConfigurationMismatchException
163
+ * @throws FileSystemException
164
+ * @throws \Magento\MagentoCloud\Package\UndefinedPackageException
145
165
*/
146
166
public function execute (InputInterface $ input , OutputInterface $ output )
147
167
{
@@ -151,12 +171,12 @@ public function execute(InputInterface $input, OutputInterface $output)
151
171
$ config = $ this ->configFactory ->create ();
152
172
153
173
$ 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 ,
160
180
];
161
181
162
182
array_walk ($ map , static function ($ key , $ option ) use ($ config , $ input ) {
@@ -165,6 +185,22 @@ public function execute(InputInterface $input, OutputInterface $output)
165
185
}
166
186
});
167
187
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
+
168
204
$ this ->file ->filePutContents (
169
205
$ builder ->getConfigPath (),
170
206
Yaml::dump ($ builder ->build ($ config ), 4 , 2 , Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK )
0 commit comments