Skip to content

Commit 41949c3

Browse files
authored
Merge branch 'develop' into 2002.1
2 parents 2e370d4 + 9294d30 commit 41949c3

21 files changed

+1096
-227
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ install:
5454
- composer config github-oauth.github.com ${GITHUB_TOKEN}
5555
- if [ -n "${MCC_VERSION}" ]; then composer config repositories.mcc git [email protected]:magento/magento-cloud-components.git && composer require "magento/magento-cloud-components:${MCC_VERSION}" --no-update; fi;
5656
- if [ -n "${MCD_VERSION}" ]; then composer config repositories.mcd git [email protected]:magento/magento-cloud-docker.git && composer require "magento/magento-cloud-docker:${MCD_VERSION}" --no-update; fi;
57+
- if [ -n "${MCD_VERSION_71}" ] && [ $TRAVIS_PHP_VERSION == "7.1" ]; then composer config repositories.mcd git [email protected]:magento/magento-cloud-docker.git && composer require "magento/magento-cloud-docker:${MCD_VERSION_71}" --no-update; fi;
5758
- if [ -n "${MCP_VERSION}" ]; then composer config repositories.mcp git [email protected]:magento/magento-cloud-patches.git && composer require "magento/magento-cloud-patches:${MCP_VERSION}" --no-update; fi;
5859
- if [ -n "${MQP_VERSION}" ]; then composer config repositories.mqp git [email protected]:magento/quality-patches.git && composer require "magento/quality-patches:${MQP_VERSION}" --no-update; fi;
5960
- composer update -n --no-suggest

config/schema.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,23 @@ variables:
668668
- MC-31387
669669
- MDVA-4567
670670
- MC-45634
671+
REMOTE_STORAGE:
672+
description: Configures remote storage credentials.
673+
magento_version: '>=2.4.2'
674+
type: array
675+
stages:
676+
- deploy
677+
default:
678+
deploy: []
679+
examples:
680+
- stage:
681+
deploy:
682+
REMOTE_STORAGE:
683+
adater: aws_s3
684+
prefix: test-prefix
685+
config:
686+
region: us-east-1
687+
bucket: test-bucket
671688

672689
# Environment variables
673690
ENV_RELATIONSHIPS:

dist/error-codes.md

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Warning errors indicate a problem with the Magento Commerce Cloud project config
150150
| 2025 | install-update:split-db | Slave connection not set. | |
151151
| 2026 | pre-deploy:restore-writable-dirs | Failed to restore some data generated during the build phase to the mounted directories | Check the `cloud.log` for more information. |
152152
| 2027 | validate-config:mage-mode-variable | Mode value for MAGE_MODE environment variable not supported | Remove the MAGE_MODE environment variable, or change its value to "production". Magento Cloud supports "production" mode only. |
153+
| 2028 | remote-storage | Remote storage could not be enabled. | Verify remote storage credentials |
153154

154155
### Post-deploy stage
155156

scenario/deploy.xml

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0"?>
22
<scenario xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:ece-tools:config/scenario.xsd">
3+
<step name="php-opcache-reset" type="Magento\MagentoCloud\Step\Deploy\PhpOpcacheReset" priority="50"/>
34
<step name="remove-deploy-failed-flag" type="Magento\MagentoCloud\Step\Deploy\RemoveDeployFailedFlag" priority="100"/>
45
<step name="pre-deploy" type="Magento\MagentoCloud\Step\Deploy\PreDeploy" priority="200">
56
<arguments>
@@ -126,6 +127,7 @@
126127
</argument>
127128
</arguments>
128129
</step>
130+
<step name="remote-storage" type="Magento\MagentoCloud\Step\Deploy\RemoteStorage" priority="1250"/>
129131
<step name="disable-maintenance-mode" type="Magento\MagentoCloud\Step\DisableMaintenanceMode" priority="1300"/>
130132
<onFail>
131133
<action name="create-deploy-failed-flag" type="Magento\MagentoCloud\OnFail\Action\CreateDeployFailedFlag" priority="100"/>

src/App/Error.php

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class Error
132132
public const WARN_SLAVE_CONNECTION_NOT_SET = 2025;
133133
public const WARN_COPY_MOUNTED_DIRS_FAILED = 2026;
134134
public const WARN_NOT_SUPPORTED_MAGE_MODE = 2027;
135+
public const WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED = 2028;
135136

136137
/**
137138
* Post-deploy

src/Config/RemoteStorage.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Config;
9+
10+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
11+
12+
/**
13+
* Config for remote storage.
14+
*/
15+
class RemoteStorage
16+
{
17+
/**
18+
* @var DeployInterface
19+
*/
20+
private $deployConfig;
21+
22+
/**
23+
* @param DeployInterface $deployConfig
24+
*/
25+
public function __construct(DeployInterface $deployConfig)
26+
{
27+
$this->deployConfig = $deployConfig;
28+
}
29+
30+
/**
31+
* @return string
32+
*/
33+
public function getDriver(): string
34+
{
35+
return (string)($this->deployConfig->get(DeployInterface::VAR_REMOTE_STORAGE)['driver'] ?? '');
36+
}
37+
38+
/**
39+
* @return string
40+
*/
41+
public function getPrefix(): string
42+
{
43+
return (string)($this->deployConfig->get(DeployInterface::VAR_REMOTE_STORAGE)['prefix'] ?? '');
44+
}
45+
46+
/**
47+
* @return string[]
48+
*/
49+
public function getConfig(): array
50+
{
51+
return (array)($this->deployConfig->get(DeployInterface::VAR_REMOTE_STORAGE)['config'] ?? []);
52+
}
53+
}

