From c603d7ca3f1ae87444a534878bda98e1cc072153 Mon Sep 17 00:00:00 2001 From: Sivaram Manijeganathan Date: Mon, 22 Apr 2024 11:00:08 -0500 Subject: [PATCH] Add lua deploy variables --- config/schema.yaml | 23 ++++++++++++++++++- src/Config/Stage/DeployInterface.php | 10 ++++++++ .../Validator/Deploy/AppropriateVersion.php | 18 +++++++++++++++ .../Deploy/PreDeploy/ConfigUpdate/Cache.php | 15 +++++++++++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/config/schema.yaml b/config/schema.yaml index c9ac513cd1..e8772bb395 100644 --- a/config/schema.yaml +++ b/config/schema.yaml @@ -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, diff --git a/src/Config/Stage/DeployInterface.php b/src/Config/Stage/DeployInterface.php index 0653adf1c4..15688474ab 100644 --- a/src/Config/Stage/DeployInterface.php +++ b/src/Config/Stage/DeployInterface.php @@ -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'; } diff --git a/src/Config/Validator/Deploy/AppropriateVersion.php b/src/Config/Validator/Deploy/AppropriateVersion.php index 236e22146e..f47d64076f 100644 --- a/src/Config/Validator/Deploy/AppropriateVersion.php +++ b/src/Config/Validator/Deploy/AppropriateVersion.php @@ -81,6 +81,24 @@ public function validate(): Validator\ResultInterface ); } + if (!$this->magentoVersion->satisfies('>= 2.4.7') + && $this->configurationChecker->isConfigured(DeployInterface::VAR_USE_LUA, true) + ) { + $errors[] = sprintf( + '%s is available for Magento 2.4.7 and above', + DeployInterface::VAR_USE_LUA + ); + } + + if (!$this->magentoVersion->satisfies('>= 2.4.7') + && $this->configurationChecker->isConfigured(DeployInterface::VAR_LUA_KEY, true) + ) { + $errors[] = sprintf( + '%s is available for Magento 2.4.7 and above', + DeployInterface::VAR_LUA_KEY + ); + } + if ($errors) { return $this->resultFactory->error( 'The current configuration is not compatible with this version of Magento', diff --git a/src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php b/src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php index 8055fbc141..a3ad7236ee 100644 --- a/src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php +++ b/src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php @@ -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. @@ -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; } /** @@ -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) { @@ -120,6 +131,8 @@ public function execute() $config['cache']['graphql'] = $graphqlConfig; } + $config['cache']['frontend']['default']['backend_options']['_useLua'] = $luaConfigKey; + $config['cache']['frontend']['default']['backend_options']['use_lua'] = $luaConfig; $this->configWriter->create($config); } catch (FileSystemException $e) { throw new StepException($e->getMessage(), Error::DEPLOY_ENV_PHP_IS_NOT_WRITABLE);