@scandipwa/magento-scripts 1.16.1 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/cli.js +2 -4
- package/lib/commands/execute.js +28 -3
- package/lib/commands/start.js +37 -15
- package/lib/commands/status.js +2 -0
- package/lib/config/docker.js +65 -42
- package/lib/config/get-project-configuration.js +3 -1
- package/lib/config/index.js +10 -7
- package/lib/config/magento/required-php-extensions/index.js +29 -0
- package/lib/config/magento/required-php-extensions/magento-2.3.js +19 -0
- package/lib/config/magento/required-php-extensions/magento-2.4.js +29 -0
- package/lib/config/php/base-repo.js +3 -0
- package/lib/config/php/extensions/apcu.js +12 -0
- package/lib/config/php/extensions/bcmath.js +7 -0
- package/lib/config/php/extensions/curl.js +11 -0
- package/lib/config/php/extensions/gd.js +14 -0
- package/lib/config/php/extensions/index.js +18 -2
- package/lib/config/php/extensions/intl.js +10 -0
- package/lib/config/php/extensions/opcache.js +10 -0
- package/lib/config/php/extensions/pdo_mysql.js +7 -0
- package/lib/config/php/extensions/soap.js +10 -0
- package/lib/config/php/extensions/sodium.js +10 -0
- package/lib/config/php/extensions/xdebug.js +8 -5
- package/lib/config/php/extensions/xsl.js +10 -0
- package/lib/config/php/extensions/zip.js +10 -0
- package/lib/config/php/{releases → versions}/index.js +0 -0
- package/lib/config/php/versions/php-7.2.js +23 -0
- package/lib/config/php/versions/php-7.3.js +23 -0
- package/lib/config/php/versions/php-7.4.js +23 -0
- package/lib/config/php/versions/php-8.1.js +23 -0
- package/lib/config/php-config.js +8 -12
- package/lib/config/port-config.js +1 -5
- package/lib/config/templates/magentorc.template +3 -3
- package/lib/config/templates/php-fpm.template.conf +3 -3
- package/lib/config/templates/php.template.ini +12 -6
- package/lib/config/templates/ssl-terminator.template.conf +1 -1
- package/lib/config/templates/vscode-launch.template.json +3 -1
- package/lib/config/versions/magento-2.3.0.js +8 -2
- package/lib/config/versions/magento-2.3.1.js +8 -2
- package/lib/config/versions/magento-2.3.2-p1.js +44 -0
- package/lib/config/versions/magento-2.3.2-p2.js +8 -2
- package/lib/config/versions/magento-2.3.2.js +8 -2
- package/lib/config/versions/magento-2.3.3-p1.js +8 -2
- package/lib/config/versions/magento-2.3.3.js +8 -2
- package/lib/config/versions/magento-2.3.4-p1.js +44 -0
- package/lib/config/versions/magento-2.3.4-p2.js +8 -2
- package/lib/config/versions/magento-2.3.4.js +8 -2
- package/lib/config/versions/magento-2.3.5-p1.js +8 -2
- package/lib/config/versions/magento-2.3.5-p2.js +8 -2
- package/lib/config/versions/magento-2.3.5.js +8 -2
- package/lib/config/versions/magento-2.3.6-p1.js +8 -2
- package/lib/config/versions/magento-2.3.6.js +8 -2
- package/lib/config/versions/magento-2.3.7-p1.js +8 -2
- package/lib/config/versions/magento-2.3.7-p2.js +8 -2
- package/lib/config/versions/magento-2.3.7-p3.js +8 -2
- package/lib/config/versions/magento-2.3.7.js +8 -2
- package/lib/config/versions/magento-2.4.0-p1.js +9 -3
- package/lib/config/versions/magento-2.4.0.js +9 -3
- package/lib/config/versions/magento-2.4.1-p1.js +6 -5
- package/lib/config/versions/magento-2.4.1.js +9 -2
- package/lib/config/versions/magento-2.4.2-p1.js +6 -5
- package/lib/config/versions/magento-2.4.2-p2.js +6 -6
- package/lib/config/versions/magento-2.4.2.js +6 -6
- package/lib/config/versions/magento-2.4.3-p1.js +7 -7
- package/lib/config/versions/magento-2.4.3-p2.js +7 -7
- package/lib/config/versions/magento-2.4.3.js +7 -7
- package/lib/config/versions/magento-2.4.4.js +9 -2
- package/lib/tasks/cleanup.js +2 -2
- package/lib/tasks/composer/index.js +14 -104
- package/lib/tasks/docker/api.d.ts +71 -0
- package/lib/tasks/docker/api.js +30 -0
- package/lib/tasks/docker/containers/container-api.d.ts +128 -0
- package/lib/tasks/docker/containers/container-api.js +153 -0
- package/lib/tasks/docker/containers/index.js +19 -0
- package/lib/tasks/docker/containers/tasks.js +215 -0
- package/lib/tasks/docker/convert-legacy-volumes.js +7 -3
- package/lib/tasks/docker/image/image-api.d.ts +34 -0
- package/lib/tasks/docker/image/image-api.js +49 -0
- package/lib/tasks/docker/image/index.js +5 -0
- package/lib/tasks/docker/index.js +1 -13
- package/lib/tasks/docker/network/index.js +7 -0
- package/lib/tasks/docker/network/network-api.d.ts +103 -0
- package/lib/tasks/docker/network/network-api.js +99 -0
- package/lib/tasks/docker/{network.js → network/tasks.js} +17 -10
- package/lib/tasks/docker/project-image-builder.js +167 -0
- package/lib/tasks/docker/volumes.js +1 -1
- package/lib/tasks/file-system/create-nginx-config.js +2 -3
- package/lib/tasks/file-system/create-php-config.js +20 -5
- package/lib/tasks/file-system/create-php-fpm-config.js +8 -4
- package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +41 -29
- package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -0
- package/lib/tasks/file-system/create-phpstorm-config/keys.js +15 -1
- package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +4 -1
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +3 -3
- package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +81 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +42 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +9 -0
- package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +66 -0
- package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +11 -9
- package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +2 -1
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +15 -30
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +24 -5
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +15 -15
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +29 -3
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +42 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +50 -0
- package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +0 -2
- package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -2
- package/lib/tasks/file-system/create-vscode-config.js +57 -42
- package/lib/tasks/file-system/index.js +2 -1
- package/lib/tasks/link.js +1 -2
- package/lib/tasks/magento/install-magento-project.js +31 -63
- package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +4 -4
- package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +6 -2
- package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
- package/lib/tasks/magento/setup-magento/disable-2fa.js +3 -5
- package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +3 -4
- package/lib/tasks/magento/setup-magento/install-magento.js +10 -9
- package/lib/tasks/magento/setup-magento/migrate-database.js +7 -8
- package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
- package/lib/tasks/magento/setup-magento/varnish-config.js +6 -4
- package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
- package/lib/tasks/mysql/connect-to-mysql.js +34 -21
- package/lib/tasks/mysql/import-dump-to-mysql.js +46 -3
- package/lib/tasks/php/php-container.js +108 -0
- package/lib/tasks/php/update-env-php.js +35 -19
- package/lib/tasks/php/update-env.php +61 -56
- package/lib/tasks/php/working_health_check.php +85 -0
- package/lib/tasks/requirements/{composer.js → composer-credentials.js} +3 -1
- package/lib/tasks/requirements/docker/index.js +15 -12
- package/lib/tasks/requirements/docker/performance.js +54 -0
- package/lib/tasks/requirements/docker/version.js +8 -8
- package/lib/tasks/requirements/index.js +5 -8
- package/lib/tasks/requirements/php-version.js +8 -116
- package/lib/tasks/requirements/platform.js +12 -25
- package/lib/tasks/start.js +38 -47
- package/lib/tasks/status/index.js +4 -10
- package/lib/tasks/stop.js +0 -2
- package/lib/tasks/theme/install-theme.js +1 -1
- package/lib/tasks/theme/symlink-theme.js +2 -3
- package/lib/util/config-php-json.js +13 -4
- package/lib/util/dockerfile-builder/build-instructions.js +197 -0
- package/lib/util/dockerfile-builder/index.js +276 -0
- package/lib/util/dockerfile-builder/types.d.ts +123 -0
- package/lib/util/env-php-json.js +10 -6
- package/lib/util/exec-async-command.js +3 -9
- package/lib/util/macos-version.js +20 -0
- package/lib/util/magento-task.js +3 -4
- package/lib/util/nginx-logs-parser.js +122 -0
- package/lib/util/php-task.js +3 -6
- package/lib/util/prefix.js +1 -1
- package/lib/util/run-composer.js +6 -14
- package/lib/util/run-container-image.js +17 -0
- package/lib/util/run-magento.js +6 -14
- package/lib/util/run-php.js +6 -17
- package/package.json +9 -9
- package/typings/context.d.ts +3 -9
- package/typings/index.d.ts +38 -57
- package/lib/config/composer.js +0 -11
- package/lib/config/php/extensions/libsodium.js +0 -36
- package/lib/config/php/releases/php-7.2.js +0 -25
- package/lib/config/php/releases/php-7.3.js +0 -25
- package/lib/config/php/releases/php-7.4.js +0 -23
- package/lib/config/php/releases/php-8.1.js +0 -25
- package/lib/config/phpbrew.js +0 -12
- package/lib/tasks/composer/install-prestissimo.js +0 -103
- package/lib/tasks/docker/containers.js +0 -231
- package/lib/tasks/php/bundled-extensions.js +0 -27
- package/lib/tasks/php/compile-options.js +0 -56
- package/lib/tasks/php/compile.js +0 -55
- package/lib/tasks/php/configure.js +0 -89
- package/lib/tasks/php/extensions/disable.js +0 -49
- package/lib/tasks/php/extensions/enable.js +0 -52
- package/lib/tasks/php/extensions/index.js +0 -80
- package/lib/tasks/php/extensions/install.js +0 -54
- package/lib/tasks/php/index.js +0 -79
- package/lib/tasks/php/install-sodium.js +0 -93
- package/lib/tasks/php/update-phpbrew.js +0 -45
- package/lib/tasks/php/validate-php.js +0 -67
- package/lib/tasks/php-fpm/get-process-id.js +0 -14
- package/lib/tasks/php-fpm/index.js +0 -4
- package/lib/tasks/php-fpm/start-php-fpm.js +0 -49
- package/lib/tasks/php-fpm/stop-php-fpm.js +0 -48
- package/lib/tasks/requirements/phpbrew/index.js +0 -61
- package/lib/tasks/requirements/phpbrew/install.js +0 -159
- package/lib/tasks/requirements/phpbrew/version.js +0 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const mysql2 = require('mysql2/promise');
|
|
2
2
|
const UnknownError = require('../../errors/unknown-error');
|
|
3
3
|
const { execAsyncSpawn } = require('../../util/exec-async-command');
|
|
4
4
|
const sleep = require('../../util/sleep');
|
|
@@ -10,10 +10,14 @@ const { createMagentoDatabase } = require('./create-magento-database');
|
|
|
10
10
|
const waitForMySQLInitialization = () => ({
|
|
11
11
|
title: 'Waiting for MySQL to initialize',
|
|
12
12
|
task: async (ctx, task) => {
|
|
13
|
-
const { mysql
|
|
13
|
+
const { mysql } = ctx.config.docker.getContainers();
|
|
14
|
+
|
|
15
|
+
task.title = `Waiting for ${mysql._} to initialize`;
|
|
16
|
+
|
|
14
17
|
let mysqlReadyForConnections = false;
|
|
18
|
+
|
|
15
19
|
while (!mysqlReadyForConnections) {
|
|
16
|
-
const mysqlOutput = await execAsyncSpawn(`docker logs ${name}`);
|
|
20
|
+
const mysqlOutput = await execAsyncSpawn(`docker logs ${mysql.name}`);
|
|
17
21
|
if (mysqlOutput.includes('ready for connections')) {
|
|
18
22
|
mysqlReadyForConnections = true;
|
|
19
23
|
break;
|
|
@@ -23,7 +27,7 @@ Please wait, this will take some time and do not restart the MySQL container unt
|
|
|
23
27
|
|
|
24
28
|
let mysqlFinishedInitialization = false;
|
|
25
29
|
while (!mysqlFinishedInitialization) {
|
|
26
|
-
const mysqlOutput = await execAsyncSpawn(`docker logs ${name}`);
|
|
30
|
+
const mysqlOutput = await execAsyncSpawn(`docker logs ${mysql.name}`);
|
|
27
31
|
if (mysqlOutput.includes('init process done.') && !mysqlFinishedInitialization) {
|
|
28
32
|
mysqlFinishedInitialization = true;
|
|
29
33
|
break;
|
|
@@ -47,19 +51,22 @@ const gettingMySQLConnection = () => ({
|
|
|
47
51
|
title: 'Getting MySQL connection',
|
|
48
52
|
task: async (ctx, task) => {
|
|
49
53
|
const { config: { docker }, ports } = ctx;
|
|
50
|
-
const { mysql
|
|
54
|
+
const { mysql } = docker.getContainers(ctx.ports);
|
|
51
55
|
let tries = 0;
|
|
52
56
|
const maxTries = 20;
|
|
53
57
|
const errors = [];
|
|
58
|
+
|
|
59
|
+
task.title = `Getting ${mysql._} connection`;
|
|
60
|
+
|
|
54
61
|
while (tries < maxTries) {
|
|
55
62
|
tries++;
|
|
56
63
|
try {
|
|
57
|
-
const connection = await
|
|
64
|
+
const connection = await mysql2.createConnection({
|
|
58
65
|
host: '127.0.0.1',
|
|
59
66
|
port: ports.mysql,
|
|
60
|
-
user: env.MYSQL_USER,
|
|
61
|
-
password: env.MYSQL_PASSWORD,
|
|
62
|
-
database: env.MYSQL_DATABASE
|
|
67
|
+
user: mysql.env.MYSQL_USER,
|
|
68
|
+
password: mysql.env.MYSQL_PASSWORD,
|
|
69
|
+
database: mysql.env.MYSQL_DATABASE
|
|
63
70
|
});
|
|
64
71
|
|
|
65
72
|
ctx.mysqlConnection = connection;
|
|
@@ -82,7 +89,7 @@ const gettingMySQLConnection = () => ({
|
|
|
82
89
|
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
83
90
|
*/
|
|
84
91
|
const terminatingExistingConnection = () => ({
|
|
85
|
-
title: 'Terminating existing
|
|
92
|
+
title: 'Terminating existing Database connection',
|
|
86
93
|
skip: (ctx) => !ctx.mysqlConnection,
|
|
87
94
|
task: (ctx) => {
|
|
88
95
|
ctx.mysqlConnection.destroy();
|
|
@@ -95,17 +102,23 @@ const terminatingExistingConnection = () => ({
|
|
|
95
102
|
const connectToMySQL = () => ({
|
|
96
103
|
title: 'Connecting to MySQL server',
|
|
97
104
|
skip: (ctx) => ctx.skipSetup,
|
|
98
|
-
task: (ctx, task) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
task: (ctx, task) => {
|
|
106
|
+
const { mysql } = ctx.config.docker.getContainers();
|
|
107
|
+
|
|
108
|
+
task.title = `Connecting to ${mysql._} server`;
|
|
109
|
+
|
|
110
|
+
return task.newListr([
|
|
111
|
+
waitForMySQLInitialization(),
|
|
112
|
+
createMagentoDatabase(),
|
|
113
|
+
terminatingExistingConnection(),
|
|
114
|
+
gettingMySQLConnection()
|
|
115
|
+
], {
|
|
116
|
+
concurrent: false,
|
|
117
|
+
rendererOptions: {
|
|
118
|
+
collapse: true
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
},
|
|
109
122
|
options: {
|
|
110
123
|
bottomBar: 10
|
|
111
124
|
}
|
|
@@ -111,12 +111,55 @@ const executeImportDumpSQL = () => ({
|
|
|
111
111
|
}
|
|
112
112
|
);
|
|
113
113
|
} catch (e) {
|
|
114
|
-
if (e.includes('Unknown collation: \'utf8mb4_0900_ai_ci\'')) {
|
|
115
|
-
|
|
114
|
+
if (e.message.includes('Unknown collation: \'utf8mb4_0900_ai_ci\'')) {
|
|
115
|
+
const confirmFixingCollation = await task.prompt({
|
|
116
|
+
type: 'Select',
|
|
117
|
+
message: `We got the following error while trying to import ${logger.style.file('dump.sql')}!
|
|
118
|
+
|
|
119
|
+
${e.message}
|
|
120
|
+
|
|
121
|
+
To fix this error we suggest running the following commands:
|
|
122
|
+
${logger.style.command('sed -i \'s/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g\' dump.sql')}
|
|
123
|
+
`,
|
|
124
|
+
choices: [
|
|
125
|
+
{
|
|
126
|
+
name: 'yes',
|
|
127
|
+
message: 'Yes, run the following commands, I reaaaalllyy want dump to work! (this will not edit original dump.sql)'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'no',
|
|
131
|
+
message: 'Okay, I got it. Will try to fix myself'
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (confirmFixingCollation === 'yes') {
|
|
137
|
+
task.output = 'Running fix command...';
|
|
138
|
+
await execAsyncSpawn(`docker exec ${mysql.name} bash -c "sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' dump.sql"`);
|
|
139
|
+
|
|
140
|
+
task.output = 'Trying to import dump again...';
|
|
141
|
+
try {
|
|
142
|
+
await execAsyncSpawn(
|
|
143
|
+
importCommand,
|
|
144
|
+
{
|
|
145
|
+
callback: (t) => {
|
|
146
|
+
task.output = t;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
return;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
throw new KnownError(`Fixing ${logger.style.file('dump.sql')} collations did not helped, we got the following error:
|
|
154
|
+
${e.message}`);
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
throw new KnownError(`Database dump import unsuccessful!
|
|
116
158
|
|
|
117
|
-
${e}
|
|
159
|
+
${e.message}
|
|
118
160
|
|
|
119
161
|
You can try replacing all occurrences of ${logger.style.misc('utf8mb4_0900_ai_ci')} with ${logger.style.misc('utf8mb4_general_ci')} in your ${logger.style.file(ctx.importDb)} file!`);
|
|
162
|
+
}
|
|
120
163
|
}
|
|
121
164
|
|
|
122
165
|
throw new UnknownError(`Unexpected error during dump import.\n\n${e}`);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
const { deepmerge } = require('../../util/deepmerge');
|
|
3
|
+
const { containerApi } = require('../docker/containers');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('../../../typings/context').ListrContext} ctx
|
|
7
|
+
* @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions<false> & { useXDebugContainer?: boolean }} [options]
|
|
8
|
+
* @param {string} command
|
|
9
|
+
*/
|
|
10
|
+
const runPHPContainerCommand = async (ctx, command, options = {}) => {
|
|
11
|
+
const { php } = ctx.config.docker.getContainers(ctx.ports);
|
|
12
|
+
|
|
13
|
+
const containers = await containerApi.ls({ formatToJSON: true, all: true });
|
|
14
|
+
|
|
15
|
+
if (containers.some((c) => c.Names === php.name)) {
|
|
16
|
+
return execPHPContainerCommand(ctx, command, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return containerApi.run(
|
|
20
|
+
deepmerge(
|
|
21
|
+
php,
|
|
22
|
+
{
|
|
23
|
+
detach: false,
|
|
24
|
+
rm: true
|
|
25
|
+
},
|
|
26
|
+
options.useXDebugContainer
|
|
27
|
+
? {
|
|
28
|
+
image: `${ php.image }.xdebug`
|
|
29
|
+
}
|
|
30
|
+
: {},
|
|
31
|
+
{
|
|
32
|
+
command
|
|
33
|
+
},
|
|
34
|
+
),
|
|
35
|
+
options
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {string} command
|
|
41
|
+
* @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions<false> & { useXDebugContainer?: boolean }} [options]
|
|
42
|
+
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
43
|
+
*/
|
|
44
|
+
const runPHPContainerCommandTask = (command, options = {}) => ({
|
|
45
|
+
title: `Running command "${command}"`,
|
|
46
|
+
task: (ctx, task) => runPHPContainerCommand(ctx, command, {
|
|
47
|
+
callback: !ctx.verbose ? undefined : (t) => {
|
|
48
|
+
task.output = t;
|
|
49
|
+
},
|
|
50
|
+
...options
|
|
51
|
+
}),
|
|
52
|
+
option: {
|
|
53
|
+
bottomBar: 10
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {import('../../../typings/context').ListrContext} ctx
|
|
60
|
+
* @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions<false> & { useXDebugContainer?: boolean }} [options]
|
|
61
|
+
* @param {string} command
|
|
62
|
+
*/
|
|
63
|
+
const execPHPContainerCommand = async (ctx, command, options = {}) => {
|
|
64
|
+
const { php } = ctx.config.docker.getContainers(ctx.ports);
|
|
65
|
+
|
|
66
|
+
const containers = await containerApi.ls({ formatToJSON: true, all: true });
|
|
67
|
+
|
|
68
|
+
if (!containers.some((c) => c.Names === php.name)) {
|
|
69
|
+
return runPHPContainerCommand(ctx, command, options);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return containerApi.exec(
|
|
73
|
+
command,
|
|
74
|
+
php.name,
|
|
75
|
+
deepmerge(
|
|
76
|
+
php,
|
|
77
|
+
options.env ? {
|
|
78
|
+
env: options.env
|
|
79
|
+
} : {}
|
|
80
|
+
),
|
|
81
|
+
options
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {string} command
|
|
87
|
+
* @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions<false> & { useXDebugContainer?: boolean, title?: string }} [options]
|
|
88
|
+
* @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
89
|
+
*/
|
|
90
|
+
const execPHPContainerCommandTask = (command, options = {}) => ({
|
|
91
|
+
title: typeof options.title === 'string' && options.title === '' ? undefined : options.title || `Running command "${command}"`,
|
|
92
|
+
task: (ctx, task) => execPHPContainerCommand(ctx, command, {
|
|
93
|
+
callback: !ctx.verbose ? undefined : (t) => {
|
|
94
|
+
task.output = t;
|
|
95
|
+
},
|
|
96
|
+
...options
|
|
97
|
+
}),
|
|
98
|
+
option: {
|
|
99
|
+
bottomBar: 10
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
runPHPContainerCommand,
|
|
105
|
+
runPHPContainerCommandTask,
|
|
106
|
+
execPHPContainerCommand,
|
|
107
|
+
execPHPContainerCommandTask
|
|
108
|
+
};
|
|
@@ -2,9 +2,10 @@ const path = require('path');
|
|
|
2
2
|
const envPhpToJson = require('../../util/env-php-json');
|
|
3
3
|
const getJsonfileData = require('../../util/get-jsonfile-data');
|
|
4
4
|
const pathExists = require('../../util/path-exists');
|
|
5
|
-
const
|
|
5
|
+
const { containerApi } = require('../docker/containers');
|
|
6
6
|
|
|
7
7
|
const composerLockPath = path.join(process.cwd(), 'composer.lock');
|
|
8
|
+
const envPhpPath = path.join(process.cwd(), 'app', 'etc', 'env.php');
|
|
8
9
|
/**
|
|
9
10
|
* @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
|
|
10
11
|
*/
|
|
@@ -12,13 +13,19 @@ const updateEnvPHP = () => ({
|
|
|
12
13
|
title: 'Updating env.php',
|
|
13
14
|
task: async (ctx, task) => {
|
|
14
15
|
// update env.php only if it's exist
|
|
15
|
-
if (!await pathExists(
|
|
16
|
+
if (!await pathExists(envPhpPath)) {
|
|
16
17
|
task.skip();
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
21
|
+
const { php } = ctx.config.docker.getContainers(ctx.ports);
|
|
22
|
+
|
|
23
|
+
const isLinux = ctx.platform === 'linux';
|
|
24
|
+
const isNativeLinux = isLinux && !ctx.isWsl;
|
|
25
|
+
const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
|
|
26
|
+
|
|
27
|
+
const useVarnish = (!ctx.debug && ctx.config.overridenConfiguration.configuration.varnish.enabled) ? '1' : '';
|
|
28
|
+
const varnishHost = hostMachine;
|
|
22
29
|
const varnishPort = ctx.ports.varnish;
|
|
23
30
|
const previousVarnishPort = ctx.cachedPorts
|
|
24
31
|
? ctx.cachedPorts.varnish
|
|
@@ -34,7 +41,7 @@ const updateEnvPHP = () => ({
|
|
|
34
41
|
ctx.CSAThemeInstalled = true;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
const envPhp = await envPhpToJson(
|
|
44
|
+
const envPhp = await envPhpToJson(ctx);
|
|
38
45
|
|
|
39
46
|
const persistedQueryConfig = envPhp.cache && envPhp.cache['persisted-query'];
|
|
40
47
|
|
|
@@ -50,20 +57,29 @@ const updateEnvPHP = () => ({
|
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
const result = await containerApi.run({
|
|
61
|
+
env: {
|
|
62
|
+
USE_VARNISH: useVarnish,
|
|
63
|
+
VARNISH_PORT: `${ varnishPort }`,
|
|
64
|
+
VARNISH_HOST: varnishHost,
|
|
65
|
+
PREVIOUS_VARNISH_PORT: `${ previousVarnishPort }`,
|
|
66
|
+
SETUP_PQ,
|
|
67
|
+
REDIS_PORT: ctx.ports.redis,
|
|
68
|
+
ADMIN_URI: ctx.config.overridenConfiguration.magento.adminuri,
|
|
69
|
+
HOST_MACHINE: hostMachine,
|
|
70
|
+
PORTS: JSON.stringify(ctx.ports)
|
|
71
|
+
},
|
|
72
|
+
command: 'php ./update-env-php.php',
|
|
73
|
+
mountVolumes: [
|
|
74
|
+
`${path.join(__dirname, 'update-env.php')}:${ctx.config.baseConfig.containerMagentoDir}/update-env-php.php`,
|
|
75
|
+
`${envPhpPath}:/${ctx.config.baseConfig.containerMagentoDir}/env.php`
|
|
76
|
+
],
|
|
77
|
+
image: php.image,
|
|
78
|
+
detach: false,
|
|
79
|
+
rm: true
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
task.output = result;
|
|
67
83
|
}
|
|
68
84
|
});
|
|
69
85
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
function varexport($expression, $return=false): string
|
|
4
4
|
{
|
|
5
5
|
$export = var_export($expression, true);
|
|
6
|
-
$export = preg_replace("/^([ ]*)(.*)/m",
|
|
6
|
+
$export = preg_replace("/^([ ]*)(.*)/m", "$1$1$2", $export);
|
|
7
7
|
$array = preg_split("/\r\n|\n|\r/", $export);
|
|
8
|
-
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [null,
|
|
8
|
+
$array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [null, "]$1", " => ["], $array);
|
|
9
9
|
$export = join(PHP_EOL, array_filter(["["] + $array));
|
|
10
10
|
if ((bool)$return) {
|
|
11
11
|
return $export;
|
|
@@ -19,12 +19,12 @@ function joinpaths(): string
|
|
|
19
19
|
$paths = array();
|
|
20
20
|
|
|
21
21
|
foreach (func_get_args() as $arg) {
|
|
22
|
-
if ($arg !==
|
|
22
|
+
if ($arg !== "") {
|
|
23
23
|
$paths[] = $arg;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
return preg_replace(
|
|
27
|
+
return preg_replace("#/+#", "/", join("/", $paths));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
class EnvUpdater
|
|
@@ -42,7 +42,7 @@ class EnvUpdater
|
|
|
42
42
|
|
|
43
43
|
public function loadConfig()
|
|
44
44
|
{
|
|
45
|
-
$this->config = require
|
|
45
|
+
$this->config = require "./env.php";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -63,14 +63,14 @@ class EnvUpdater
|
|
|
63
63
|
|
|
64
64
|
public function loadPortConfig()
|
|
65
65
|
{
|
|
66
|
-
$portConfigContent =
|
|
66
|
+
$portConfigContent = getenv("PORTS");
|
|
67
67
|
if ($portConfigContent === false) {
|
|
68
|
-
throw new Error(
|
|
68
|
+
throw new Error("Ports env does not exists");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
$portConfigJsonData = json_decode($portConfigContent, true);
|
|
72
72
|
if ($portConfigJsonData === null) {
|
|
73
|
-
throw new Error(
|
|
73
|
+
throw new Error("Ports env is not parseable");
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
$this->portConfig = $portConfigJsonData;
|
|
@@ -79,91 +79,96 @@ class EnvUpdater
|
|
|
79
79
|
public function modifyConfig()
|
|
80
80
|
{
|
|
81
81
|
// set admin uri
|
|
82
|
-
$this->config[
|
|
82
|
+
$this->config["backend"]["frontName"] = getenv("ADMIN_URI");
|
|
83
|
+
$hostMachine = getenv("HOST_MACHINE");
|
|
84
|
+
if ($hostMachine === false) {
|
|
85
|
+
$hostMachine = '127.0.0.1';
|
|
86
|
+
}
|
|
83
87
|
|
|
84
88
|
// update mysql config
|
|
85
|
-
if (isset($this->config[
|
|
86
|
-
$conn = &$this->config[
|
|
89
|
+
if (isset($this->config["db"]["connection"]["default"])) {
|
|
90
|
+
$conn = &$this->config["db"]["connection"]["default"];
|
|
91
|
+
$mysqlHost = $hostMachine . ":" . $this->portConfig["mysql"];
|
|
87
92
|
if (
|
|
88
|
-
isset($conn[
|
|
89
|
-
isset($conn[
|
|
90
|
-
$conn[
|
|
91
|
-
$conn[
|
|
93
|
+
isset($conn["engine"]) &&
|
|
94
|
+
isset($conn["host"]) &&
|
|
95
|
+
$conn["engine"] === "innodb" &&
|
|
96
|
+
$conn["host"] !== $mysqlHost
|
|
92
97
|
) {
|
|
93
|
-
$conn[
|
|
98
|
+
$conn["host"] = $mysqlHost;
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
// update redis session config
|
|
98
103
|
if (
|
|
99
|
-
isset($this->config[
|
|
100
|
-
$this->config[
|
|
101
|
-
$this->config[
|
|
104
|
+
isset($this->config["session"]) &&
|
|
105
|
+
$this->config["session"]["save"] === "redis" &&
|
|
106
|
+
$this->config["session"]["redis"]["port"] !== strval($this->portConfig["redis"])
|
|
102
107
|
) {
|
|
103
|
-
$this->config[
|
|
108
|
+
$this->config["session"]["redis"]["port"] = strval($this->portConfig["redis"]);
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
if (
|
|
107
|
-
isset($this->config[
|
|
108
|
-
$this->config[
|
|
109
|
-
$this->config[
|
|
112
|
+
isset($this->config["session"]) &&
|
|
113
|
+
$this->config["session"]["save"] === "redis" &&
|
|
114
|
+
$this->config["session"]["redis"]["host"] !== $hostMachine
|
|
110
115
|
) {
|
|
111
|
-
$this->config[
|
|
116
|
+
$this->config["session"]["redis"]["host"] = $hostMachine;
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
// update redis frontend config
|
|
115
|
-
if (isset($this->config[
|
|
116
|
-
$frontendCache = &$this->config[
|
|
117
|
-
if ($frontendCache[
|
|
118
|
-
$frontendCache[
|
|
120
|
+
if (isset($this->config["cache"]["frontend"]["default"])) {
|
|
121
|
+
$frontendCache = &$this->config["cache"]["frontend"]["default"];
|
|
122
|
+
if ($frontendCache["backend_options"]["port"] !== strval($this->portConfig["redis"])) {
|
|
123
|
+
$frontendCache["backend_options"]["port"] = strval($this->portConfig["redis"]);
|
|
119
124
|
}
|
|
120
|
-
if ($frontendCache[
|
|
121
|
-
$frontendCache[
|
|
125
|
+
if ($frontendCache["backend_options"]["server"] !== $hostMachine) {
|
|
126
|
+
$frontendCache["backend_options"]["server"] = $hostMachine;
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
// update persisted query redis config
|
|
126
|
-
if (getenv(
|
|
127
|
-
$cacheConfig = &$this->config[
|
|
128
|
-
$redisPort = getenv(
|
|
131
|
+
if (getenv("SETUP_PQ") == "1") {
|
|
132
|
+
$cacheConfig = &$this->config["cache"];
|
|
133
|
+
$redisPort = getenv("REDIS_PORT");
|
|
129
134
|
|
|
130
|
-
if (isset($cacheConfig) && isset($cacheConfig[
|
|
131
|
-
$cacheConfig[
|
|
135
|
+
if (isset($cacheConfig) && isset($cacheConfig["persisted-query"]) && isset($cacheConfig["persisted-query"]["redis"]) && $cacheConfig["persisted-query"]["redis"]["port"] != $redisPort) {
|
|
136
|
+
$cacheConfig["persisted-query"]["redis"]["port"] = $redisPort;
|
|
132
137
|
} else {
|
|
133
138
|
if (!isset($cacheConfig)) {
|
|
134
|
-
$this->config[
|
|
139
|
+
$this->config["cache"] = [];
|
|
135
140
|
}
|
|
136
|
-
$this->config[
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
$this->config["cache"]["persisted-query"] = [
|
|
142
|
+
"redis" => [
|
|
143
|
+
"host" => $hostMachine,
|
|
144
|
+
"port" => $redisPort,
|
|
145
|
+
"database" => "5",
|
|
146
|
+
"scheme" => "tcp"
|
|
142
147
|
]
|
|
143
148
|
];
|
|
144
149
|
}
|
|
145
150
|
} else {
|
|
146
|
-
unset($this->config[
|
|
151
|
+
unset($this->config["cache"]["persisted-query"]);
|
|
147
152
|
}
|
|
148
153
|
|
|
149
154
|
// set varnish config
|
|
150
|
-
$httpCacheHosts = &$this->config[
|
|
155
|
+
$httpCacheHosts = &$this->config["http_cache_hosts"];
|
|
151
156
|
$httpCacheHosts = [];
|
|
152
157
|
|
|
153
|
-
if (getenv(
|
|
154
|
-
$varnishHost = getenv(
|
|
155
|
-
$varnishPort = getenv(
|
|
156
|
-
$previousVarnishPort = getenv(
|
|
158
|
+
if (getenv("USE_VARNISH") == "1") {
|
|
159
|
+
$varnishHost = getenv("VARNISH_HOST");
|
|
160
|
+
$varnishPort = getenv("VARNISH_PORT");
|
|
161
|
+
$previousVarnishPort = getenv("PREVIOUS_VARNISH_PORT");
|
|
157
162
|
$varnishConfig = [
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
"host" => $varnishHost,
|
|
164
|
+
"port" => $varnishPort
|
|
160
165
|
];
|
|
161
166
|
|
|
162
167
|
if (isset($httpCacheHosts)) {
|
|
163
168
|
$varnishHostExists = false;
|
|
164
169
|
foreach ($httpCacheHosts as $host) {
|
|
165
|
-
if ($host[
|
|
166
|
-
$host[
|
|
170
|
+
if ($host["host"] == $varnishHost && $host["port"] == $previousVarnishPort) {
|
|
171
|
+
$host["port"] = $varnishPort;
|
|
167
172
|
$varnishHostExists = true;
|
|
168
173
|
break;
|
|
169
174
|
}
|
|
@@ -173,10 +178,10 @@ class EnvUpdater
|
|
|
173
178
|
$httpCacheHosts = [$varnishConfig];
|
|
174
179
|
}
|
|
175
180
|
} else {
|
|
176
|
-
$this->config[
|
|
181
|
+
$this->config["http_cache_hosts"] = [$varnishConfig];
|
|
177
182
|
}
|
|
178
183
|
} else {
|
|
179
|
-
unset($this->config[
|
|
184
|
+
unset($this->config["http_cache_hosts"]);
|
|
180
185
|
}
|
|
181
186
|
}
|
|
182
187
|
|
|
@@ -184,7 +189,7 @@ class EnvUpdater
|
|
|
184
189
|
{
|
|
185
190
|
file_put_contents(
|
|
186
191
|
$filePath,
|
|
187
|
-
|
|
192
|
+
"<?php".PHP_EOL."return ".varexport($this->config, true).";" . PHP_EOL
|
|
188
193
|
);
|
|
189
194
|
}
|
|
190
195
|
|
|
@@ -193,7 +198,7 @@ class EnvUpdater
|
|
|
193
198
|
$this->loadConfig();
|
|
194
199
|
$this->loadPortConfig();
|
|
195
200
|
$this->modifyConfig();
|
|
196
|
-
$this->saveConfig(
|
|
201
|
+
$this->saveConfig("./env.php");
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
|