Skip to content

Commit 75dadf4

Browse files
committed
Merge branch 'MCLOUD-10819' of https://github.com/glo72880/ece-tools into MCLOUD-10819
2 parents 6790add + be20ae6 commit 75dadf4

File tree

10 files changed

+126
-4
lines changed

10 files changed

+126
-4
lines changed

scenario/build/transfer.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<argument name="steps" xsi:type="array">
99
<item name="static-content" xsi:type="object" priority="100">Magento\MagentoCloud\Step\Build\BackupData\StaticContent</item>
1010
<item name="writable-dirs" xsi:type="object" priority="200">Magento\MagentoCloud\Step\Build\BackupData\WritableDirectories</item>
11+
<item name="clear-mounted-dirs" xsi:type="object" priority="300">Magento\MagentoCloud\Step\Build\ClearMountedDirectories</item>
1112
</argument>
1213
</arguments>
1314
</step>

src/Filesystem/DirectoryList.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ public function getWritableDirectories(): array
177177
}, $writableDirs);
178178
}
179179

180+
/**
181+
* Retrieves mount points for writable directories.
182+
*
183+
* @return array
184+
* @throws UndefinedPackageException
185+
*/
186+
public function getMountPoints(): array
187+
{
188+
$mountPoints = [
189+
static::DIR_ETC,
190+
static::DIR_VAR,
191+
static::DIR_MEDIA,
192+
static::DIR_STATIC
193+
];
194+
195+
return array_map(function ($path) {
196+
return $this->getPath($path, true);
197+
}, $mountPoints);
198+
}
199+
180200
/**
181201
* @return array
182202
*/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/************************************************************************
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
* ************************************************************************
15+
*/
16+
declare(strict_types=1);
17+
18+
namespace Magento\MagentoCloud\Step\Build;
19+
20+
use Magento\MagentoCloud\Filesystem\Driver\File;
21+
use Magento\MagentoCloud\Filesystem\DirectoryList;
22+
use Magento\MagentoCloud\Step\StepInterface;
23+
use Psr\Log\LoggerInterface;
24+
25+
/**
26+
* Clear the mounted directories on the local filesystem before mounting the remote filesystem.
27+
*
28+
* This prevents warning messages that the mounted directories are not empty.
29+
*
30+
* {@inheritdoc}
31+
*/
32+
class ClearMountedDirectories implements StepInterface
33+
{
34+
/** @var LoggerInterface */
35+
private $logger;
36+
37+
/** @var File */
38+
private $file;
39+
40+
/** @var DirectoryList */
41+
private $directoryList;
42+
43+
public function __construct(
44+
LoggerInterface $logger,
45+
File $file,
46+
DirectoryList $directoryList
47+
) {
48+
$this->logger = $logger;
49+
$this->file = $file;
50+
$this->directoryList = $directoryList;
51+
}
52+
53+
/**
54+
* {@inheritDoc}
55+
*/
56+
public function execute()
57+
{
58+
foreach ($this->directoryList->getMountPoints() as $mount) {
59+
if ($this->file->isExists($mount) === false) {
60+
continue;
61+
}
62+
$this->logger->info(sprintf('Clearing the %s path of all files and folders', $mount));
63+
$this->file->clearDirectory($mount);
64+
}
65+
}
66+
}

src/Test/Functional/Acceptance/BackupDb24Cest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ private function partRunDbDumpWithoutSplitDbArch(CliTester $I)
8888

