Skip to content

Commit

Permalink
Merge pull request #146 from magento-commerce/develop
Browse files Browse the repository at this point in the history
MCLOUD-12266: Cloud Tools Release 2002.1.19
  • Loading branch information
andriyShevtsov authored May 20, 2024
2 parents 568b354 + e4d5076 commit eb9a239
Show file tree
Hide file tree
Showing 22 changed files with 206 additions and 87 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"consolidation/robo": "^1.2 || ^3.0",
"php-mock/php-mock-phpunit": "^2.0",
"phpmd/phpmd": "@stable",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^1.10",
"phpunit/php-code-coverage": "^7.0 || ^9.2",
"phpunit/phpunit": "^8.5 || ^9.5",
"squizlabs/php_codesniffer": "^3.0",
Expand Down
23 changes: 22 additions & 1 deletion config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,28 @@ variables:
backend: file
page_cache:
backend: file

USE_LUA:
description: "Enable/Disable LUA in environments starting from Magento 2.4.7"
type: boolean
stages:
- deploy
default:
deploy: false
examples:
- stage:
deploy:
USE_LUA: true
LUA_KEY:
description: "LUA KEY for environments starting from Magento 2.4.7"
type: boolean
stages:
- deploy
default:
deploy: true
examples:
- stage:
deploy:
LUA_KEY: false
SESSION_CONFIGURATION:
description: "Replace or modify the Magento session configuration generated during the deployment process.
By default, ece-tools configures Magento to store Redis session data. To replace the existing configuration,
Expand Down
20 changes: 13 additions & 7 deletions src/App/Logger/Gelf/TransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class TransportFactory
public const TRANSPORT_UDP = 'udp';
public const TRANSPORT_TCP = 'tcp';

private const DEFAULT_HOST = '127.0.0.1';
private const DEFAULT_PORT_HTTP = 12202;
private const DEFAULT_PORT_TCP = 12201;
private const DEFAULT_PORT_UDP = 12201;
private const DEFAULT_PATH_HTTP = '/gelf';

/**
* @param string $type
* @param array $config
Expand All @@ -34,27 +40,27 @@ public function create(string $type, array $config): AbstractTransport
switch ($type) {
case self::TRANSPORT_HTTP:
$transport = new HttpTransport(
$config['host'] ?? null,
$config['port'] ?? null,
$config['path'] ?? null
$config['host'] ?? self::DEFAULT_HOST,
$config['port'] ?? self::DEFAULT_PORT_HTTP,
$config['path'] ?? self::DEFAULT_PATH_HTTP
);
if (isset($config['connection_timeout'])) {
$transport->setConnectTimeout($config['connection_timeout']);
}
break;
case self::TRANSPORT_TCP:
$transport = new TcpTransport(
$config['host'] ?? TcpTransport::DEFAULT_HOST,
$config['port'] ?? TcpTransport::DEFAULT_PORT
$config['host'] ?? self::DEFAULT_HOST,
$config['port'] ?? self::DEFAULT_PORT_TCP
);
if (isset($config['connection_timeout'])) {
$transport->setConnectTimeout($config['connection_timeout']);
}
break;
case self::TRANSPORT_UDP:
$transport = new UdpTransport(
$config['host'] ?? UdpTransport::DEFAULT_HOST,
$config['port'] ?? UdpTransport::DEFAULT_PORT,
$config['host'] ?? self::DEFAULT_HOST,
$config['port'] ?? self::DEFAULT_PORT_UDP,
$config['chunk_size'] ?? UdpTransport::CHUNK_SIZE_WAN
);
break;
Expand Down
10 changes: 10 additions & 0 deletions src/Config/Stage/DeployInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@ interface DeployInterface extends StageConfigInterface
* The variable responsible for enabling google analytics in environments other than prod.
*/
public const VAR_ENABLE_GOOGLE_ANALYTICS = 'ENABLE_GOOGLE_ANALYTICS';

/**
* The variable responsible for enabling LUA cache in environments starting from Magento 2.4.7.
*/
public const VAR_USE_LUA = 'USE_LUA';

