Skip to content

Commit

Permalink
Merge pull request #106 from magento-commerce/develop
Browse files Browse the repository at this point in the history
MCLOUD-9560: October cloud tools release
  • Loading branch information
BaDos committed Oct 25, 2022
2 parents 93df22b + 15f7000 commit 88ab8f0
Show file tree
Hide file tree
Showing 16 changed files with 884 additions and 37 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento/ece-tools",
"description": "Provides tools to build and deploy Magento 2 Enterprise Edition",
"type": "magento2-component",
"version": "2002.1.12",
"version": "2002.1.13",
"license": "OSL-3.0",
"repositories": {
"repo.magento.com": {
Expand All @@ -23,7 +23,7 @@
"illuminate/config": "^5.5||^8.77",
"magento/magento-cloud-components": "^1.0.8",
"magento/magento-cloud-docker": "^1.0.0",
"magento/magento-cloud-patches": "^1.0.11",
"magento/magento-cloud-patches": "^1.0.20",
"magento/quality-patches": "^1.1.0",
"monolog/monolog": "^1.25 || ^2.3",
"nesbot/carbon": "^1.0 || ^2.0",
Expand Down
14 changes: 12 additions & 2 deletions config/schema.error.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
!php/const Magento\MagentoCloud\App\Error::BUILD_WRONG_BRAINTREE_VARIABLE:
step: validate-config
title: 'Remove Magento Braintree module configuration which is no longer supported in Adobe Commerce and Magento Open Source 2.4 and later versions.'
suggestion: 'Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree payment support, use an official extension from the Commerce Marketplace instead.'
suggestion: 'Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the `.magento.app.yaml` file. For Braintree payment support, use an official extension from the Commerce Marketplace instead.'
stage: build
type: critical
!php/const Magento\MagentoCloud\App\Error::DEPLOY_WRONG_CACHE_CONFIGURATION:
Expand Down Expand Up @@ -334,7 +334,7 @@
!php/const Magento\MagentoCloud\App\Error::DEPLOY_WRONG_BRAINTREE_VARIABLE:
step: validate-config
title: 'Remove Magento Braintree module configuration which is no longer supported in Adobe Commerce or Magento Open Source 2.4 and later versions.'
suggestion: 'Support for the Braintree module is no longer included with Adobe Commerce or Magento Open Source 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree support, use an official Braintree Payments extension from the Commerce Marketplace instead.'
suggestion: 'Support for the Braintree module is no longer included with Adobe Commerce or Magento Open Source 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the `.magento.app.yaml` file. For Braintree support, use an official Braintree Payments extension from the Commerce Marketplace instead.'
stage: deploy
type: critical
!php/const Magento\MagentoCloud\App\Error::DEPLOY_ES_SERVICE_NOT_INSTALLED:
Expand Down Expand Up @@ -430,6 +430,16 @@
suggestion: ''
stage: general
type: critical
!php/const Magento\MagentoCloud\App\Error::GLOBAL_EVENTING_MODULE_GENERATE_FAILED:
title: 'Unable to generate a module for eventing'
suggestion: 'Check the `cloud.log` for more information.'
stage: general
type: critical
!php/const Magento\MagentoCloud\App\Error::GLOBAL_EVENTING_MODULE_ENABLEMENT_FAILED:
title: 'Unable to enable a module for eventing'
suggestion: 'Check the `cloud.log` for more information.'
stage: general
type: critical
# Warning errors
!php/const Magento\MagentoCloud\App\Error::WARN_CONFIG_PHP_NOT_EXISTS:
title: 'File app/etc/config.php does not exist'
Expand Down
11 changes: 11 additions & 0 deletions config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,17 @@ variables:
config:
region: us-east-1
bucket: test-bucket
ENABLE_EVENTING:
description: Enables commerce eventing.
type: boolean
stages:
- global
default:
global: false
examples:
- stage:
global:
ENABLE_EVENTING: true

# Environment variables
ENV_RELATIONSHIPS:
Expand Down
50 changes: 26 additions & 24 deletions dist/error-codes.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions scenario/build/generate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</item>
<item name="warning" xsi:type="array">
<item name="config-file-exists" xsi:type="object" priority="100">Magento\MagentoCloud\Config\Validator\Build\ConfigFileExists</item>
<item name="opcache-exclude-paths" xsi:type="object" priority="100">Magento\MagentoCloud\Config\Validator\Build\OpcacheExcludePaths</item>
<item name="deprecated-ini" xsi:type="object" priority="200">Magento\MagentoCloud\Config\Validator\Build\UnsupportedBuildOptionsIni</item>
<item name="modules-exists" xsi:type="object" priority="300">Magento\MagentoCloud\Config\Validator\Build\ModulesExists</item>
<item name="appropriate-version" xsi:type="object" priority="400">Magento\MagentoCloud\Config\Validator\Build\AppropriateVersion</item>
Expand All @@ -28,6 +29,7 @@
<step name="set-report-dir-nesting-level" type="Magento\MagentoCloud\Step\Build\SetReportDirNestingLevel" priority="700"/>
<step name="marshall-files" type="Magento\MagentoCloud\Step\Build\MarshallFiles" priority="800"/>
<step name="copy-sample-data" type="Magento\MagentoCloud\Step\Build\CopySampleData" priority="900"/>
<step name="enable-eventing" type="Magento\MagentoCloud\Step\Build\EnableEventing" priority="950" />
<step name="compile-di" type="Magento\MagentoCloud\Step\Build\CompileDi" priority="1000"/>
<step name="dump-autoload" type="Magento\MagentoCloud\Step\Build\ComposerDumpAutoload" priority="1100"/>
<step name="deploy-static-content" type="Magento\MagentoCloud\Step\Build\DeployStaticContent" priority="1200">
Expand Down
3 changes: 3 additions & 0 deletions src/App/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class Error
public const GLOBAL_CONFIG_PARSE_FAILED = 244;
public const GLOBAL_CONFIG_UNABLE_TO_READ = 245;
public const GLOBAL_CONFIG_UNABLE_TO_READ_SCHEMA_YAML = 246;
public const GLOBAL_EVENTING_MODULE_GENERATE_FAILED = 247;
public const GLOBAL_EVENTING_MODULE_ENABLEMENT_FAILED = 248;

/**
* Build
Expand All @@ -105,6 +107,7 @@ class Error
public const WARN_SCD_OPTIONS_IGNORANCE = 1005;
public const WARN_CONFIGURATION_STATE_NOT_IDEAL = 1006;
public const WARN_BALER_CANNOT_BE_USED = 1007;
public const WARN_WRONG_OPCACHE_CONFIG = 1008;

/**
* Deploy
Expand Down
1 change: 1 addition & 0 deletions src/Config/StageConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface StageConfigInterface
public const VAR_SCD_MATRIX = 'SCD_MATRIX';
public const VAR_SCD_NO_PARENT = 'SCD_NO_PARENT';
public const VAR_X_FRAME_CONFIGURATION = 'X_FRAME_CONFIGURATION';
public const VAR_ENABLE_EVENTING = 'ENABLE_EVENTING';

/**
* Settings for deployment from git.
Expand Down
107 changes: 107 additions & 0 deletions src/Config/Validator/Build/OpcacheExcludePaths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\Config\Validator\Build;

use Magento\MagentoCloud\App\Error;
use Magento\MagentoCloud\Config\Validator;
use Magento\MagentoCloud\Config\ValidatorInterface;
use Magento\MagentoCloud\Filesystem\Driver\File;
use Magento\MagentoCloud\Filesystem\FileList;

/**
* Checks that required paths to exclude for OPCache are present.
*/
class OpcacheExcludePaths implements ValidatorInterface
{
/**
* @var File
*/
private $file;

/**
* @var FileList
*/
private $fileList;

/**
* @var Validator\ResultFactory
*/
private $resultFactory;

/**
* @param File $file
* @param FileList $fileList
* @param Validator\ResultFactory $resultFactory
*/
public function __construct(
File $file,
FileList $fileList,
Validator\ResultFactory $resultFactory
) {
$this->file = $file;
$this->fileList = $fileList;
$this->resultFactory = $resultFactory;
}

/**
* Checks if php.ini and op-exclude.txt are present, and they contain needed configuration
*
* {@inheritdoc}
*/
public function validate(): Validator\ResultInterface
{
$phpIni = $this->fileList->getPhpIni();
$excludeList = $this->fileList->getOpCacheExcludeList();

// Checks if files are present
if (!$this->file->isExists($phpIni) || !$this->file->isExists($excludeList)) {
return $this->resultFactory->error(
'File php.ini or op-exclude.txt does not exist',
'Check if your cloud template contains latest php.ini and op-exclude.txt files',
Error::WARN_WRONG_OPCACHE_CONFIG
);
}

// Checks if the php.ini file contains correct path to the op-exclude.txt file
$parsedPhpIni = (array) $this->file->parseIni($phpIni);

if (!(array_key_exists('opcache.blacklist_filename', $parsedPhpIni)
&& $parsedPhpIni['opcache.blacklist_filename'] == $excludeList)) {
return $this->resultFactory->error(
'File php.ini does not contain opcache.blacklist_filename configuration',
'Check if your cloud template contains latest php.ini configuration file'
. ' https://github.com/magento/magento-cloud/blob/master/php.ini',
Error::WARN_WRONG_OPCACHE_CONFIG
);
}

// Checks if the op-exclude.txt file contains all needed paths to exclude for OPCache
$diff = array_diff(
[
'/app/*/app/etc/config.php',
'/app/*/app/etc/env.php',
'/app/app/etc/config.php',
'/app/app/etc/env.php',
'/app/etc/config.php',
'/app/etc/env.php'
],
explode(PHP_EOL, (string) $this->file->fileGetContents($excludeList))
);

if (!empty($diff)) {
return $this->resultFactory->error(
'File op-exclude.txt does not contain required paths to exclude for OPCache',
'Check if your op-exclude.txt contains the next paths:' . PHP_EOL
. implode(PHP_EOL, $diff),
Error::WARN_WRONG_OPCACHE_CONFIG
);
}

return $this->resultFactory->create(Validator\ResultInterface::SUCCESS);
}
}
16 changes: 16 additions & 0 deletions src/Filesystem/ConfigFileList.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,20 @@ public function getErrorReportConfig(): string
{
return $this->systemList->getMagentoRoot() . '/pub/errors/local.xml';
}

/**
* @return string
*/
public function getPhpIni(): string
{
return $this->systemList->getMagentoRoot() . '/php.ini';
}

/**
* @return string
*/
public function getOpCacheExcludeList(): string
{
return $this->systemList->getMagentoRoot() . '/op-exclude.txt';
}
}
92 changes: 92 additions & 0 deletions src/Step/Build/EnableEventing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\MagentoCloud\Step\Build;

use Magento\MagentoCloud\App\Error;
use Magento\MagentoCloud\Config\ConfigException;
use Magento\MagentoCloud\Config\GlobalSection;
use Magento\MagentoCloud\Config\StageConfigInterface;
use Magento\MagentoCloud\Shell\MagentoShell;
use Magento\MagentoCloud\Shell\ShellException;
use Magento\MagentoCloud\Shell\ShellFactory;
use Magento\MagentoCloud\Step\StepException;
use Magento\MagentoCloud\Step\StepInterface;
use Psr\Log\LoggerInterface;

/**
* Runs a command to generate a module for eventing and enables this module in case when
* it is enabled in configuration
*/
class EnableEventing implements StepInterface
{
/**
* @var LoggerInterface
*/
private $logger;

/**
* @var MagentoShell
*/
private $magentoShell;

/**
* @var GlobalSection
*/
private $globalConfig;

/**
* @param LoggerInterface $logger
* @param ShellFactory $shellFactory
* @param GlobalSection $globalConfig
*/
public function __construct(
LoggerInterface $logger,
ShellFactory $shellFactory,
GlobalSection $globalConfig
) {
$this->logger = $logger;
$this->magentoShell = $shellFactory->createMagento();
$this->globalConfig = $globalConfig;
}

/**
* Generates and enables a module for eventing if @see StageConfigInterface::VAR_ENABLE_EVENTING set to true
*
* {@inheritDoc}
*/
public function execute()
{
try {
if (!$this->globalConfig->get(StageConfigInterface::VAR_ENABLE_EVENTING)) {
return;
}
} catch (ConfigException $e) {
throw new StepException($e->getMessage(), $e->getCode(), $e);
}

try {
$this->logger->notice('Generating module for eventing');
$this->magentoShell->execute('events:generate:module');
} catch (ShellException $e) {
$this->logger->error(
'Failed to generate the Magento_AdobeCommerceEvents module. ' .
'Refer to the eventing documentation to determine if all required modules are have been installed. ' .
'Error: ' . $e->getMessage()
);
throw new StepException($e->getMessage(), Error::GLOBAL_EVENTING_MODULE_GENERATE_FAILED, $e);
}

try {
$this->logger->notice('Enabling module for eventing');
$this->magentoShell->execute('module:enable Magento_AdobeCommerceEvents');
} catch (ShellException $e) {
$this->logger->error('Failed to enable module for eventing: ' . $e->getMessage());
throw new StepException($e->getMessage(), Error::GLOBAL_EVENTING_MODULE_ENABLEMENT_FAILED, $e);
}
}
}
5 changes: 5 additions & 0 deletions src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function execute()
try {
$config = $this->configReader->read();
$cacheConfig = $this->cacheConfig->get();
$graphqlConfig = $config['cache']['graphql'] ?? [];

if (isset($cacheConfig['frontend'])) {
$cacheConfig['frontend'] = array_filter($cacheConfig['frontend'], function ($cacheFrontend) {
Expand Down Expand Up @@ -108,6 +109,10 @@ public function execute()
$config['cache'] = $cacheConfig;
}

if (!empty($graphqlConfig)) {
$config['cache']['graphql'] = $graphqlConfig;
}

$this->configWriter->create($config);
} catch (FileSystemException $e) {
throw new StepException($e->getMessage(), Error::DEPLOY_ENV_PHP_IS_NOT_WRITABLE);
Expand Down
1 change: 1 addition & 0 deletions src/Test/Unit/Config/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public function testGetDefaultsForGlobalSection(): void
StageConfigInterface::VAR_DEPLOY_FROM_GIT_OPTIONS => [],
StageConfigInterface::VAR_MIN_LOGGING_LEVEL => '',
StageConfigInterface::VAR_X_FRAME_CONFIGURATION => 'SAMEORIGIN',
StageConfigInterface::VAR_ENABLE_EVENTING => false,
],
$this->schema->getDefaults(StageConfigInterface::STAGE_GLOBAL)
);
Expand Down
Loading

0 comments on commit 88ab8f0

Please sign in to comment.