Skip to content

Commit c241e11

Browse files
committed
Support some cases of blue/green deployment
1 parent 21e8e4e commit c241e11

File tree

6 files changed

+79
-205
lines changed

6 files changed

+79
-205
lines changed

app/code/Magento/Deploy/Model/Plugin/ConfigChangeDetector.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Deploy\Model\Plugin;
88

99
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\FrontControllerInterface;
1112
use Magento\Framework\App\RequestInterface;
1213
use Magento\Framework\Exception\LocalizedException;
@@ -20,19 +21,24 @@
2021
*/
2122
class ConfigChangeDetector
2223
{
24+
private const DEPLOYMENT_BLUE_GREEN_ENABLED = 'deployment/blue_green/enabled';
25+
2326
/**
2427
* Configuration data changes detector.
2528
*
2629
* @var ChangeDetector
2730
*/
2831
private $changeDetector;
2932

33+
private DeploymentConfig $deploymentConfig;
34+
3035
/**
3136
* @param ChangeDetector $changeDetector configuration data changes detector
3237
*/
33-
public function __construct(ChangeDetector $changeDetector)
38+
public function __construct(ChangeDetector $changeDetector, DeploymentConfig $deploymentConfig)
3439
{
3540
$this->changeDetector = $changeDetector;
41+
$this->deploymentConfig = $deploymentConfig;
3642
}
3743

3844
/**
@@ -46,7 +52,9 @@ public function __construct(ChangeDetector $changeDetector)
4652
*/
4753
public function beforeDispatch(FrontControllerInterface $subject, RequestInterface $request)
4854
{
49-
if ($this->changeDetector->hasChanges()) {
55+
if (!$this->deploymentConfig->get(self::DEPLOYMENT_BLUE_GREEN_ENABLED)
56+
&& $this->changeDetector->hasChanges()
57+
) {
5058
throw new LocalizedException(
5159
__(
5260
'The configuration file has changed.'

app/code/Magento/Deploy/Test/Unit/Model/Plugin/ConfigChangeDetectorTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Deploy\Model\DeploymentConfig\ChangeDetector;
1111
use Magento\Deploy\Model\Plugin\ConfigChangeDetector;
12+
use Magento\Framework\App\DeploymentConfig;
1213
use Magento\Framework\App\FrontControllerInterface;
1314
use Magento\Framework\App\RequestInterface;
1415
use PHPUnit\Framework\MockObject\MockObject;
@@ -36,6 +37,11 @@ class ConfigChangeDetectorTest extends TestCase
3637
*/
3738
private $requestMock;
3839

40+
/**
41+
* @var DeploymentConfig|mixed|MockObject
42+
*/
43+
private $deploymentConfig;
44+
3945
/**
4046
* @return void
4147
*/
@@ -48,8 +54,14 @@ protected function setUp(): void
4854
->getMockForAbstractClass();
4955
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
5056
->getMockForAbstractClass();
57+
$this->deploymentConfig =$this->getMockBuilder(DeploymentConfig::class)
58+
->disableOriginalConstructor()
59+
->getMock();
5160

52-
$this->configChangeDetectorPlugin = new ConfigChangeDetector($this->changeDetectorMock);
61+
$this->configChangeDetectorPlugin = new ConfigChangeDetector(
62+
$this->changeDetectorMock,
63+
$this->deploymentConfig
64+
);
5365
}
5466

5567
/**
@@ -65,8 +77,6 @@ public function testBeforeDispatchWithoutException()
6577

6678
/**
6779
* @return void
68-
* @codingStandardsIgnoreStart
69-
* @codingStandardsIgnoreEnd
7080
*/
7181
public function testBeforeDispatchWithException()
7282
{
@@ -80,4 +90,13 @@ public function testBeforeDispatchWithException()
8090
->willReturn(true);
8191
$this->configChangeDetectorPlugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
8292
}
93+
94+
public function testBeforeDispatchWithBlueGreen()
95+
{
96+
$this->deploymentConfig->expects($this->atLeastOnce())
97+
->method('get')
98+
->with('deployment/blue_green/enabled')
99+
->willReturn(1);
100+
$this->configChangeDetectorPlugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
101+
}
83102
}

lib/internal/Magento/Framework/Cache/Backend/RemoteSynchronizedCache.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class RemoteSynchronizedCache extends \Zend_Cache_Backend implements \Zend_Cache
6464
'local_backend_custom_naming' => true,
6565
'local_backend_autoload' => true,
6666
'use_stale_cache' => false,
67+
'cleanup_percentage' => 95,
6768
];
6869

6970
/**
@@ -264,7 +265,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
264265
*/
265266
private function checkIfLocalCacheSpaceExceeded()
266267
{
267-
return $this->getFillingPercentage() >= 95;
268+
return $this->getFillingPercentage() >= ($this->_options['cleanup_percentage'] ?? 95);
268269
}
269270

270271
/**

lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Framework\Module\Plugin;
77

8+
use Magento\Framework\App\DeploymentConfig;
89
use Magento\Framework\Cache\FrontendInterface as FrontendCacheInterface;
910
use Magento\Framework\Module\DbVersionInfo;
1011
use Magento\Framework\App\FrontController;
@@ -17,6 +18,8 @@
1718
*/
1819
class DbStatusValidator
1920
{
21+
private const DEPLOYMENT_BLUE_GREEN_ENABLED = 'deployment/blue_green/enabled';
22+
2023
/**
2124
* @var FrontendCacheInterface
2225
*/
@@ -27,14 +30,21 @@ class DbStatusValidator
2730
*/
2831
private $dbVersionInfo;
2932

33+
private DeploymentConfig $deploymentConfig;
34+
3035
/**
3136
* @param FrontendCacheInterface $cache
3237
* @param DbVersionInfo $dbVersionInfo
38+
* @param DeploymentConfig $deploymentConfig
3339
*/
34-
public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVersionInfo)
35-
{
40+
public function __construct(
41+
FrontendCacheInterface $cache,
42+
DbVersionInfo $dbVersionInfo,
43+
DeploymentConfig $deploymentConfig
44+
) {
3645
$this->cache = $cache;
3746
$this->dbVersionInfo = $dbVersionInfo;
47+
$this->deploymentConfig = $deploymentConfig;
3848
}
3949

4050
/**
@@ -49,6 +59,10 @@ public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVers
4959
*/
5060
public function beforeDispatch(FrontController $subject, RequestInterface $request)
5161
{
62+
if ($this->deploymentConfig->get(self::DEPLOYMENT_BLUE_GREEN_ENABLED)) {
63+
return;
64+
}
65+
5266
if (!$this->cache->load('db_is_up_to_date')) {
5367
list($versionTooLowErrors, $versionTooHighErrors) = array_values($this->getGroupedDbVersionErrors());
5468
if ($versionTooHighErrors) {

lib/internal/Magento/Framework/Module/Test/Unit/Plugin/DbStatusValidatorTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Framework\Module\Test\Unit\Plugin;
99

10+
use Magento\Framework\App\DeploymentConfig;
1011
use Magento\Framework\App\FrontController;
1112
use Magento\Framework\App\RequestInterface;
1213
use Magento\Framework\Cache\FrontendInterface;
@@ -50,6 +51,11 @@ class DbStatusValidatorTest extends TestCase
5051
*/
5152
private $dbVersionInfoMock;
5253

54+
/**
55+
* @var DeploymentConfig|mixed|MockObject
56+
*/
57+
private $deploymentConfig;
58+
5359
protected function setUp(): void
5460
{
5561
$this->_cacheMock = $this->getMockBuilder(FrontendInterface::class)
@@ -67,9 +73,15 @@ protected function setUp(): void
6773
->disableOriginalConstructor()
6874
->getMock();
6975
$this->dbVersionInfoMock = $this->createMock(DbVersionInfo::class);
76+
77+
$this->deploymentConfig =$this->getMockBuilder(DeploymentConfig::class)
78+
->disableOriginalConstructor()
79+
->getMock();
80+
7081
$this->_model = new DbStatusValidator(
7182
$this->_cacheMock,
72-
$this->dbVersionInfoMock
83+
$this->dbVersionInfoMock,
84+
$this->deploymentConfig
7385
);
7486
}
7587

@@ -188,4 +200,20 @@ public function aroundDispatchExceptionDataProvider()
188200
],
189201
];
190202
}
203+
204+
public function testAroundDispatchBlueGreen()
205+
{
206+
$this->deploymentConfig->expects($this->atLeastOnce())
207+
->method('get')
208+
->with('deployment/blue_green/enabled')
209+
->willReturn(1);
210+
211+
$this->_cacheMock->expects($this->never())
212+
->method('load');
213+
214+
$this->dbVersionInfoMock->expects($this->never())
215+
->method('getDbVersionErrors');
216+
217+
$this->_model->beforeDispatch($this->subjectMock, $this->requestMock);
218+
}
191219
}

0 commit comments

Comments
 (0)