Skip to content

Commit e4d5076

Browse files
Merge pull request #137 from magento-commerce/MCLOUD-12022
Add lua deploy variables
2 parents 776fcbb + 0c17136 commit e4d5076

File tree

7 files changed

+95
-18
lines changed

7 files changed

+95
-18
lines changed

config/schema.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,28 @@ variables:
466466
backend: file
467467
page_cache:
468468
backend: file
469-
469+
USE_LUA:
470+
description: "Enable/Disable LUA in environments starting from Magento 2.4.7"
471+
type: boolean
472+
stages:
473+
- deploy
474+
default:
475+
deploy: false
476+
examples:
477+
- stage:
478+
deploy:
479+
USE_LUA: true
480+
LUA_KEY:
481+
description: "LUA KEY for environments starting from Magento 2.4.7"
482+
type: boolean
483+
stages:
484+
- deploy
485+
default:
486+
deploy: true
487+
examples:
488+
- stage:
489+
deploy:
490+
LUA_KEY: false
470491
SESSION_CONFIGURATION:
471492
description: "Replace or modify the Magento session configuration generated during the deployment process.
472493
By default, ece-tools configures Magento to store Redis session data. To replace the existing configuration,

src/Config/Stage/DeployInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,14 @@ interface DeployInterface extends StageConfigInterface
8686
* The variable responsible for enabling google analytics in environments other than prod.
8787
*/
8888
public const VAR_ENABLE_GOOGLE_ANALYTICS = 'ENABLE_GOOGLE_ANALYTICS';
89+
90+
/**
91+
* The variable responsible for enabling LUA cache in environments starting from Magento 2.4.7.
92+
*/
93+
public const VAR_USE_LUA = 'USE_LUA';
94+
95+
/**
96+
* The variable responsible for LUA KEY in environments starting from Magento 2.4.7.
97+
*/
98+
public const VAR_LUA_KEY = 'LUA_KEY';
8999
}

src/Config/Validator/Deploy/AppropriateVersion.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function __construct(
5050

5151
/**
5252
* @return Validator\ResultInterface
53+
*
54+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5355
*/
5456
public function validate(): Validator\ResultInterface
5557
{
@@ -81,6 +83,22 @@ public function validate(): Validator\ResultInterface
8183
);
8284
}
8385

