Skip to content

Commit 4128349

Browse files
MAGECLOUD-3511: [Cloud Docker] Add development configuration (#448)
1 parent 4722cd4 commit 4128349

19 files changed

+427
-448
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@
8989
"dist/docker/mysql",
9090
"docker/mysql"
9191
],
92-
[
93-
"dist/docker/global.php",
94-
"docker/global.php.dist"
95-
],
9692
[
9793
"dist/docker/README.md",
9894
"docker/README.md"
95+
],
96+
[
97+
"dist/docker-sync.yml",
98+
"docker-sync.yml"
9999
]
100100
]
101101
}

dist/docker-sync.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 2
2+
syncs:
3+
magento:
4+
src: './'
5+
sync_excludes: ['.git', '.idea']

dist/docker/global.php

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

src/Command/Docker/Build.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\MagentoCloud\Config\Environment;
1111
use Magento\MagentoCloud\Config\RepositoryFactory;
12-
use Magento\MagentoCloud\Docker\BuilderFactory;
13-
use Magento\MagentoCloud\Docker\BuilderInterface;
12+
use Magento\MagentoCloud\Docker\ComposeManagerFactory;
13+
use Magento\MagentoCloud\Docker\ComposeManagerInterface;
1414
use Magento\MagentoCloud\Docker\Config\DistGenerator;
1515
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
1616
use Magento\MagentoCloud\Filesystem\Driver\File;
@@ -36,9 +36,10 @@ class Build extends Command
3636
const OPTION_REDIS = 'redis';
3737
const OPTION_ES = 'es';
3838
const OPTION_RABBIT_MQ = 'rmq';
39+
const OPTION_MODE = 'mode';
3940

4041
/**
41-
* @var BuilderFactory
42+
* @var ComposeManagerFactory
4243
*/
4344
private $builderFactory;
4445

@@ -63,14 +64,14 @@ class Build extends Command
6364
private $distGenerator;
6465

6566
/**
66-
* @param BuilderFactory $builderFactory
67+
* @param ComposeManagerFactory $builderFactory
6768
* @param File $file
6869
* @param Environment $environment
6970
* @param RepositoryFactory $configFactory
7071
* @param DistGenerator $distGenerator
7172
*/
7273
public function __construct(
73-
BuilderFactory $builderFactory,
74+
ComposeManagerFactory $builderFactory,
7475
File $file,
7576
Environment $environment,
7677
RepositoryFactory $configFactory,
@@ -122,6 +123,15 @@ protected function configure()
122123
null,
123124
InputOption::VALUE_OPTIONAL,
124125
'RabbitMQ version'
126+
)->addOption(
127+
self::OPTION_MODE,
128+
'm',
129+
InputOption::VALUE_OPTIONAL,
130+
sprintf(
131+
'Mode of environment (%s)',
132+
implode(', ', [ComposeManagerFactory::COMPOSE_DEVELOPER, ComposeManagerFactory::COMPOSE_PRODUCTION])
133+
),
134+
ComposeManagerFactory::COMPOSE_PRODUCTION
125135
);
126136