src/Config/Stage/DeployInterface.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface DeployInterface extends StageConfigInterface
2929
public const VAR_CLEAN_STATIC_FILES = 'CLEAN_STATIC_FILES';
3030
public const VAR_UPDATE_URLS = 'UPDATE_URLS';
3131
public const VAR_FORCE_UPDATE_URLS = 'FORCE_UPDATE_URLS';
32+
public const VAR_REMOTE_STORAGE = 'REMOTE_STORAGE';
3233

3334
/**
3435
* The variable responsible to set lock provider for Magento 2.2.5 and higher.

src/Service/Php.php

+20
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,24 @@ public function getVersion(): string
3131
{
3232
return $this->getConfiguration()['version'];
3333
}
34+
35+
/**
36+
* Checks if opcache is enabled for PHP CLI
37+
*
38+
* @return bool
39+
*/
40+
public function isOpcacheCliEnabled(): bool
41+
{
42+
return (bool)ini_get('opcache.enable_cli');
43+
}
44+
45+
/**
46+
* Resets the contents of the opcache
47+
*
48+
* @return bool
49+
*/
50+
public function resetOpcache(): bool
51+
{
52+
return opcache_reset();
53+
}
3454
}

src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php

+47-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Magento\MagentoCloud\Service\ServiceException;
2222
use Magento\MagentoCloud\Util\UrlManager;
2323
use Magento\MagentoCloud\Util\PasswordGenerator;
24+
use Magento\MagentoCloud\Config\RemoteStorage;
2425

2526
/**
2627
* Generates command for magento installation
@@ -78,6 +79,11 @@ class InstallCommandFactory
7879
*/
7980
private $elasticSearch;
8081

82+
/**
83+
* @var RemoteStorage
84+
*/
85+
private $remoteStorage;
86+
8187
/**
8288
* @param UrlManager $urlManager
8389
* @param AdminDataInterface $adminData
@@ -88,6 +94,9 @@ class InstallCommandFactory
8894
* @param DbConfig $dbConfig
8995
* @param MagentoVersion $magentoVersion
9096
* @param ElasticSearch $elasticSearch
97+
* @param RemoteStorage $remoteStorage
98+
*
99+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
91100
*/
92101
public function __construct(
93102
UrlManager $urlManager,
@@ -98,7 +107,8 @@ public function __construct(
98107
ElasticSuite $elasticSuite,
99108
DbConfig $dbConfig,
100109
MagentoVersion $magentoVersion,
101-
ElasticSearch $elasticSearch
110+
ElasticSearch $elasticSearch,
111+
RemoteStorage $remoteStorage
102112
) {
103113
$this->urlManager = $urlManager;
104114
$this->adminData = $adminData;
@@ -109,6 +119,7 @@ public function __construct(
109119
$this->dbConfig = $dbConfig;
110120
$this->magentoVersion = $magentoVersion;
111121
$this->elasticSearch = $elasticSearch;
122+
$this->remoteStorage = $remoteStorage;
112123
}
113124

114125
/**
@@ -127,7 +138,8 @@ public function create(): string
127138
$options = array_replace(
128139
$this->getBaseOptions(),
129140
$this->getAdminOptions(),
130-
$this->getEsOptions()
141+
$this->getEsOptions(),
142+
$this->getRemoteStorageOptions()
131143
);
132144
} catch (GenericException $exception) {
133145
throw new ConfigException($exception->getMessage(), $exception->getCode(), $exception);
@@ -237,6 +249,39 @@ private function getEsOptions(): array
237249
return $options;
238250
}
239251

252+
/**
253+
* Provides install options for remote storage.
254+
*
255+
* @return array
256+
* @throws UndefinedPackageException
257+
* @throws ConfigException
258+
*/
259+
private function getRemoteStorageOptions(): array
260+
{
261+
$options = [];
262+
263+
if ($this->magentoVersion->isGreaterOrEqual('2.4.2') && $this->remoteStorage->getDriver()) {
264+
$config = $this->remoteStorage->getConfig();
265+
266+
$options['--remote-storage-driver'] = $this->remoteStorage->getDriver();
267+
$options['--remote-storage-prefix'] = $this->remoteStorage->getPrefix();
268+
269+
if (empty($config['bucket']) || empty($config['region'])) {
270+
throw new ConfigException('Bucket and region are required configurations');
271+
}
272+
273+
$options['--remote-storage-bucket'] = $config['bucket'];
274+
$options['--remote-storage-region'] = $config['region'];
275+
276+
if (isset($config['key'], $config['secret'])) {
277+
$options['--remote-storage-key'] = $config['key'];
278+
$options['--remote-storage-secret'] = $config['secret'];
279+
}
280+
}
281+
282+
return $options;
283+
}
284+
240285
/**
241286
* Returns instance of ConnectionInterface
242287
*

src/Step/Deploy/PhpOpcacheReset.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Step\Deploy;
9+
10+
use Magento\MagentoCloud\Service\Php;
11+
use Magento\MagentoCloud\Step\StepInterface;
12+
use Psr\Log\LoggerInterface;
13+
14+
/**
15+
* Flushes the contents of the opcache if the PHP CLI opcache is enabled
16+
*/
17+
class PhpOpcacheReset implements StepInterface
18+
{
19+
/**
20+
* @var LoggerInterface
21+
*/
22+
private $logger;
23+
24+
/**
25+
* @var Php
26+
*/
27+
private $php;
28+
29+
/**
30+
* @param LoggerInterface $logger
31+
* @param Php $php
32+
*/
33+
public function __construct(
34+
LoggerInterface $logger,
35+
Php $php
36+
) {
37+
$this->logger = $logger;
38+
$this->php = $php;
39+
}
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function execute()
45+
{
46+
if ($this->php->isOpcacheCliEnabled()) {
47+
$this->logger->notice('Reset the contents of the opcache');
48+
$this->php->resetOpcache();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)