Skip to content

Commit

Permalink
Merge pull request #137 from magento-commerce/MCLOUD-12022
Browse files Browse the repository at this point in the history
Add lua deploy variables
  • Loading branch information
andriyShevtsov authored May 13, 2024
2 parents 776fcbb + 0c17136 commit e4d5076
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 18 deletions.
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
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
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
2 changes: 2 additions & 0 deletions src/Test/Unit/Config/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function testGetDefaultsForDeploy(): void
DeployInterface::VAR_CACHE_REDIS_BACKEND => 'Cm_Cache_Backend_Redis',
DeployInterface::VAR_REMOTE_STORAGE => [],
DeployInterface::VAR_SCD_NO_PARENT => false,
DeployInterface::VAR_USE_LUA => false,
DeployInterface::VAR_LUA_KEY => true,
],
$this->schema->getDefaults(StageConfigInterface::STAGE_DEPLOY)
);
Expand Down
33 changes: 18 additions & 15 deletions src/Test/Unit/Config/Validator/Deploy/AppropriateVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\MagentoCloud\Package\MagentoVersion;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\MagentoCloud\Config\Stage\DeployInterface;

/**
* @inheritdoc
Expand Down Expand Up @@ -60,12 +61,12 @@ protected function setUp(): void
);
}

public function testValidateVersionGreaterTwoDotTwo()
public function testValidateVersion()
{
$this->magentoVersion->expects($this->once())
$this->magentoVersion->expects($this->exactly(2))
->method('isGreaterOrEqual')
->with('2.2')
->willReturn(true);
->withConsecutive(['2.2'], ['2.4.7'])
->willReturnOnConsecutiveCalls(true, true);
$this->magentoVersion->expects($this->once())
->method('satisfies')
->willReturn(true);
Expand All @@ -75,32 +76,32 @@ public function testValidateVersionGreaterTwoDotTwo()
$this->assertInstanceOf(Success::class, $this->validator->validate());
}

public function testValidateVersionTwoDotOneAndVariablesNotConfigured()
public function testValidateVersionAndVariablesNotConfigured()
{
$this->magentoVersion->expects($this->once())
$this->magentoVersion->expects($this->exactly(2))
->method('isGreaterOrEqual')
->with('2.2')
->willReturn(false);
->withConsecutive(['2.2'], ['2.4.7'])
->willReturnOnConsecutiveCalls(false, false);
$this->magentoVersion->expects($this->once())
->method('satisfies')
->willReturn(false);
$this->configurationCheckerMock->expects($this->exactly(4))
$this->configurationCheckerMock->expects($this->exactly(6))
->method('isConfigured')
->willReturn(false);

$this->assertInstanceOf(Success::class, $this->validator->validate());
}

public function testValidateVersionTwoDotOneAndAllVariablesAreConfigured()
public function testValidateVersionAndAllVariablesAreConfigured()
{
$this->magentoVersion->expects($this->once())
$this->magentoVersion->expects($this->exactly(2))
->method('isGreaterOrEqual')
->with('2.2')
->willReturn(false);
->withConsecutive(['2.2'], ['2.4.7'])
->willReturnOnConsecutiveCalls(false, false);
$this->magentoVersion->expects($this->once())
->method('satisfies')
->willReturn(false);
$this->configurationCheckerMock->expects($this->exactly(4))
$this->configurationCheckerMock->expects($this->exactly(6))
->method('isConfigured')
->willReturn(true);
$this->resultFactoryMock->expects($this->once())
Expand All @@ -111,7 +112,9 @@ public function testValidateVersionTwoDotOneAndAllVariablesAreConfigured()
'CRON_CONSUMERS_RUNNER is available for Magento 2.2.0 and later.',
'SCD_STRATEGY is available for Magento 2.2.0 and later.',
'SCD_MAX_EXECUTION_TIME is available for Magento 2.2.0 and later.',
'GENERATED_CODE_SYMLINK is available for Magento 2.1.x.'
'GENERATED_CODE_SYMLINK is available for Magento 2.1.x.',
'USE_LUA is available for Magento 2.4.7 and later.',
'LUA_KEY is available for Magento 2.4.7 and later.'
])
);

Expand Down
10 changes: 9 additions & 1 deletion src/Test/Unit/Step/Deploy/PreDeploy/ConfigUpdate/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Magento\MagentoCloud\Package\MagentoVersion;
use Magento\MagentoCloud\Config\Stage\DeployInterface;

/**
* @inheritdoc
Expand Down Expand Up @@ -72,6 +73,11 @@ class CacheTest extends TestCase
*/
private $magentoVersion;

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

/**
* @inheritdoc
*/
Expand All @@ -82,13 +88,15 @@ protected function setUp(): void
$this->configReaderMock = $this->createMock(ConfigReader::class);
$this->cacheConfigMock = $this->createMock(CacheFactory::class);
$this->magentoVersion = $this->createMock(MagentoVersion::class);
$this->stageConfig = $this->createMock(DeployInterface::class);

$this->step = new Cache(
$this->configReaderMock,
$this->configWriterMock,
$this->loggerMock,
$this->cacheConfigMock,
$this->magentoVersion
$this->magentoVersion,
$this->stageConfig
);

$this->socketCreateMock = $this->getFunctionMock(
Expand Down

0 comments on commit e4d5076

Please sign in to comment.