Skip to content

Commit 9cebb0f

Browse files
committed
MAGECLOUD-1057: Add possibility to change SCD strategy
1 parent 7ddb18c commit 9cebb0f

File tree

17 files changed

+1056
-588
lines changed

17 files changed

+1056
-588
lines changed

src/Magento/MagentoCloud/App/Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function __construct(string $root, array $config)
161161
->give(function () {
162162
return $this->makeWith(ProcessPool::class, [
163163
'processes' => [
164-
$this->get(DeployProcess\DeployStaticContent\GenerateFresh::class),
164+
$this->get(DeployProcess\DeployStaticContent\Generate::class),
165165
],
166166
]);
167167
});
@@ -173,7 +173,7 @@ public function __construct(string $root, array $config)
173173
->give(function () {
174174
return $this->makeWith(ProcessPool::class, [
175175
'processes' => [
176-
$this->get(BuildProcess\DeployStaticContent\GenerateFresh::class),
176+
$this->get(BuildProcess\DeployStaticContent\Generate::class),
177177
],
178178
]);
179179
});

src/Magento/MagentoCloud/Config/Build.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function __construct(ReaderInterface $reader)
3838

3939
/**
4040
* @param string $key
41-
* @param mixed $default
42-
* @return mixed
41+
* @param string|null $default
42+
* @return string|null
4343
*/
4444
public function get(string $key, $default = null)
4545
{
@@ -57,14 +57,4 @@ public function getVerbosityLevel(): string
5757
{
5858
return $this->get(static::OPT_VERBOSE_COMMANDS) === 'enabled' ? ' -vv ' : '';
5959
}
60-
61-
/**
62-
* @return string
63-
*/
64-
public function getScdStrategy(): string
65-
{
66-
$strategy = $this->get(static::OPT_SCD_STRATEGY);
67-
68-
return $strategy ? '-s ' . $strategy : '';
69-
}
7060
}

src/Magento/MagentoCloud/Config/Environment.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public function getVariables(): array
129129
return $this->data['variables'] = $this->get('MAGENTO_CLOUD_VARIABLES', []);
130130
}
131131

132+
/**
133+
* Returns variable value if such variable exists otherwise return $default
134+
*
135+
* @param string $name
136+
* @param mixed $default
137+
* @return mixed
138+
*/
139+
public function getVariable($name, $default = null)
140+
{
141+
return $this->getVariables()[$name] ?? $default;
142+
}
143+
132144
/**
133145
* Checks that static content symlink is on.
134146
*
@@ -294,7 +306,7 @@ public function doCleanStaticFiles(): bool
294306
*/
295307
public function getStaticDeployExcludeThemes(): string
296308
{
297-
return $this->getVariables()['STATIC_CONTENT_EXCLUDE_THEMES'] ?? '';
309+
return $this->getVariable('STATIC_CONTENT_EXCLUDE_THEMES', '');
298310
}
299311

300312
/**
@@ -403,14 +415,4 @@ public function isMasterBranch(): bool
403415
return isset($_ENV['MAGENTO_CLOUD_ENVIRONMENT'])
404416
&& preg_match(self::GIT_MASTER_BRANCH_RE, $_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
405417
}
406-
407-
/**
408-
* @return string
409-
*/
410-
public function getScdStrategy(): string
411-
{
412-
$var = $this->getVariables();
413-
414-
return !empty($var[static::VAR_SCD_STRATEGY]) ? '-s ' . $var[static::VAR_SCD_STRATEGY] : '';
415-
}
416418
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MagentoCloud\Process\Build\DeployStaticContent;
7+
8+
use Magento\MagentoCloud\Config\Environment;
9+
use Magento\MagentoCloud\Process\ProcessInterface;
10+
use Magento\MagentoCloud\Shell\ShellInterface;
11+
use Magento\MagentoCloud\StaticContent\Build\Option;
12+
use Magento\MagentoCloud\StaticContent\Command;
13+
use Psr\Log\LoggerInterface;
14+
15+
/**
16+
* @inheritdoc
17+
*/
18+
class Generate implements ProcessInterface
19+
{
20+
/**
21+
* @var ShellInterface
22+
*/
23+
private $shell;
24+
25+
/**
26+
* @var LoggerInterface
27+
*/
28+
private $logger;
29+
/**
30+
* @var Environment
31+
*/
32+
private $environment;
33+
34+
/**
35+
* @var Command
36+
*/
37+
private $scdCommand;
38+
39+
/**
40+
* @var Option
41+
*/
42+
private $buildOption;
43+
44+
/**
45+
* @param ShellInterface $shell
46+
* @param LoggerInterface $logger
47+
* @param Environment $environment
48+
* @param Command $scdCommand
49+
* @param Option $buildOption
50+
*/
51+
public function __construct(
52+
ShellInterface $shell,
53+
LoggerInterface $logger,
54+
Environment $environment,
55+
Command $scdCommand,
56+
Option $buildOption
57+
) {
58+
$this->shell = $shell;
59+
$this->logger = $logger;
60+
$this->environment = $environment;
61+
$this->scdCommand = $scdCommand;
62+
$this->buildOption = $buildOption;
63+
}
64+
65+
/**
66+
* @inheritdoc
67+
*/
68+
public function execute()
69+
{
70+
try {
71+
$locales = $this->buildOption->getLocales();
72+
$excludeThemes = $this->buildOption->getExcludedThemes();
73+
$threadCount= $this->buildOption->getTreadCount();
74+
75+
$logMessage = 'Generating static content for locales: ' . implode(' ', $locales);
76+
77+
if (count($excludeThemes)) {
78+
$logMessage .= PHP_EOL . 'Excluding Themes: ' . implode(' ', $excludeThemes);
79+
}
80+
81+
if ($threadCount) {
82+
$logMessage .= PHP_EOL . 'Using ' . $threadCount . ' Threads';
83+
}
84+
85+
$this->logger->info($logMessage);
86+
87+
$parallelCommands = $this->scdCommand->createParallel($this->buildOption);
88+
89+
$this->shell->execute(sprintf(
90+
"printf '%s' | xargs -I CMD -P %d bash -c CMD",
91+
$parallelCommands,
92+
$threadCount
93+
));
94+
95+
$this->environment->setFlagStaticDeployInBuild();
96+
} catch (\Exception $e) {
97+
throw new \Exception($e->getMessage(), 5);
98+
}
99+
}
100+
}

src/Magento/MagentoCloud/Process/Build/DeployStaticContent/GenerateFresh.php

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)