Skip to content

Commit 3a8a3e6

Browse files
MAGECLOUD-1369: Unified environment configs (#132)
1 parent 477ab92 commit 3a8a3e6

File tree

68 files changed

+1470
-1078
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1470
-1078
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"phpmd src xml tests/static/phpmd-ruleset.xml",
4949
"phpunit --configuration tests/unit/phpunit.xml.dist"
5050
],
51-
"test-coverage": "phpunit --configuration tests/unit/phpunit.xml.dist --coverage-html tests/unit/tmp/coverage"
51+
"test-coverage": "phpunit --configuration tests/unit/phpunit.xml.dist --coverage-clover tests/unit/tmp/clover.xml && php tests/unit/code-coverage.php tests/unit/tmp/clover.xml 85",
52+
"test-coverage-generate": "phpunit --configuration tests/unit/phpunit.xml.dist --coverage-html tests/unit/tmp/coverage"
5253
},
5354
"prefer-stable": true
5455
}

src/App/Container.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ function () {
9898
\Magento\MagentoCloud\DB\Dump::class
9999
);
100100
$this->container->singleton(\Magento\MagentoCloud\Config\Environment::class);
101-
$this->container->singleton(\Magento\MagentoCloud\Config\Build::class);
102-
$this->container->singleton(\Magento\MagentoCloud\Config\Deploy::class);
101+
$this->container->singleton(\Magento\MagentoCloud\Config\State::class);
103102
$this->container->singleton(\Psr\Log\LoggerInterface::class, \Magento\MagentoCloud\App\Logger::class);
104103
$this->container->singleton(\Magento\MagentoCloud\Package\Manager::class);
105104
$this->container->singleton(\Magento\MagentoCloud\Package\MagentoVersion::class);
@@ -115,6 +114,14 @@ function () {
115114
$this->container->singleton(\Magento\MagentoCloud\Config\Stage\Build::class);
116115
$this->container->singleton(\Magento\MagentoCloud\Config\Stage\Deploy::class);
117116
$this->container->singleton(\Magento\MagentoCloud\Config\RepositoryFactory::class);
117+
$this->container->singleton(
118+
\Magento\MagentoCloud\Config\Stage\BuildInterface::class,
119+
\Magento\MagentoCloud\Config\Stage\Build::class
120+
);
121+
$this->container->singleton(
122+
\Magento\MagentoCloud\Config\Stage\DeployInterface::class,
123+
\Magento\MagentoCloud\Config\Stage\Deploy::class
124+
);
118125
/**
119126
* Contextual binding.
120127
*/
@@ -304,9 +311,6 @@ function () {
304311
],
305312
]);
306313
});
307-
$this->container->when(\Magento\MagentoCloud\Config\Build::class)
308-
->needs(\Magento\MagentoCloud\Filesystem\Reader\ReaderInterface::class)
309-
->give(\Magento\MagentoCloud\Config\Build\Reader::class);
310314
$this->container->when(BuildProcess\DeployStaticContent::class)
311315
->needs(ProcessInterface::class)
312316
->give(function () {
@@ -338,18 +342,6 @@ function () {
338342
],
339343
]);
340344
});
341-
$this->container->when(BuildProcess\DeployStaticContent::class)
342-
->needs(StageConfigInterface::class)
343-
->give(BuildConfig::class);
344-
$this->container->when(\Magento\MagentoCloud\StaticContent\Build\Option::class)
345-
->needs(StageConfigInterface::class)
346-
->give(BuildConfig::class);
347-
$this->container->when(\Magento\MagentoCloud\StaticContent\Deploy\Option::class)
348-
->needs(StageConfigInterface::class)
349-
->give(DeployConfig::class);
350-
$this->container->when(\Magento\MagentoCloud\StaticContent\Prestart\Option::class)
351-
->needs(StageConfigInterface::class)
352-
->give(BuildConfig::class);
353345
}
354346

355347
/**

src/Config/Build.php

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

src/Config/Environment.php

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ class Environment
3131
const DEFAULT_ADMIN_FIRSTNAME = 'Admin';
3232
const DEFAULT_ADMIN_LASTNAME = 'Username';
3333

34-
/**
35-
* Variables.
36-
*/
37-
const VAR_QUEUE_CONFIGURATION = 'QUEUE_CONFIGURATION';
38-
const VAR_SEARCH_CONFIGURATION = 'SEARCH_CONFIGURATION';
39-
const VAR_REDIS_SESSION_DISABLE_LOCKING = 'REDIS_SESSION_DISABLE_LOCKING';
40-
const VAR_SCD_COMPRESSION_LEVEL = Build::OPT_SCD_COMPRESSION_LEVEL;
41-
4234
/**
4335
* @var LoggerInterface
4436
*/
@@ -159,31 +151,6 @@ public function getVariable($name, $default = null)
159151
return $this->getVariables()[$name] ?? $default;
160152
}
161153