127137
parent::configure();
@@ -135,19 +145,21 @@ protected function configure()
135145
*/
136146
public function execute(InputInterface $input, OutputInterface $output)
137147
{
138-
$builder = $this->builderFactory->create(BuilderFactory::BUILDER_DEV);
148+
$type = $input->getOption(self::OPTION_MODE);
149+
150+
$builder = $this->builderFactory->create($type);
139151
$config = $this->configFactory->create();
140152

141153
$map = [
142-
self::OPTION_PHP => BuilderInterface::PHP_VERSION,
143-
self::OPTION_DB => BuilderInterface::DB_VERSION,
144-
self::OPTION_NGINX => BuilderInterface::NGINX_VERSION,
145-
self::OPTION_REDIS => BuilderInterface::REDIS_VERSION,
146-
self::OPTION_ES => BuilderInterface::ES_VERSION,
147-
self::OPTION_RABBIT_MQ => BuilderInterface::RABBIT_MQ_VERSION,
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,
148160
];
149161

150-
array_walk($map, function ($key, $option) use ($config, $input) {
162+
array_walk($map, static function ($key, $option) use ($config, $input) {
151163
if ($value = $input->getOption($option)) {
152164
$config->set($key, $value);
153165
}
@@ -160,9 +172,13 @@ public function execute(InputInterface $input, OutputInterface $output)
160172

161173
$this->distGenerator->generate();
162174

163-
$this->getApplication()
164-
->find(ConfigConvert::NAME)
165-
->run(new ArrayInput([]), $output);
175+
try {
176+
$this->getApplication()
177+
->find(ConfigConvert::NAME)
178+
->run(new ArrayInput([]), $output);
179+
} catch (\Exception $exception) {
180+
throw new ConfigurationMismatchException($exception->getMessage(), $exception->getCode(), $exception);
181+
}
166182

167183
$output->writeln('<info>Configuration was built.</info>');
168184
}

src/Command/Docker/BuildIntegration.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\MagentoCloud\Config\Environment;
1111
use Magento\MagentoCloud\Config\RepositoryFactory;
12-
use Magento\MagentoCloud\Docker\BuilderFactory;
13-
use Magento\MagentoCloud\Docker\BuilderInterface;
12+
use Magento\MagentoCloud\Docker\ComposeManagerFactory;
13+
use Magento\MagentoCloud\Docker\ComposeManagerInterface;
1414
use Magento\MagentoCloud\Docker\ConfigurationMismatchException;
1515
use Magento\MagentoCloud\Filesystem\Driver\File;
1616
use Magento\MagentoCloud\Filesystem\FileSystemException;
@@ -35,7 +35,7 @@ class BuildIntegration extends Command
3535
const OPTION_DB = 'db';
3636

3737
/**
38-
* @var BuilderFactory
38+
* @var ComposeManagerFactory
3939
*/
4040
private $builderFactory;
4141

@@ -55,13 +55,13 @@ class BuildIntegration extends Command
5555
private $environment;
5656

5757
/**
58-
* @param BuilderFactory $builderFactory
58+
* @param ComposeManagerFactory $builderFactory
5959
* @param File $file
6060
* @param RepositoryFactory $configFactory
6161
* @param Environment $environment
6262
*/
6363
public function __construct(
64-
BuilderFactory $builderFactory,
64+
ComposeManagerFactory $builderFactory,
6565
File $file,
6666
RepositoryFactory $configFactory,
6767
Environment $environment
@@ -86,8 +86,8 @@ protected function configure()
8686
InputArgument::REQUIRED,
8787
sprintf(
8888
'Version of integration framework configuration (%s/%s)',
89-
BuilderFactory::BUILDER_TEST_V1,
90-
BuilderFactory::BUILDER_TEST_V2
89+
ComposeManagerFactory::COMPOSE_TEST_V1,
90+
ComposeManagerFactory::COMPOSE_TEST_V2
9191
)
9292
)->addOption(
9393
self::OPTION_PHP,
@@ -121,18 +121,19 @@ protected function configure()
121121
public function execute(InputInterface $input, OutputInterface $output)
122122
{
123123
$strategy = $input->getArgument(self::ARGUMENT_VERSION);
124+
$allowedStrategies = [ComposeManagerFactory::COMPOSE_TEST_V1, ComposeManagerFactory::COMPOSE_TEST_V2];
124125

125-
if (!in_array($strategy, [BuilderFactory::BUILDER_TEST_V1, BuilderFactory::BUILDER_TEST_V2], true)) {
126+
if (!in_array($strategy, $allowedStrategies, true)) {
126127
throw new ConfigurationMismatchException('Wrong framework version');
127128
}
128129

129130
$builder = $this->builderFactory->create($strategy);
130131
$config = $this->configFactory->create();
131132

132133
$map = [
133-
self::OPTION_PHP => BuilderInterface::PHP_VERSION,
134-
self::OPTION_DB => BuilderInterface::DB_VERSION,
135-
self::OPTION_NGINX => BuilderInterface::NGINX_VERSION,
134+
self::OPTION_PHP => ComposeManagerInterface::PHP_VERSION,
135+
self::OPTION_DB => ComposeManagerInterface::DB_VERSION,
136+
self::OPTION_NGINX => ComposeManagerInterface::NGINX_VERSION,
136137
];
137138

138139
array_walk($map, function ($key, $option) use ($config, $input) {

src/Command/Docker/ConfigConvert.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\MagentoCloud\Command\Docker;
77

8+
use Magento\MagentoCloud\Docker\Config\Converter;
89
use Magento\MagentoCloud\Filesystem\Driver\File;
910
use Magento\MagentoCloud\Filesystem\FileSystemException;
1011
use Magento\MagentoCloud\Filesystem\SystemList;
@@ -24,7 +25,6 @@ class ConfigConvert extends Command
2425
*/
2526
private static $map = [
2627
'/docker/config.php' => '/docker/config.env',
27-
'/docker/global.php' => '/docker/global.env',
2828
];
2929

3030
/**
@@ -37,14 +37,21 @@ class ConfigConvert extends Command
3737
*/
3838
private $file;
3939

40+
/**
41+
* @var Converter
42+
*/
43+
private $converter;
44+
4045
/**
4146
* @param SystemList $directoryList
4247
* @param File $file
48+
* @param Converter $converter
4349
*/
44-
public function __construct(SystemList $directoryList, File $file)
50+
public function __construct(SystemList $directoryList, File $file, Converter $converter)
4551
{
4652
$this->systemList = $directoryList;
4753
$this->file = $file;
54+
$this->converter = $converter;
4855

4956
parent::__construct();
5057
}
@@ -84,12 +91,11 @@ public function execute(InputInterface $input, OutputInterface $output)
8491
$this->file->deleteFile($envPath);
8592
}
8693

87-
$content = '';
94+
$content = $this->converter->convert(
95+
$this->file->requireFile($sourcePath)
96+
);
8897

89-
foreach ($this->file->requireFile($sourcePath) as $variable => $value) {
90-
$formattedValue = is_bool($value) ? var_export($value, true) : $value;
91-
$content .= $variable . '=' . $formattedValue . PHP_EOL;
92-
}
98+
$content = implode(PHP_EOL, $content);
9399

94100
$this->file->filePutContents($envPath, $content);
95101
}

src/Docker/BuilderFactory.php

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Docker\Compose;
7+
8+
use Illuminate\Contracts\Config\Repository;
9+
10+
/**
11+
* Developer compose configuration.
12+
*
13+
* @codeCoverageIgnore
14+
*/
15+
class DeveloperCompose extends ProductionCompose
16+
{
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function build(Repository $config): array
21+
{
22+
$compose = parent::build($config);
23+
$compose['volumes'] = [
24+
'magento' => [
25+
'external' => true
26+
]
27+
];
28+
29+
return $compose;
30+
}
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
protected function getMagentoVolumes(bool $isReadOnly): array
36+
{
37+
return [
38+
'magento:' . self::DIR_MAGENTO . ':nocopy'
39+
];
40+
}
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
protected function getVariables(): array
46+
{
47+
$variables = parent::getVariables();
48+
$variables['MAGENTO_RUN_MODE'] = 'developer';
49+
50+
return $variables;
51+
}
52+
}

src/Docker/IntegrationV1Builder.php renamed to src/Docker/Compose/IntegrationV1Compose.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\MagentoCloud\Docker;
8+
namespace Magento\MagentoCloud\Docker\Compose;
99

1010
use Illuminate\Contracts\Config\Repository;
11+
use Magento\MagentoCloud\Docker\ComposeManagerInterface;
1112
use Magento\MagentoCloud\Docker\Service\ServiceFactory;
1213
use Magento\MagentoCloud\Filesystem\FileList;
1314

@@ -16,7 +17,7 @@
1617
*
1718
* @codeCoverageIgnore
1819
*/
19-
class IntegrationV1Builder implements BuilderInterface
20+
class IntegrationV1Compose implements ComposeManagerInterface
2021
{
2122
/**
2223
* @var FileList

0 commit comments

Comments
 (0)