Skip to content

MCLOUD-6898: Add option to customize port for MailHog #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/composer.lock
/auth.json
/_workdir
/_workdir_cache
.phpunit.result.cache
4 changes: 4 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ modules:
printOutput: false
PhpBrowser:
url: "%Magento.docker.settings.env.url.base%"
REST:
depends: PhpBrowser
url: "%Magento.docker.settings.env.url.base%"
shortDebugResponse: 300
Magento\CloudDocker\Test\Functional\Codeception\MagentoDb:
dsn: "mysql:host=%Magento.docker.settings.db.host%;port=%Magento.docker.settings.db.port%;dbname=%Magento.docker.settings.db.path%"
user: "%Magento.docker.settings.db.username%"
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"codeception/module-asserts": "^1.2",
"codeception/module-db": "^1.0",
"codeception/module-phpbrowser": "^1.0",
"codeception/module-rest": "^1.2",
"consolidation/robo": "^1.2",
"phpmd/phpmd": "@stable",
"phpstan/phpstan": "^0.11",
Expand Down
10 changes: 10 additions & 0 deletions src/Command/BuildCompose.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ protected function configure(): void
null,
InputOption::VALUE_NONE,
'Disable mailhog'
)->addOption(
Source\CliSource::OPTION_MAILHOG_SMTP_PORT,
null,
InputOption::VALUE_REQUIRED,
'MailHog SMTP port'
)->addOption(
Source\CliSource::OPTION_MAILHOG_HTTP_PORT,
null,
InputOption::VALUE_REQUIRED,
'MailHog HTTP port'
)->addOption(
Source\CliSource::OPTION_SET_DOCKER_HOST_XDEBUG,
null,
Expand Down
8 changes: 7 additions & 1 deletion src/Compose/ProductionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,13 @@ public function build(Config $config): Manager
self::SERVICE_MAILHOG,
$this->serviceFactory->create(
ServiceInterface::SERVICE_MAILHOG,
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG)
$this->serviceFactory->getDefaultVersion(ServiceInterface::SERVICE_MAILHOG),
[
'ports' => [
$config->getMailHogSmtpPort() . ':1025',
$config->getMailHogHttpPort() . ':8025',
]
]
),
[self::NETWORK_MAGENTO],
[]
Expand Down
18 changes: 18 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,22 @@ public function getDbIncrementOffset(): int
1
);
}

/**
* @return string|null
* @throws ConfigurationMismatchException
*/
public function getMailHogSmtpPort(): ?string
{
return $this->all()->get(SourceInterface::SYSTEM_MAILHOG_SMTP_PORT);
}

/**
* @return string|null
* @throws ConfigurationMismatchException
*/
public function getMailHogHttpPort(): ?string
{
return $this->all()->get(SourceInterface::SYSTEM_MAILHOG_HTTP_PORT);
}
}
6 changes: 5 additions & 1 deletion src/Config/Source/BaseSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class BaseSource implements SourceInterface
public const DEFAULT_HOST = 'magento2.docker';
public const DEFAULT_PORT = '80';
public const DEFAULT_TLS_PORT = '443';
public const DEFAULT_MAILHOG_SMTP_PORT = '1025';
public const DEFAULT_MAILHOG_HTTP_PORT = '8025';

/**
* @var EnvReader
Expand Down Expand Up @@ -73,7 +75,9 @@ public function read(): Repository
self::SYSTEM_HOST => self::DEFAULT_HOST,
self::SYSTEM_TLS_PORT => self::DEFAULT_TLS_PORT,
self::INSTALLATION_TYPE => self::INSTALLATION_TYPE_COMPOSER,
self::MAGENTO_VERSION => $this->getMagentoVersion()
self::MAGENTO_VERSION => $this->getMagentoVersion(),
self::SYSTEM_MAILHOG_SMTP_PORT => self::DEFAULT_MAILHOG_SMTP_PORT,
self::SYSTEM_MAILHOG_HTTP_PORT => self::DEFAULT_MAILHOG_HTTP_PORT
]);

try {
Expand Down
14 changes: 14 additions & 0 deletions src/Config/Source/CliSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class CliSource implements SourceInterface
public const OPTION_NO_ES = 'no-es';
public const OPTION_NO_MAILHOG = 'no-mailhog';

/**
* MailHog configuration
*/
public const OPTION_MAILHOG_SMTP_PORT = 'mailhog-smtp-port';
public const OPTION_MAILHOG_HTTP_PORT = 'mailhog-http-port';