162-
/**
163-
* Checks that static content symlink is on.
164-
*
165-
* If STATIC_CONTENT_SYMLINK == disabled return false
166-
* Returns true by default
167-
*
168-
* @return bool
169-
*/
170-
public function isStaticContentSymlinkOn(): bool
171-
{
172-
$var = $this->getVariables();
173-
174-
return isset($var['STATIC_CONTENT_SYMLINK']) && $var['STATIC_CONTENT_SYMLINK'] == 'disabled' ? false : true;
175-
}
176-
177-
/**
178-
* @return string
179-
*/
180-
public function getVerbosityLevel(): string
181-
{
182-
$var = $this->getVariables();
183-
184-
return isset($var['VERBOSE_COMMANDS']) && $var['VERBOSE_COMMANDS'] == 'enabled' ? ' -vvv ' : '';
185-
}
186-
187154
/**
188155
* @return string
189156
*/
@@ -212,43 +179,7 @@ public function getWritableDirectories(): array
212179
*/
213180
public function isDeployStaticContent(): bool
214181
{
215-
$var = $this->getVariables();
216-
217-
/**
218-
* Can use environment variable to always disable.
219-
* Default is to deploy static content if it was not deployed in the build step.
220-
*/
221-
if (isset($var['DO_DEPLOY_STATIC_CONTENT']) && $var['DO_DEPLOY_STATIC_CONTENT'] == 'disabled') {
222-
$flag = false;
223-
} else {
224-
$flag = !$this->flagFilePool->getFlag(StaticContentDeployFlag::KEY)->exists();
225-
}
226-
227-
$this->logger->info('Flag DO_DEPLOY_STATIC_CONTENT is set to ' . ($flag ? 'enabled' : 'disabled'));
228-
229-
return $flag;
230-
}
231-
232-
/**
233-
* @return int
234-
*/
235-
public function getStaticDeployThreadsCount(): int
236-
{
237-
/**
238-
* Use 1 for PAAS environment.
239-
*/
240-
$staticDeployThreads = 1;
241-
$var = $this->getVariables();
242-
243-
if (isset($var['STATIC_CONTENT_THREADS'])) {
244-
$staticDeployThreads = (int)$var['STATIC_CONTENT_THREADS'];
245-
} elseif (isset($_ENV['STATIC_CONTENT_THREADS'])) {
246-
$staticDeployThreads = (int)$_ENV['STATIC_CONTENT_THREADS'];
247-
} elseif (isset($_ENV['MAGENTO_CLOUD_MODE']) && $_ENV['MAGENTO_CLOUD_MODE'] === static::CLOUD_MODE_ENTERPRISE) {
248-
$staticDeployThreads = 3;
249-
}
250-
251-
return $staticDeployThreads;
182+
return !$this->flagFilePool->getFlag(StaticContentDeployFlag::KEY)->exists();
252183
}
253184

254185
/**
@@ -259,24 +190,6 @@ public function getAdminLocale(): string
259190
return $this->getVariables()['ADMIN_LOCALE'] ?? 'en_US';
260191
}
261192

262-
/**
263-
* @return bool
264-
*/
265-
public function doCleanStaticFiles(): bool
266-
{
267-
$var = $this->getVariables();
268-
269-
return !(isset($var['CLEAN_STATIC_FILES']) && $var['CLEAN_STATIC_FILES'] === static::VAL_DISABLED);
270-
}
271-
272-
/**
273-
* @return string
274-
*/
275-
public function getStaticDeployExcludeThemes(): string
276-
{
277-
return $this->getVariable('STATIC_CONTENT_EXCLUDE_THEMES', '');
278-
}
279-
280193
/**
281194
* @return string|float
282195
*/
@@ -357,24 +270,6 @@ public function getAdminUrl(): string
357270
return $this->getVariables()['ADMIN_URL'] ?? '';
358271
}
359272

360-
/**
361-
* @return array
362-
*/
363-
public function getCronConsumersRunner(): array
364-
{
365-
return $this->getJsonVariable('CRON_CONSUMERS_RUNNER');
366-
}
367-
368-
/**
369-
* @return bool
370-
*/
371-
public function isUpdateUrlsEnabled(): bool
372-
{
373-
$var = $this->getVariables();
374-
375-
return isset($var['UPDATE_URLS']) && $var['UPDATE_URLS'] == 'disabled' ? false : true;
376-
}
377-
378273
/**
379274
* @return string
380275
*/
@@ -391,21 +286,4 @@ public function isMasterBranch(): bool
391286
return isset($_ENV['MAGENTO_CLOUD_ENVIRONMENT'])
392287
&& preg_match(self::GIT_MASTER_BRANCH_RE, $_ENV['MAGENTO_CLOUD_ENVIRONMENT']);
393288
}
394-
395-
/**
396-
* Returns variable that was set in json format.
397-
*
398-
* @param string $name
399-
* @return array
400-
*/
401-
public function getJsonVariable(string $name): array
402-
{
403-
$config = $this->getVariable($name, []);
404-
405-
if (!is_array($config)) {
406-
$config = (array)json_decode($config, true);
407-
}
408-
409-
return $config;
410-
}
411289
}

0 commit comments

Comments
 (0)