Skip to content

Commit d8aad29

Browse files
MCLOUD-7470: Integrate local devbox capabilities (#28)
1 parent fea0ee7 commit d8aad29

File tree

29 files changed

+293
-50
lines changed

29 files changed

+293
-50
lines changed

config/services.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
<service id="Magento\CloudDocker\App\ConfigurationMismatchException" autowire="false"/>
5252
<service id="Magento\CloudDocker\App\GenericException" autowire="false"/>
5353
<service id="Magento\CloudDocker\Compose\DeveloperBuilder" shared="false"/>
54-
<service id="Magento\CloudDocker\Config\Config" autowire="false"/>
5554
<service id="Magento\CloudDocker\Config\Source\CliSource" autowire="false"/>
5655
<service id="Magento\CloudDocker\Config\Source\CustomSource" autowire="false"/>
5756
<service id="Composer\Semver\VersionParser"/>

src/Command/BuildCompose.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ protected function configure(): void
305305
null,
306306
InputOption::VALUE_REQUIRED,
307307
'"auto_increment_offset" database variable'
308+
)->addOption(
309+
Source\CliSource::OPTION_ROOT_DIR,
310+
null,
311+
InputOption::VALUE_REQUIRED,
312+
'Root directory'
308313
);
309314

310315
parent::configure();

src/Compose/BuilderInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ interface BuilderInterface
3939
public const NETWORK_MAGENTO = 'magento';
4040
public const NETWORK_MAGENTO_BUILD = 'magento-build';
4141

42-
public const VOLUME_MAGENTO = '.';
4342
public const VOLUME_DOCKER_MNT = '.docker/mnt';
4443
public const VOLUME_MARIADB_CONF = '.docker/mysql/mariadb.conf.d';
4544
public const VOLUME_MAGENTO_VENDOR = 'magento-vendor';
4645
public const VOLUME_MAGENTO_GENERATED = 'magento-generated';
4746
public const VOLUME_MAGENTO_DB = 'magento-db';
4847
public const VOLUME_MAGENTO_DB_QUOTE = 'magento-db-quote';
4948
public const VOLUME_MAGENTO_DB_SALES = 'magento-db-sales';
50-
public const VOLUME_MAGENTO_DEV = './dev';
5149
public const VOLUME_DOCKER_ENTRYPOINT = '.docker/mysql/docker-entrypoint-initdb.d';
5250
public const VOLUME_DOCKER_ENTRYPOINT_QUOTE = '.docker/mysql-quote/docker-entrypoint-initdb.d';
5351
public const VOLUME_DOCKER_ENTRYPOINT_SALES = '.docker/mysql-sales/docker-entrypoint-initdb.d';

src/Compose/DeveloperBuilder.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CloudDocker\Compose;
99

1010
use Magento\CloudDocker\Compose\Php\ExtensionResolver;
11+
use Magento\CloudDocker\Compose\ProductionBuilder\VolumeResolver;
1112
use Magento\CloudDocker\Config\Config;
1213
use Magento\CloudDocker\Config\Environment\Converter;
1314
use Magento\CloudDocker\Filesystem\FileList;
@@ -51,22 +52,30 @@ class DeveloperBuilder implements BuilderInterface
5152
*/
5253
private $extensionResolver;
5354

55+
/**
56+
* @var VolumeResolver
57+
*/
58+
private $volumeResolver;
59+
5460
/**
5561
* @param BuilderFactory $builderFactory
5662
* @param FileList $fileList
5763
* @param Converter $converter
5864
* @param ExtensionResolver $extensionResolver
65+
* @param VolumeResolver $volumeResolver
5966
*/
6067
public function __construct(
6168
BuilderFactory $builderFactory,
6269
FileList $fileList,
6370
Converter $converter,
64-
ExtensionResolver $extensionResolver
71+
ExtensionResolver $extensionResolver,
72+
VolumeResolver $volumeResolver
6573
) {
6674
$this->builderFactory = $builderFactory;
6775
$this->fileList = $fileList;
6876
$this->converter = $converter;
6977
$this->extensionResolver = $extensionResolver;
78+
$this->volumeResolver = $volumeResolver;
7079
}
7180

