Skip to content

Commit

Permalink
Add lua deploy variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaram7 committed Apr 22, 2024
1 parent 579df76 commit c603d7c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 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 @@ -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',
Expand Down
15 changes: 14 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 @@ -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);
Expand Down

0 comments on commit c603d7c

Please sign in to comment.