/**
* The variable responsible for LUA KEY in environments starting from Magento 2.4.7.
*/
public const VAR_LUA_KEY = 'LUA_KEY';
}
18 changes: 18 additions & 0 deletions src/Config/Validator/Deploy/AppropriateVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function __construct(

/**
* @return Validator\ResultInterface
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function validate(): Validator\ResultInterface
{
Expand Down Expand Up @@ -81,6 +83,22 @@ public function validate(): Validator\ResultInterface
);
}

if (!$this->magentoVersion->isGreaterOrEqual('2.4.7')) {
$variables = [
DeployInterface::VAR_USE_LUA,
DeployInterface::VAR_LUA_KEY,
];

foreach ($variables as $variableName) {
if ($this->configurationChecker->isConfigured($variableName, true)) {
$errors[] = sprintf(
'%s is available for Magento 2.4.7 and later.',
$variableName
);
}
}
}

if ($errors) {
return $this->resultFactory->error(
'The current configuration is not compatible with this version of Magento',
Expand Down
56 changes: 28 additions & 28 deletions src/Filesystem/DirectoryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function getPath(string $code, bool $relativePath = false): string
throw new \RuntimeException("Code {$code} is not registered");
}

if (!array_key_exists(static::PATH, $directories[$code])) {
if (!array_key_exists(self::PATH, $directories[$code])) {
throw new \RuntimeException(
sprintf('Config var "%s" does not exists', static::PATH)
sprintf('Config var "%s" does not exists', self::PATH)
);
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public function getMagentoRoot(): string
*/
public function getInit(): string
{
return $this->getPath(static::DIR_INIT);
return $this->getPath(self::DIR_INIT);
}

/**
Expand All @@ -122,7 +122,7 @@ public function getInit(): string
*/
public function getVar(): string
{
return $this->getPath(static::DIR_VAR);
return $this->getPath(self::DIR_VAR);
}

/**
Expand All @@ -131,7 +131,7 @@ public function getVar(): string
*/
public function getLog(): string
{
return $this->getPath(static::DIR_LOG);
return $this->getPath(self::DIR_LOG);
}

/**
Expand All @@ -140,7 +140,7 @@ public function getLog(): string
*/
public function getGeneratedCode(): string
{
return $this->getPath(static::DIR_GENERATED_CODE);
return $this->getPath(self::DIR_GENERATED_CODE);
}

/**
Expand All @@ -149,7 +149,7 @@ public function getGeneratedCode(): string
*/
public function getGeneratedMetadata(): string
{
return $this->getPath(static::DIR_GENERATED_METADATA);
return $this->getPath(self::DIR_GENERATED_METADATA);
}

/**
Expand All @@ -161,15 +161,15 @@ public function getGeneratedMetadata(): string
public function getWritableDirectories(): array
{
$writableDirs = [
static::DIR_ETC,
static::DIR_MEDIA,
static::DIR_LOG,
static::DIR_VIEW_PREPROCESSED,
self::DIR_ETC,
self::DIR_MEDIA,
self::DIR_LOG,
self::DIR_VIEW_PREPROCESSED,
];

if ($this->magentoVersion->satisfies('2.1.*')) {
$writableDirs[] = static::DIR_GENERATED_METADATA;
$writableDirs[] = static::DIR_GENERATED_CODE;
$writableDirs[] = self::DIR_GENERATED_METADATA;
$writableDirs[] = self::DIR_GENERATED_CODE;
}

return array_map(function ($path) {
Expand All @@ -186,10 +186,10 @@ public function getWritableDirectories(): array
public function getMountPoints(): array
{
$mountPoints = [
static::DIR_ETC,
static::DIR_VAR,
static::DIR_MEDIA,
static::DIR_STATIC
self::DIR_ETC,
self::DIR_VAR,
self::DIR_MEDIA,
self::DIR_STATIC
];

return array_map(function ($path) {
Expand All @@ -203,13 +203,13 @@ public function getMountPoints(): array
private function getDefaultDirectories(): array
{
$config = [
static::DIR_INIT => [static::PATH => 'init'],
static::DIR_VAR => [static::PATH => 'var'],
static::DIR_LOG => [static::PATH => 'var/log'],
static::DIR_ETC => [static::PATH => 'app/etc'],
static::DIR_MEDIA => [static::PATH => 'pub/media'],
static::DIR_STATIC => [static::PATH => 'pub/static'],
static::DIR_VIEW_PREPROCESSED => [static::PATH => 'var/view_preprocessed'],
self::DIR_INIT => [self::PATH => 'init'],
self::DIR_VAR => [self::PATH => 'var'],
self::DIR_LOG => [self::PATH => 'var/log'],
self::DIR_ETC => [self::PATH => 'app/etc'],
self::DIR_MEDIA => [self::PATH => 'pub/media'],
self::DIR_STATIC => [self::PATH => 'pub/static'],
self::DIR_VIEW_PREPROCESSED => [self::PATH => 'var/view_preprocessed'],
];

return $config;
Expand All @@ -224,11 +224,11 @@ private function getDefaultVariadicDirectories(): array
$config = [];

if ($this->magentoVersion->satisfies('2.1.*')) {
$config[static::DIR_GENERATED_CODE] = [static::PATH => 'var/generation'];
$config[static::DIR_GENERATED_METADATA] = [static::PATH => 'var/di'];
$config[self::DIR_GENERATED_CODE] = [self::PATH => 'var/generation'];
$config[self::DIR_GENERATED_METADATA] = [self::PATH => 'var/di'];
} else {
$config[static::DIR_GENERATED_CODE] = [static::PATH => 'generated/code'];
$config[static::DIR_GENERATED_METADATA] = [static::PATH => 'generated/metadata'];
$config[self::DIR_GENERATED_CODE] = [self::PATH => 'generated/code'];
$config[self::DIR_GENERATED_METADATA] = [self::PATH => 'generated/metadata'];
}

return $config;
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Validator
* Supported version constraints of Redis services
*/
private const REDIS_SUPPORT_VERSIONS = [
'*' => '~3.2.0 || ~4.0.0 || ~5.0.0 || ~6.0.0 || ~6.2.0 || ~7.0.0',
'*' => '~3.2.0 || ~4.0.0 || ~5.0.0 || ~6.0.0 || ~6.2.0 || ~7.0.0 || ~7.2.0',
];

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ class Validator
'>=2.3.0 <2.3.7-p4 || >=2.4.0 <2.4.3-p3' => '~3.5.0 || ~3.7.0 || ~3.8.0',
'>=2.4.3-p3 <2.4.5-p3 || ~2.3.7-p4' => '~3.5.0 || ~3.7.0 || ~3.8.0 || ~3.9.0',
'>=2.4.5-p3 <2.4.7' => '~3.9.0 || ~3.11.0',
'>=2.4.7' => '~3.11.0',
'>=2.4.7' => '~3.12.0 || ~3.13.0',
],
ServiceInterface::NAME_NODE => [
'*' => '^6 || ^8 || ^10 || ^11',
Expand Down
17 changes: 16 additions & 1 deletion src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Magento\MagentoCloud\Step\StepInterface;
use Psr\Log\LoggerInterface;
use Magento\MagentoCloud\Package\MagentoVersion;
use Magento\MagentoCloud\Config\Stage\DeployInterface;

/**
* Processes cache configuration.
Expand Down Expand Up @@ -49,25 +50,33 @@ class Cache implements StepInterface
*/
private $magentoVersion;

/**
* @var DeployInterface
*/
private $stageConfig;

/**
* @param ConfigReader $configReader
* @param ConfigWriter $configWriter
* @param LoggerInterface $logger
* @param CacheFactory $cacheConfig
* @param MagentoVersion $magentoVersion
* @param DeployInterface $stageConfig
*/
public function __construct(
ConfigReader $configReader,
ConfigWriter $configWriter,
LoggerInterface $logger,
CacheFactory $cacheConfig,
MagentoVersion $magentoVersion
MagentoVersion $magentoVersion,
DeployInterface $stageConfig
) {
$this->configReader = $configReader;
$this->configWriter = $configWriter;
$this->logger = $logger;
$this->cacheConfig = $cacheConfig;
$this->magentoVersion = $magentoVersion;
$this->stageConfig = $stageConfig;
}

/**
Expand All @@ -79,6 +88,8 @@ public function execute()
$config = $this->configReader->read();
$cacheConfig = $this->cacheConfig->get();
$graphqlConfig = $config['cache']['graphql'] ?? [];
$luaConfig = (boolean)$this->stageConfig->get(DeployInterface::VAR_USE_LUA);
$luaConfigKey = (boolean)$this->stageConfig->get(DeployInterface::VAR_LUA_KEY);

if (isset($cacheConfig['frontend'])) {
$cacheConfig['frontend'] = array_filter($cacheConfig['frontend'], function ($cacheFrontend) {
Expand Down Expand Up @@ -112,6 +123,10 @@ public function execute()
);
unset($config['cache']);
} else {
if (isset($cacheConfig['frontend']['default'])) {
$cacheConfig['frontend']['default']['backend_options']['_useLua'] = $luaConfigKey;
$cacheConfig['frontend']['default']['backend_options']['use_lua'] = $luaConfig;
}
$this->logger->info('Updating cache configuration.');
$config['cache'] = $cacheConfig;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Test/Unit/App/Logger/Gelf/MessageFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public function testSetAdditional()
'datetime' => new \DateTime(),
'level' => Logger::INFO,
'extra' => [],
'context' => []
'context' => [],
'channel' => 'some_channel'
]);

$this->assertEquals(
[
'some_key' => 'some_value'
'some_key' => 'some_value',
'facility' => 'some_channel'
],
$message->getAllAdditionals()
);
Expand Down
Loading

0 comments on commit eb9a239

Please sign in to comment.