7281
/**
@@ -87,7 +96,7 @@ public function build(Config $config): Manager
8796
$volumePrefix . self::VOLUME_MAGENTO_DB => []
8897
];
8998

90-
$volumes = [self::VOLUME_MAGENTO . ':' . self::DIR_MAGENTO . ':delegated'];
99+
$volumes = [$this->volumeResolver->getMagentoVolume($config) . ':' . self::DIR_MAGENTO . ':delegated'];
91100

92101
if (in_array($syncEngine, [self::SYNC_ENGINE_MUTAGEN, self::SYNC_ENGINE_DOCKER_SYNC], true)) {
93102
$volumesList[$volumePrefix . self::VOLUME_MAGENTO_SYNC] = $syncEngine === self::SYNC_ENGINE_DOCKER_SYNC

src/Compose/ProductionBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ private function hasServiceEnabled(ServiceBuilderInterface $service, Config $con
152152
BuilderInterface::SERVICE_DB_QUOTE,
153153
BuilderInterface::SERVICE_DB_SALES,
154154
];
155-
$service = in_array($service->getName(), $serviceNames) ? $service->getServiceName() : $service->getName();
156155

157-
return $config->hasServiceEnabled($service);
156+
return $config->hasServiceEnabled(
157+
in_array($service->getName(), $serviceNames, true) ? $service->getServiceName() : $service->getName()
158+
);
158159
}
159160
}

src/Compose/ProductionBuilder/Service/ElasticSearch.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ public function getServiceName(): string
5454
*/
5555
public function getConfig(Config $config): array
5656
{
57-
$esEnvVars = [];
57+
$esEnvVars = [
58+
'cluster.name=docker-cluster',
59+
'bootstrap.memory_lock=true'
60+
];
5861

5962
if (!empty($config->get(SourceInterface::SERVICES_ES_VARS))) {
60-
$esEnvVars = $config->get(SourceInterface::SERVICES_ES_VARS);
63+
$esEnvVars = array_merge($esEnvVars, $config->get(SourceInterface::SERVICES_ES_VARS));
6164
}
6265

6366
if (!empty($plugins = $config->get(SourceInterface::SERVICES_ES_PLUGINS)) && is_array($plugins)) {

src/Compose/ProductionBuilder/Volume.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function __construct(VolumeResolver $volumeResolver)
4040
public function getRo(Config $config): array
4141
{
4242
return $this->volumeResolver->normalize(array_merge(
43-
$this->volumeResolver->getRootVolume(true),
44-
$this->volumeResolver->getDevVolumes($config->hasServiceEnabled(ServiceInterface::SERVICE_TEST)),
43+
$this->volumeResolver->getRootVolume($config, true),
44+
$this->volumeResolver->getDevVolumes($config, $config->hasServiceEnabled(ServiceInterface::SERVICE_TEST)),
4545
$this->volumeResolver->getMagentoVolumes($config->getMounts(), true, $this->hasGenerated($config)),
4646
$this->volumeResolver->getMountVolumes($config->hasTmpMounts())
4747
));
@@ -57,8 +57,8 @@ public function getRo(Config $config): array
5757
public function getRw(Config $config): array
5858
{
5959
return $this->volumeResolver->normalize(array_merge(
60-
$this->volumeResolver->getRootVolume(false),
61-
$this->volumeResolver->getDevVolumes($config->hasServiceEnabled(ServiceInterface::SERVICE_TEST)),
60+
$this->volumeResolver->getRootVolume($config, false),
61+
$this->volumeResolver->getDevVolumes($config, $config->hasServiceEnabled(ServiceInterface::SERVICE_TEST)),
6262
$this->volumeResolver->getMagentoVolumes($config->getMounts(), false, $this->hasGenerated($config)),
6363
$this->volumeResolver->getMountVolumes($config->hasTmpMounts()),
6464
$this->volumeResolver->getComposerVolumes()
@@ -75,7 +75,7 @@ public function getRw(Config $config): array
7575
public function getBuild(Config $config): array
7676
{
7777
return $this->volumeResolver->normalize(array_merge(
78-
$this->volumeResolver->getRootVolume(false),
78+
$this->volumeResolver->getRootVolume($config, false),
7979
$this->volumeResolver->getDefaultMagentoVolumes(false, $this->hasGenerated($config)),
8080
$this->volumeResolver->getComposerVolumes()
8181
));

src/Compose/ProductionBuilder/VolumeResolver.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@
77

88
namespace Magento\CloudDocker\Compose\ProductionBuilder;
99

10+
use Magento\CloudDocker\App\ConfigurationMismatchException;
1011
use Magento\CloudDocker\Compose\BuilderInterface;
12+
use Magento\CloudDocker\Config\Config;
1113

1214
/**
1315
* Resolves the volume definitions.
1416
*/
1517
class VolumeResolver
1618
{
17-
public function getRootVolume(bool $isReadOnly): array
19+
/**
20+
* @param Config $config
21+
* @param bool $isReadOnly
22+
* @return array[]
23+
*/
24+
public function getRootVolume(Config $config, bool $isReadOnly): array
1825
{
1926
$mode = $isReadOnly ? 'ro,delegated' : 'rw,delegated';
2027

2128
return [
22-
BuilderInterface::VOLUME_MAGENTO => [
29+
$this->getMagentoVolume($config) => [
2330
'path' => BuilderInterface::DIR_MAGENTO,
2431
'volume' => '/',
2532
'mode' => $mode
@@ -28,14 +35,15 @@ public function getRootVolume(bool $isReadOnly): array
2835
}
2936

3037
/**
38+
* @param Config $config
3139
* @param bool $hasTest
3240
* @return array
3341
*/
34-
public function getDevVolumes(bool $hasTest): array
42+
public function getDevVolumes(Config $config, bool $hasTest): array
3543
{
3644
if ($hasTest) {
3745
return [
38-
BuilderInterface::VOLUME_MAGENTO_DEV => [
46+
$this->getMagentoDevVolume($config) => [
3947
'path' => BuilderInterface::DIR_MAGENTO . '/dev',
4048
'volume' => '/dev',
4149
'mode' => 'rw,delegated'
@@ -153,4 +161,24 @@ public function normalize(array $volumes): array
153161

154162
return $normalized;
155163
}
164+
165+
/**
166+
* @param Config $config
167+
* @return string
168+
* @throws ConfigurationMismatchException
169+
*/
170+
public function getMagentoVolume(Config $config): string
171+
{
172+
return $config->getRootDirectory();
173+
}
174+
175+
/**
176+
* @param Config $config
177+
* @return string
178+
* @throws ConfigurationMismatchException
179+
*/
180+
public function getMagentoDevVolume(Config $config): string
181+
{
182+
return $config->getRootDirectory() . '/dev';
183+
}
156184
}

src/Config/Config.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\CloudDocker\Compose\ProductionBuilder;
1515
use Magento\CloudDocker\Config\Source\SourceException;
1616
use Magento\CloudDocker\Config\Source\SourceInterface;
17+
use Magento\CloudDocker\Filesystem\DirectoryList;
1718
use Magento\CloudDocker\Service\ServiceInterface;
1819

1920
/**
@@ -31,6 +32,11 @@ class Config
3132
*/
3233
private $data;
3334

35+
/**
36+
* @var DirectoryList
37+
*/
38+
private $directoryList;
39+
3440
/**
3541
* Available engines per mode
3642
*
@@ -42,10 +48,12 @@ class Config
4248
];
4349

4450
/**
51+
* @param DirectoryList $directoryList
4552
* @param SourceInterface[] $sources
4653
*/
47-
public function __construct(array $sources = [])
54+
public function __construct(DirectoryList $directoryList, array $sources = [])
4855
{
56+
$this->directoryList = $directoryList;
4957
$this->sources = $sources;
5058
$this->data = new Repository();
5159
}
@@ -401,11 +409,17 @@ public function getTlsPort(): string
401409
*/
402410
public function getName(): string
403411
{
404-
if (!$this->all()->has(SourceInterface::NAME)) {
412+
$name = $this->all()->get(SourceInterface::NAME);
413+
414+
if (!$name) {
415+
$name = str_replace(['.'], ['-'], basename($this->directoryList->getMagentoRoot()));
416+
}
417+
418+
if (!$name) {
405419
throw new ConfigurationMismatchException('Required parameter "name" is not provided');
406420
}
407421

408-
return $this->all()->get(SourceInterface::NAME);
422+
return $name;
409423
}
410424

411425
/**
@@ -489,6 +503,7 @@ public function getNginxWorkerProcesses(): string
489503
if (SourceInterface::NGINX_WORKER_PROCESSES_AUTO === $value) {
490504
return $value;
491505
}
506+
492507
return (string)$value;
493508
}
494509

@@ -500,4 +515,20 @@ public function getNginxWorkerConnections()
500515
{
501516
return (int)$this->all()->get(SourceInterface::SYSTEM_NGINX_WORKER_CONNECTIONS);
502517
}
518+
519+
/**
520+
* Retrieves root folder for Docker mount.
521+
* Can be relative - `./magento2` or absolute
522+
*
523+
* @return string
524+
* @throws ConfigurationMismatchException
525+
*/
526+
public function getRootDirectory(): string
527+
{
528+
if ($this->all()->has(SourceInterface::SYSTEM_ROOT_DIR)) {
529+
return (string)$this->all()->get(SourceInterface::SYSTEM_ROOT_DIR);
530+
}
531+
532+
return '.';
533+
}
503534
}

src/Config/ConfigFactory.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,33 @@
77

88
namespace Magento\CloudDocker\Config;
99

10+
use Magento\CloudDocker\App\ContainerInterface;
11+
use Magento\CloudDocker\Filesystem\DirectoryList;
12+
1013
/**
1114
* Creates instances of config repository.
1215
*/
1316
class ConfigFactory
1417
{
18+
/**
19+
* @var ContainerInterface
20+
*/
21+
private $container;
22+
23+
/**
24+
* @param ContainerInterface $container
25+
*/
26+
public function __construct(ContainerInterface $container)
27+
{
28+
$this->container = $container;
29+
}
30+
1531
/**
1632
* @param array $sources
1733
* @return Config
1834
*/
1935
public function create(array $sources): Config
2036
{
21-
return new Config($sources);
37+
return new Config($this->container->get(DirectoryList::class), $sources);
2238
}
2339
}

0 commit comments

Comments
 (0)