Skip to content

Commit bc964b2

Browse files
authored
MCLOUD-6898: Add option to customize port for MailHog (#290)
1 parent 942796c commit bc964b2

File tree

15 files changed

+134
-7
lines changed

15 files changed

+134
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
/composer.lock
66
/auth.json
77
/_workdir
8+
/_workdir_cache
89
.phpunit.result.cache

codeception.dist.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ modules:
3434
printOutput: false
3535
PhpBrowser:
3636
url: "%Magento.docker.settings.env.url.base%"
37+
REST:
38+
depends: PhpBrowser
39+
url: "%Magento.docker.settings.env.url.base%"
40+
shortDebugResponse: 300
3741
Magento\CloudDocker\Test\Functional\Codeception\MagentoDb:
3842
dsn: "mysql:host=%Magento.docker.settings.db.host%;port=%Magento.docker.settings.db.port%;dbname=%Magento.docker.settings.db.path%"
3943
user: "%Magento.docker.settings.db.username%"

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"codeception/module-asserts": "^1.2",
2424
"codeception/module-db": "^1.0",
2525
"codeception/module-phpbrowser": "^1.0",
26+
"codeception/module-rest": "^1.2",
2627
"consolidation/robo": "^1.2",
2728
"phpmd/phpmd": "@stable",
2829
"phpstan/phpstan": "^0.11",

src/Command/BuildCompose.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ protected function configure(): void
171171
null,
172172
InputOption::VALUE_NONE,
173173
'Disable mailhog'
174+
)->addOption(
175+
Source\CliSource::OPTION_MAILHOG_SMTP_PORT,
176+
null,
177+
InputOption::VALUE_REQUIRED,
178+
'MailHog SMTP port'
179+
)->addOption(
180+
Source\CliSource::OPTION_MAILHOG_HTTP_PORT,
181+
null,
182+
InputOption::VALUE_REQUIRED,
183+
'MailHog HTTP port'
174184
)->addOption(
175185
Source\CliSource::OPTION_SET_DOCKER_HOST_XDEBUG,
176186
null,

src/Compose/ProductionBuilder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,13 @@ public function build(Config $config): Manager
402402
self::SERVICE_MAILHOG,
403403
$this->serviceFactory->create(
404404
ServiceInterface::SERVICE_MAILHOG,
405-
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG)
405+
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG),
406+
[
407+
'ports' => [
408+
$config->getMailHogSmtpPort() . ':1025',
409+
$config->getMailHogHttpPort() . ':8025',
410+
]
411+
]
406412
),
407413
[self::NETWORK_MAGENTO],
408414
[]

src/Config/Config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,22 @@ public function getDbIncrementOffset(): int
454454
1
455455
);
456456
}
457+
458+
/**
459+
* @return string|null
460+
* @throws ConfigurationMismatchException
461+
*/
462+
public function getMailHogSmtpPort(): ?string
463+
{
464+
return $this->all()->get(SourceInterface::SYSTEM_MAILHOG_SMTP_PORT);
465+
}
466+
467+
/**
468+
* @return string|null
469+
* @throws ConfigurationMismatchException
470+
*/
471+
public function getMailHogHttpPort(): ?string
472+
{
473+
return $this->all()->get(SourceInterface::SYSTEM_MAILHOG_HTTP_PORT);
474+
}
457475
}

src/Config/Source/BaseSource.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class BaseSource implements SourceInterface
2727
public const DEFAULT_HOST = 'magento2.docker';
2828
public const DEFAULT_PORT = '80';
2929
public const DEFAULT_TLS_PORT = '443';
30+
public const DEFAULT_MAILHOG_SMTP_PORT = '1025';
31+
public const DEFAULT_MAILHOG_HTTP_PORT = '8025';
3032

3133
/**
3234
* @var EnvReader
@@ -73,7 +75,9 @@ public function read(): Repository
7375
self::SYSTEM_HOST => self::DEFAULT_HOST,
7476
self::SYSTEM_TLS_PORT => self::DEFAULT_TLS_PORT,
7577
self::INSTALLATION_TYPE => self::INSTALLATION_TYPE_COMPOSER,
76-
self::MAGENTO_VERSION => $this->getMagentoVersion()
78+
self::MAGENTO_VERSION => $this->getMagentoVersion(),
79+
self::SYSTEM_MAILHOG_SMTP_PORT => self::DEFAULT_MAILHOG_SMTP_PORT,
80+
self::SYSTEM_MAILHOG_HTTP_PORT => self::DEFAULT_MAILHOG_HTTP_PORT
7781
]);
7882

7983
try {

src/Config/Source/CliSource.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class CliSource implements SourceInterface
3434
public const OPTION_NO_ES = 'no-es';
3535
public const OPTION_NO_MAILHOG = 'no-mailhog';
3636

37+
/**
38+
* MailHog configuration
39+
*/
40+
public const OPTION_MAILHOG_SMTP_PORT = 'mailhog-smtp-port';
41+
public const OPTION_MAILHOG_HTTP_PORT = 'mailhog-http-port';
42+
3743
/**
3844
* State modifiers.
3945
*/
@@ -277,6 +283,14 @@ public function read(): Repository
277283
$repository->set(SourceInterface::SYSTEM_MARIADB_CONF, true);
278284
}
279285

286+
if ($port = $this->input->getOption(self::OPTION_MAILHOG_SMTP_PORT)) {
287+
$repository->set(self::SYSTEM_MAILHOG_SMTP_PORT, $port);
288+
}
289+
290+
if ($port = $this->input->getOption(self::OPTION_MAILHOG_HTTP_PORT)) {
291+
$repository->set(self::SYSTEM_MAILHOG_HTTP_PORT, $port);
292+
}
293+
280294
return $repository;
281295
}
282296
}

src/Config/Source/SourceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ interface SourceInterface
143143
public const SYSTEM_DB_ENTRYPOINT = 'system.db_entrypoint';
144144
public const SYSTEM_MARIADB_CONF = 'system.mariadb_conf';
145145
public const SYSTEM_SET_DOCKER_HOST = 'system.set_docker_host';
146+
public const SYSTEM_MAILHOG_SMTP_PORT = 'system.mailhog.smtp_port';
147+
public const SYSTEM_MAILHOG_HTTP_PORT = 'system.mailhog.http_port';
146148

147149
public const SYSTEM_DB_INCREMENT_INCREMENT = 'system.db.increment_increment';
148150
public const SYSTEM_DB_INCREMENT_OFFSET = 'system.db.increment_offset';

src/Service/ServiceFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class ServiceFactory
132132
'version' => 'latest',
133133
'pattern' => self::PATTERN_STD,
134134
'config' => [
135-
'restart' => 'always',
136135
'ports' => [
137136
'1025:1025',
138137
'8025:8025'

0 commit comments

Comments
 (0)