Skip to content

Commit 8c37bf2

Browse files
authored
MCLOUD-6660: Add possibility to disable MailHog (#274)
1 parent 58a078b commit 8c37bf2

File tree

10 files changed

+50
-51
lines changed

10 files changed

+50
-51
lines changed

autoload.php

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
define('BP', dirname(__DIR__, 3));
1111
}
1212

13-
if (!defined('ECE_BP')) {
14-
define('ECE_BP', BP);
15-
}
16-
1713
foreach ([__DIR__ . '/../../autoload.php', __DIR__ . '/vendor/autoload.php'] as $file) {
1814
if (file_exists($file)) {
1915
return require $file;

bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
use Magento\CloudDocker\App\Container;
99

10-
return new Container(__DIR__, BP, ECE_BP);
10+
return new Container(__DIR__, BP);

src/App/Container.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,18 @@ class Container implements ContainerInterface
2727
/**
2828
* @param string $root
2929
* @param string $magentoRoot
30-
* @param string|null $eceToolsRoot
3130
* @throws ContainerException
3231
*/
33-
public function __construct(string $root, string $magentoRoot, string $eceToolsRoot = null)
32+
public function __construct(string $root, string $magentoRoot)
3433
{
3534
$containerBuilder = new ContainerBuilder();
3635
$containerBuilder->set('container', $this);
3736
$containerBuilder->setDefinition('container', new Definition(__CLASS__))
38-
->setArguments([$root, $magentoRoot, $eceToolsRoot]);
37+
->setArguments([$root, $magentoRoot]);
3938

4039
$containerBuilder->set(DirectoryList::class, new DirectoryList(
4140
$root,
42-
$magentoRoot,
43-
$eceToolsRoot
41+
$magentoRoot
4442
));
4543

4644
try {

src/Command/BuildCompose.php

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ protected function configure(): void
166166
null,
167167
InputOption::VALUE_NONE,
168168
'Disable Elasticsearch'
169+
)->addOption(
170+
Source\CliSource::OPTION_NO_MAILHOG,
171+
null,
172+
InputOption::VALUE_NONE,
173+
'Disable mailhog'
169174
);
170175

171176
$this->addOption(

src/Compose/ProductionBuilder.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -423,15 +423,17 @@ public function build(Config $config): Manager
423423
);
424424
}
425425

426-
$manager->addService(
427-
self::SERVICE_MAILHOG,
428-
$this->serviceFactory->create(
429-
ServiceInterface::SERVICE_MAILHOG,
430-
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG)
431-
),
432-
[self::NETWORK_MAGENTO],
433-
[]
434-
);
426+
if ($config->hasServiceEnabled(self::SERVICE_MAILHOG)) {
427+
$manager->addService(
428+
self::SERVICE_MAILHOG,
429+
$this->serviceFactory->create(
430+
ServiceInterface::SERVICE_MAILHOG,
431+
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG)
432+
),
433+
[self::NETWORK_MAGENTO],
434+
[]
435+
);
436+
}
435437

436438
return $manager;
437439
}

src/Config/Source/CliSource.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CliSource implements SourceInterface
3232
public const OPTION_SELENIUM_IMAGE = 'selenium-image';
3333
public const OPTION_INSTALLATION_TYPE = 'installation-type';
3434
public const OPTION_NO_ES = 'no-es';
35+
public const OPTION_NO_MAILHOG = 'no-mailhog';
3536

3637
/**
3738
* State modifiers.
@@ -103,7 +104,8 @@ class CliSource implements SourceInterface
103104
* @var array
104105
*/
105106
private static $disableOptionsMap = [
106-
self::OPTION_NO_ES => self::SERVICES_ES
107+
self::OPTION_NO_ES => self::SERVICES_ES,
108+
self::OPTION_NO_MAILHOG => self::SERVICES_MAILHOG,
107109
];
108110

109111
/**

src/Config/Source/CloudSource.php

+16
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function read(): Repository
120120
$repository,
121121
$version
122122
);
123+
$repository = $this->addMailhog($repository);
123124
$repository = $this->addCronJobs(
124125
$repository,
125126
$appConfig['crons'] ?? []
@@ -331,4 +332,19 @@ private function addName(Repository $repository, string $name): Repository
331332

332333
return $repository;
333334
}
335+
336+
/**
337+
* Adds mailhog configuration
338+
*
339+
* @param Repository $repository
340+
* @return Repository
341+
*/
342+
private function addMailhog(Repository $repository): Repository
343+
{
344+
$repository->set([
345+
self::SERVICES_MAILHOG . '.enabled' => true
346+
]);
347+
348+
return $repository;
349+
}
334350
}

src/Config/Source/SourceInterface.php

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ interface SourceInterface
7575
*/
7676
public const SERVICES_ES = self::SERVICES . '.' . ServiceInterface::SERVICE_ELASTICSEARCH;
7777

78+
/**
79+
* Mailhog
80+
*/
81+
public const SERVICES_MAILHOG = self::SERVICES . '.' . ServiceInterface::SERVICE_MAILHOG;
82+
7883
/**
7984
* ES environment variables
8085
*/

src/Filesystem/DirectoryList.php

+1-29
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,14 @@ class DirectoryList
2222
*/
2323
private $magentoRoot;
2424

25-
/**
26-
* @var string
27-
*/
28-
private $eceRoot;
29-
3025
/**
3126
* @param string $root
3227
* @param string $magentoRoot
33-
* @param string $eceRoot
3428
*/
35-
public function __construct(string $root, string $magentoRoot, string $eceRoot = null)
29+
public function __construct(string $root, string $magentoRoot)
3630
{
3731
$this->root = realpath($root);
3832
$this->magentoRoot = realpath($magentoRoot);
39-
$this->eceRoot = $eceRoot ? realpath($eceRoot) : null;
4033
}
4134

4235
/**
@@ -55,27 +48,6 @@ public function getMagentoRoot(): string
5548
return $this->magentoRoot;
5649
}
5750

58-
/**
59-
* @return bool
60-
*/
61-
public function hasEceToolsRoot(): bool
62-
{
63-
return $this->eceRoot !== null;
64-
}
65-
66-
/**
67-
* @return string
68-
* @throws FilesystemException
69-
*/
70-
public function getEceToolsRoot(): string
71-
{
72-
if (null === $this->eceRoot) {
73-
throw new FilesystemException('No ECE-Tools root defined');
74-
}
75-
76-
return $this->eceRoot;
77-
}
78-
7951
/**
8052
* @return string
8153
*/

src/Test/Integration/BuildCustomComposeTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function testBuild(string $directory, array $arguments): void
6060
$command->execute($inputMock, $outputMock);
6161

6262
$this->assertSame(
63-
$filesystem->get($directory . '/docker-compose.yml'),
64-
$filesystem->get($directory . '/docker-compose.exp.yml')
63+
$filesystem->get($directory . '/docker-compose.exp.yml'),
64+
$filesystem->get($directory . '/docker-compose.yml')
6565
);
6666
}
6767

@@ -100,6 +100,9 @@ public function buildDataProvider(): array
100100
'image' => 'mariadb',
101101
'enabled' => true,
102102
],
103+
'mailhog' => [
104+
'enabled' => true,
105+
]
103106
],
104107
'hooks' => [
105108
'build' => 'set -e' . PHP_EOL

0 commit comments

Comments
 (0)