Skip to content

Commit

Permalink
remove separate setup-pq task, move its logic to update-env-php task,…
Browse files Browse the repository at this point in the history
… add setup for admin uri in env.php
  • Loading branch information
ejnshtein committed Jun 29, 2022
1 parent d4bc35b commit 2328851
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ const setBaseUrl = require('./set-base-url');
const disableMaintenanceMode = require('./disable-maintenance-mode');
const disable2fa = require('./disable-2fa');
const setUrlRewrite = require('./set-url-rewrite');
const updateEnvPHP = require('../../php/update-env-php');
const increaseAdminSessionLifetime = require('./increase-admin-session-lifetime');
const magentoTask = require('../../../util/magento-task');
const urnHighlighter = require('./urn-highlighter');
const waitingForVarnish = require('./waiting-for-varnish');
const setupPersistedQuery = require('../../theme/setup-persisted-query');
const adjustFullPageCache = require('./adjust-full-page-cache');

/**
Expand All @@ -28,17 +26,13 @@ const setupMagento = (options = {}) => ({
return task.newListr([
flushRedisConfig(),
waitingForRedis(),
updateEnvPHP(),
setupPersistedQuery(),
migrateDatabase({ onlyInstallMagento: true })
]);
}

return task.newListr([
flushRedisConfig(),
waitingForRedis(),
updateEnvPHP(),
setupPersistedQuery(),
migrateDatabase(),
{
title: 'Configuring Magento settings',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const installMagento = require('./install-magento');
const upgradeMagento = require('./upgrade-magento');
const varnishConfigSetup = require('./varnish-config');
const pathExists = require('../../../util/path-exists');
const updateEnvPHP = require('../../php/update-env-php');

/**
* @param {Object} [options]
Expand Down Expand Up @@ -41,6 +42,7 @@ const migrateDatabase = (options = {}) => ({

return task.newListr([
installMagento({ isDbEmpty: true }),
updateEnvPHP(),
varnishConfigSetup(),
configureElasticsearch(),
upgradeMagento(),
Expand All @@ -65,6 +67,7 @@ const migrateDatabase = (options = {}) => ({
ctx.isSetupUpgradeNeeded = false;
// no setup is needed, but still to be sure configure ES
return task.newListr([
updateEnvPHP(),
varnishConfigSetup(),
configureElasticsearch()
], {
Expand All @@ -86,6 +89,7 @@ const migrateDatabase = (options = {}) => ({

return task.newListr([
installMagentoProject(),
updateEnvPHP(),
varnishConfigSetup(),
configureElasticsearch(),
upgradeMagento(),
Expand All @@ -101,6 +105,7 @@ const migrateDatabase = (options = {}) => ({
}
case 2: {
return task.newListr([
updateEnvPHP(),
varnishConfigSetup(),
configureElasticsearch(),
upgradeMagento()
Expand Down
34 changes: 33 additions & 1 deletion build-packages/magento-scripts/lib/tasks/php/update-env-php.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const path = require('path');
const envPhpToJson = require('../../util/env-php-json');
const getJsonfileData = require('../../util/get-jsonfile-data');
const pathExists = require('../../util/path-exists');
const phpTask = require('../../util/php-task');

const composerLockPath = path.join(process.cwd(), 'composer.lock');
/**
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
*/
Expand All @@ -21,14 +24,43 @@ const updateEnvPHP = () => ({
? ctx.cachedPorts.varnish
: ctx.cachedPorts;

let SETUP_PQ = '1';

if (await pathExists(composerLockPath)) {
const composerLockData = await getJsonfileData(composerLockPath);

if (composerLockData.packages.some(({ name }) => name === 'scandipwa/persisted-query')) {
if (typeof ctx.CSAThemeInstalled !== 'boolean') {
ctx.CSAThemeInstalled = true;
}

const envPhp = await envPhpToJson(process.cwd(), { magentoVersion: ctx.magentoVersion });

const persistedQueryConfig = envPhp.cache && envPhp.cache['persisted-query'];

if (
persistedQueryConfig
&& persistedQueryConfig.redis
&& persistedQueryConfig.redis.port === `${ ctx.ports.redis }`
&& persistedQueryConfig.redis.host === 'localhost'
) {
SETUP_PQ = '';
return;
}
}
}

return task.newListr(
phpTask(`-f ${ path.join(__dirname, 'update-env.php') }`, {
noTitle: true,
env: {
USE_VARNISH: useVarnish,
VARNISH_PORT: `${ varnishPort }`,
VARNISH_HOST: varnishHost,
PREVIOUS_VARNISH_PORT: `${ previousVarnishPort }`
PREVIOUS_VARNISH_PORT: `${ previousVarnishPort }`,
SETUP_PQ,
REDIS_PORT: ctx.ports.redis,
ADMIN_URI: ctx.config.overridenConfiguration.magento.adminuri
}
})
);
Expand Down
30 changes: 22 additions & 8 deletions build-packages/magento-scripts/lib/tasks/php/update-env.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function loadPortConfig()

public function modifyConfig()
{
// set admin uri
$this->config['backend']['frontName'] = getenv('ADMIN_URI');

// update mysql config
if (isset($this->config['db']['connection']['default'])) {
$conn = &$this->config['db']['connection']['default'];
Expand Down Expand Up @@ -120,19 +123,30 @@ public function modifyConfig()
}

// update persisted query redis config
if (isset($this->config['cache']['persisted-query'])) {
$persistedQuery = &$this->config['cache']['persisted-query'];
if (getenv('SETUP_PQ') == '1') {
$cacheConfig = &$this->config['cache'];
$redisPort = getenv('REDIS_PORT');

if (isset($persistedQuery['redis'])) {
if ($persistedQuery['redis']['port'] !== strval($this->portConfig['redis'])) {
$persistedQuery['redis']['port'] = strval($this->portConfig['redis']);
}
if ($persistedQuery['redis']['host'] !== 'localhost') {
$persistedQuery['redis']['host'] = 'localhost';
if (isset($cacheConfig) && isset($cacheConfig['persisted-query']) && isset($cacheConfig['persisted-query']['redis']) && $cacheConfig['persisted-query']['redis']['port'] != $redisPort) {
$cacheConfig['persisted-query']['redis']['port'] = $redisPort;
} else {
if (!isset($cacheConfig)) {
$this->config['cache'] = [];
}
$this->config['cache']['persisted-query'] = [
'redis' => [
'host' => 'localhost',
'port' => $redisPort,
'database' => '5',
'scheme' => 'tcp'
]
];
}
} else {
unset($this->config['cache']['persisted-query']);
}

// set varnish config
$httpCacheHosts = &$this->config['http_cache_hosts'];
$httpCacheHosts = [];

Expand Down
2 changes: 0 additions & 2 deletions build-packages/magento-scripts/lib/tasks/theme/link-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const adjustFullPageCache = require('../magento/setup-magento/adjust-full-page-c
const disablePageBuilder = require('../magento/setup-magento/disable-page-builder');
const buildTheme = require('./build-theme');
const upgradeMagento = require('../magento/setup-magento/upgrade-magento');
const setupPersistedQuery = require('./setup-persisted-query');
const updateEnvPHP = require('../php/update-env-php');
const semver = require('semver');

Expand Down Expand Up @@ -51,7 +50,6 @@ const linkTheme = () => ({
symlinkTheme(theme),
installTheme(theme),
updateEnvPHP(),
setupPersistedQuery(),
upgradeMagento(),
adjustFullPageCache(),
...(isPageBuilderInstalled && Number(isPagebuilderEnabled) ? [disablePageBuilder()] : []),
Expand Down

This file was deleted.

0 comments on commit 2328851

Please sign in to comment.