8989
// Running database dump command with invalid database label
9090
$I->runDockerComposeCommand('run build cloud-build');
91+
92+
// Restore app/etc after build phase
93+
$I->runDockerComposeCommand('run build bash -c "cp -r /app/init/app/etc /app/app"');
94+
9195
$I->runDockerComposeCommand('run deploy ece-command db-dump incorrectName');
9296
$I->seeInOutput(
9397
'CRITICAL: Incorrect the database names: [ incorrectName ].'

src/Test/Functional/Acceptance/BackupDbCest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ private function partRunDbDumpWithoutSplitDbArch(CliTester $I)
8585

8686
// Running database dump command with invalid database label
8787
$I->runDockerComposeCommand('run build cloud-build');
88+
89+
// Restore app/etc after build phase
90+
$I->runDockerComposeCommand('run build bash -c "cp -r /app/init/app/etc /app/app"');
91+
8892
$I->runDockerComposeCommand('run deploy ece-command db-dump incorrectName');
8993
$I->seeInOutput(
9094
'CRITICAL: Incorrect the database names: [ incorrectName ].'

src/Test/Functional/Acceptance/ScenarioExtensibilityCest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testScenarioExtensibilityAndPriority(\CliTester $I): void
5353
$I->runDockerComposeCommand('run build cloud-build');
5454
$I->startEnvironment();
5555

56-
$cloudLog = $I->grabFileContent('/var/log/cloud.log', Docker::BUILD_CONTAINER);
56+
$cloudLog = $I->grabFileContent('/init/var/log/cloud.log', Docker::BUILD_CONTAINER);
5757

5858
$I->assertStringContainsString(
5959
'Step "copy-sample-data" was skipped',

src/Test/Functional/Acceptance/SplitDbCest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public function testSplitDb(CliTester $I, Example $data)
7171
$I->writeServicesYaml($services);
7272
$I->writeAppMagentoYaml($magentoApp);
7373

74+
// Restore app/etc after build phase
75+
$I->runDockerComposeCommand('run build bash -c "cp -r /app/init/app/etc /app/app"');
76+
7477
// Deploy 'Split Db' in an environment with prepared architecture. Case with upgrade
7578
$I->generateDockerCompose('--mode=production');
7679
foreach ($this->variationsDataPartWithSplitDbArch() as $variationData) {

src/Test/Functional/Acceptance/SplitDbWizardCest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public function testSplitDbWizard(CliTester $I, Example $data)
5959
$appMagento['relationships']['database-sales'] = 'mysql-sales:mysql';
6060
$I->writeServicesYaml($services);
6161
$I->writeAppMagentoYaml($appMagento);
62+
// Restore app/etc after build phase
63+
$I->runDockerComposeCommand('run build bash -c "cp -r /app/init/app/etc /app/app"');
6264
$I->generateDockerCompose('--mode=production');
6365

6466
foreach ($this->variationsData() as $variationData) {

src/Test/Functional/Acceptance/WizardScdCest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function _before(\CliTester $I): void
3737
public function testDefault(\CliTester $I): void
3838
{
3939
$I->runDockerComposeCommand('run build cloud-build');
40-
$I->assertFalse($I->runDockerComposeCommand('run build ece-command wizard:scd-on-build'));
40+
$I->runDockerComposeCommand('run deploy cloud-deploy');
41+
$I->assertFalse($I->runDockerComposeCommand('run deploy ece-command wizard:scd-on-build'));
4142
$I->seeInOutput(' - No stores/website/locales found in');
4243
$I->seeInOutput('SCD on build is disabled');
4344
}
@@ -50,7 +51,8 @@ public function testScdInBuildIsEnabled(\CliTester $I): void
5051
{
5152
$I->copyFileToWorkDir('files/scdinbuild/config.php', 'app/etc/config.php');
5253
$I->runDockerComposeCommand('run build cloud-build');
53-
$I->assertTrue($I->runDockerComposeCommand('run build ece-command wizard:scd-on-build'));
54+
$I->runDockerComposeCommand('run deploy cloud-deploy');
55+
$I->assertTrue($I->runDockerComposeCommand('run deploy ece-command wizard:scd-on-build'));
5456
$I->seeInOutput('SCD on build is enabled');
5557
}
5658

@@ -62,7 +64,8 @@ public function testScdOnDemandIsEnabled(\CliTester $I): void
6264
{
6365
$I->copyFileToWorkDir('files/scdondemand/.magento.env.yaml', '.magento.env.yaml');
6466
$I->runDockerComposeCommand('run build cloud-build');
65-
$I->assertTrue($I->runDockerComposeCommand('run build ece-command wizard:scd-on-demand'));
67+
$I->runDockerComposeCommand('run deploy cloud-deploy');
68+
$I->assertTrue($I->runDockerComposeCommand('run deploy ece-command wizard:scd-on-demand'));
6669
$I->seeInOutput('SCD on demand is enabled');
6770
}
6871
}

src/Test/Unit/Filesystem/DirectoryListTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ public function getWritableDirectoriesDataProvider(): array
162162
];
163163
}
164164

165+
/**
166+
* @param DirectoryList $directoryList
167+
* @return void
168+
* @dataProvider getDirectoryLists
169+
*/
170+
public function testGetMountPoints(DirectoryList $directoryList)
171+
{
172+
$paths = [
173+
'app/etc',
174+
'pub/media',
175+
'pub/static',
176+
'var'
177+
];
178+
$result = $directoryList->getMountPoints();
179+
sort($result);
180+
sort($paths);
181+
$this->assertSame($paths, $result);
182+
}
183+
165184
/**
166185
* @param DirectoryList $directoryList
167186
* @dataProvider getDirectoryLists

0 commit comments

Comments
 (0)