/**
* State modifiers.
*/
Expand Down Expand Up @@ -277,6 +283,14 @@ public function read(): Repository
$repository->set(SourceInterface::SYSTEM_MARIADB_CONF, true);
}

if ($port = $this->input->getOption(self::OPTION_MAILHOG_SMTP_PORT)) {
$repository->set(self::SYSTEM_MAILHOG_SMTP_PORT, $port);
}

if ($port = $this->input->getOption(self::OPTION_MAILHOG_HTTP_PORT)) {
$repository->set(self::SYSTEM_MAILHOG_HTTP_PORT, $port);
}

return $repository;
}
}
2 changes: 2 additions & 0 deletions src/Config/Source/SourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ interface SourceInterface
public const SYSTEM_DB_ENTRYPOINT = 'system.db_entrypoint';
public const SYSTEM_MARIADB_CONF = 'system.mariadb_conf';
public const SYSTEM_SET_DOCKER_HOST = 'system.set_docker_host';
public const SYSTEM_MAILHOG_SMTP_PORT = 'system.mailhog.smtp_port';
public const SYSTEM_MAILHOG_HTTP_PORT = 'system.mailhog.http_port';

public const SYSTEM_DB_INCREMENT_INCREMENT = 'system.db.increment_increment';
public const SYSTEM_DB_INCREMENT_OFFSET = 'system.db.increment_offset';
Expand Down
1 change: 0 additions & 1 deletion src/Service/ServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ServiceFactory
'version' => 'latest',
'pattern' => self::PATTERN_STD,
'config' => [
'restart' => 'always',
'ports' => [
'1025:1025',
'8025:8025'
Expand Down
1 change: 1 addition & 0 deletions src/Test/Functional/Acceptance.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ modules:
- Magento\CloudDocker\Test\Functional\Codeception\MagentoDb
- PhpBrowser
- Asserts
- REST
65 changes: 65 additions & 0 deletions src/Test/Functional/Acceptance/MailHogCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CloudDocker\Test\Functional\Acceptance;

/**
* @group php74
*/
class MailHogCest extends AbstractCest
{
/**
* @param \CliTester $I
* @throws \Exception
*/
public function testDefaultPorts(\CliTester $I): void
{
$I->updateBaseUrl('http://magento2.docker:8025/');
$I->assertTrue(
$I->runEceDockerCommand('build:compose'),
'Command build:compose failed'
);
$this->runAndAssert($I);
}

/**
* @param \CliTester $I
* @throws \Exception
*/
public function testCustomPorts(\CliTester $I): void
{
$I->updateBaseUrl('http://magento2.docker:8026/');
$I->assertTrue(
$I->runEceDockerCommand('build:compose --mailhog-http-port=8026 --mailhog-smtp-port=1026'),
'Command build:compose failed'
);
$this->runAndAssert($I);
}

/**
* @param \CliTester $I
* @throws \Exception
*/
private function runAndAssert(\CliTester $I): void
{
$I->replaceImagesWithGenerated();
$I->startEnvironment();
$I->amOnPage('/');
$I->see('MailHog');

$I->sendAjaxGetRequest('/api/v2/messages', ['limit' => 10]);
$I->seeResponseIsJson();
$I->assertSame([0], $I->grabDataFromResponseByJsonPath('$.total'));

$I->assertTrue(
$I->runDockerComposeCommand('run deploy bash -c "php -r \"mail(\'[email protected]\',\'test\',\'test\');\""')
);
$I->sendAjaxGetRequest('/api/v2/messages', ['limit' => 10]);
$I->seeResponseIsJson();
$I->assertSame([1], $I->grabDataFromResponseByJsonPath('$.total'));
}
}
4 changes: 4 additions & 0 deletions src/Test/Integration/BuildCustomComposeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function buildDataProvider(): array
'db' => [
'increment_increment' => 3,
'increment_offset' => 2
],
'mailhog' => [
'smtp_port' => '1026',
'http_port' => '8026'
]
],
'services' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ services:
mailhog:
hostname: mailhog.magento2.docker
image: 'mailhog/mailhog:latest'
restart: always
ports:
- '1025:1025'
- '8025:8025'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ services:
mailhog:
hostname: mailhog.magento2.test
image: 'mailhog/mailhog:latest'
restart: always
ports:
- '1025:1025'
- '8025:8025'
- '1026:1025'
- '8026:8025'
networks:
magento:
aliases:
Expand Down