86+
if (!$this->magentoVersion->isGreaterOrEqual('2.4.7')) {
87+
$variables = [
88+
DeployInterface::VAR_USE_LUA,
89+
DeployInterface::VAR_LUA_KEY,
90+
];
91+
92+
foreach ($variables as $variableName) {
93+
if ($this->configurationChecker->isConfigured($variableName, true)) {
94+
$errors[] = sprintf(
95+
'%s is available for Magento 2.4.7 and later.',
96+
$variableName
97+
);
98+
}
99+
}
100+
}
101+
84102
if ($errors) {
85103
return $this->resultFactory->error(
86104
'The current configuration is not compatible with this version of Magento',

src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\MagentoCloud\Step\StepInterface;
1717
use Psr\Log\LoggerInterface;
1818
use Magento\MagentoCloud\Package\MagentoVersion;
19+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1920

2021
/**
2122
* Processes cache configuration.
@@ -49,25 +50,33 @@ class Cache implements StepInterface
4950
*/
5051
private $magentoVersion;
5152

53+
/**
54+
* @var DeployInterface
55+
*/
56+
private $stageConfig;
57+
5258
/**
5359
* @param ConfigReader $configReader
5460
* @param ConfigWriter $configWriter
5561
* @param LoggerInterface $logger
5662
* @param CacheFactory $cacheConfig
5763
* @param MagentoVersion $magentoVersion
64+
* @param DeployInterface $stageConfig
5865
*/
5966
public function __construct(
6067
ConfigReader $configReader,
6168
ConfigWriter $configWriter,
6269
LoggerInterface $logger,
6370
CacheFactory $cacheConfig,
64-
MagentoVersion $magentoVersion
71+
MagentoVersion $magentoVersion,
72+
DeployInterface $stageConfig
6573
) {
6674
$this->configReader = $configReader;
6775
$this->configWriter = $configWriter;
6876
$this->logger = $logger;
6977
$this->cacheConfig = $cacheConfig;
7078
$this->magentoVersion = $magentoVersion;
79+
$this->stageConfig = $stageConfig;
7180
}
7281

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

8394
if (isset($cacheConfig['frontend'])) {
8495
$cacheConfig['frontend'] = array_filter($cacheConfig['frontend'], function ($cacheFrontend) {
@@ -112,6 +123,10 @@ public function execute()
112123
);
113124
unset($config['cache']);
114125
} else {
126+
if (isset($cacheConfig['frontend']['default'])) {
127+
$cacheConfig['frontend']['default']['backend_options']['_useLua'] = $luaConfigKey;
128+
$cacheConfig['frontend']['default']['backend_options']['use_lua'] = $luaConfig;
129+
}
115130
$this->logger->info('Updating cache configuration.');
116131
$config['cache'] = $cacheConfig;
117132
}

src/Test/Unit/Config/SchemaTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public function testGetDefaultsForDeploy(): void
118118
DeployInterface::VAR_CACHE_REDIS_BACKEND => 'Cm_Cache_Backend_Redis',
119119
DeployInterface::VAR_REMOTE_STORAGE => [],
120120
DeployInterface::VAR_SCD_NO_PARENT => false,
121+
DeployInterface::VAR_USE_LUA => false,
122+
DeployInterface::VAR_LUA_KEY => true,
121123
],
122124
$this->schema->getDefaults(StageConfigInterface::STAGE_DEPLOY)
123125
);

src/Test/Unit/Config/Validator/Deploy/AppropriateVersionTest.php

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\MagentoCloud\Package\MagentoVersion;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717
use PHPUnit\Framework\TestCase;
18+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
1819

1920
/**
2021
* @inheritdoc
@@ -60,12 +61,12 @@ protected function setUp(): void
6061
);
6162
}
6263

63-
public function testValidateVersionGreaterTwoDotTwo()
64+
public function testValidateVersion()
6465
{
65-
$this->magentoVersion->expects($this->once())
66+
$this->magentoVersion->expects($this->exactly(2))
6667
->method('isGreaterOrEqual')
67-
->with('2.2')
68-
->willReturn(true);
68+
->withConsecutive(['2.2'], ['2.4.7'])
69+
->willReturnOnConsecutiveCalls(true, true);
6970
$this->magentoVersion->expects($this->once())
7071
->method('satisfies')
7172
->willReturn(true);
@@ -75,32 +76,32 @@ public function testValidateVersionGreaterTwoDotTwo()
7576
$this->assertInstanceOf(Success::class, $this->validator->validate());
7677
}
7778

78-
public function testValidateVersionTwoDotOneAndVariablesNotConfigured()
79+
public function testValidateVersionAndVariablesNotConfigured()
7980
{
80-
$this->magentoVersion->expects($this->once())
81+
$this->magentoVersion->expects($this->exactly(2))
8182
->method('isGreaterOrEqual')
82-
->with('2.2')
83-
->willReturn(false);
83+
->withConsecutive(['2.2'], ['2.4.7'])
84+
->willReturnOnConsecutiveCalls(false, false);
8485
$this->magentoVersion->expects($this->once())
8586
->method('satisfies')
8687
->willReturn(false);
87-
$this->configurationCheckerMock->expects($this->exactly(4))
88+
$this->configurationCheckerMock->expects($this->exactly(6))
8889
->method('isConfigured')
8990
->willReturn(false);
9091

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

94-
public function testValidateVersionTwoDotOneAndAllVariablesAreConfigured()
95+
public function testValidateVersionAndAllVariablesAreConfigured()
9596
{
96-
$this->magentoVersion->expects($this->once())
97+
$this->magentoVersion->expects($this->exactly(2))
9798
->method('isGreaterOrEqual')
98-
->with('2.2')
99-
->willReturn(false);
99+
->withConsecutive(['2.2'], ['2.4.7'])
100+
->willReturnOnConsecutiveCalls(false, false);
100101
$this->magentoVersion->expects($this->once())
101102
->method('satisfies')
102103
->willReturn(false);
103-
$this->configurationCheckerMock->expects($this->exactly(4))
104+
$this->configurationCheckerMock->expects($this->exactly(6))
104105
->method('isConfigured')
105106
->willReturn(true);
106107
$this->resultFactoryMock->expects($this->once())
@@ -111,7 +112,9 @@ public function testValidateVersionTwoDotOneAndAllVariablesAreConfigured()
111112
'CRON_CONSUMERS_RUNNER is available for Magento 2.2.0 and later.',
112113
'SCD_STRATEGY is available for Magento 2.2.0 and later.',
113114
'SCD_MAX_EXECUTION_TIME is available for Magento 2.2.0 and later.',
114-
'GENERATED_CODE_SYMLINK is available for Magento 2.1.x.'
115+
'GENERATED_CODE_SYMLINK is available for Magento 2.1.x.',
116+
'USE_LUA is available for Magento 2.4.7 and later.',
117+
'LUA_KEY is available for Magento 2.4.7 and later.'
115118
])
116119
);
117120

src/Test/Unit/Step/Deploy/PreDeploy/ConfigUpdate/CacheTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Framework\TestCase;
2020
use Psr\Log\LoggerInterface;
2121
use Magento\MagentoCloud\Package\MagentoVersion;
22+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
2223

2324
/**
2425
* @inheritdoc
@@ -72,6 +73,11 @@ class CacheTest extends TestCase
7273
*/
7374
private $magentoVersion;
7475

76+
/**
77+
* @var DeployInterface
78+
*/
79+
private $stageConfig;
80+
7581
/**
7682
* @inheritdoc
7783
*/
@@ -82,13 +88,15 @@ protected function setUp(): void
8288
$this->configReaderMock = $this->createMock(ConfigReader::class);
8389
$this->cacheConfigMock = $this->createMock(CacheFactory::class);
8490
$this->magentoVersion = $this->createMock(MagentoVersion::class);
91+
$this->stageConfig = $this->createMock(DeployInterface::class);
8592

8693
$this->step = new Cache(
8794
$this->configReaderMock,
8895
$this->configWriterMock,
8996
$this->loggerMock,
9097
$this->cacheConfigMock,
91-
$this->magentoVersion
98+
$this->magentoVersion,
99+
$this->stageConfig
92100
);
93101

94102
$this->socketCreateMock = $this->getFunctionMock(

0 commit comments

Comments
 (0)