@scandipwa/magento-scripts 2.0.0-alpha.1 → 2.0.0-alpha.12

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.
Files changed (128) hide show
  1. package/exec.js +71 -0
  2. package/index.js +1 -1
  3. package/lib/commands/cli.js +5 -0
  4. package/lib/commands/execute.js +2 -57
  5. package/lib/commands/start.js +17 -3
  6. package/lib/commands/status.js +9 -1
  7. package/lib/config/config.js +20 -2
  8. package/lib/config/docker.js +51 -49
  9. package/lib/config/index.js +1 -1
  10. package/lib/config/php/versions/php-7.2.js +1 -0
  11. package/lib/config/php/versions/php-7.3.js +1 -0
  12. package/lib/config/php/versions/php-7.4.js +1 -0
  13. package/lib/config/php/versions/php-8.1.js +1 -0
  14. package/lib/config/php-config.js +4 -3
  15. package/lib/config/services/composer/versions/composer-1.js +8 -0
  16. package/lib/config/services/composer/versions/composer-2.js +8 -0
  17. package/lib/config/services/composer/versions/index.js +4 -0
  18. package/lib/config/services/elasticsearch/default-es-env.js +6 -0
  19. package/lib/config/services/elasticsearch/versions/elasticsearch-6.8.js +2 -6
  20. package/lib/config/services/nginx/versions/index.js +3 -0
  21. package/lib/config/services/nginx/versions/nginx-1.18.js +11 -0
  22. package/lib/config/{ssl-terminator → services/ssl-terminator}/index.js +3 -0
  23. package/lib/config/templates/magentorc.template +6 -5
  24. package/lib/config/templates/php-debug.template.ini +31 -0
  25. package/lib/config/templates/php-fpm.template.conf +1 -2
  26. package/lib/config/templates/php.template.ini +6 -202
  27. package/lib/config/templates/ssl-terminator.template.conf +10 -3
  28. package/lib/config/templates/varnish.template.vcl +20 -13
  29. package/lib/config/varnish/varnish-6-0.js +4 -0
  30. package/lib/config/varnish/varnish-6-6.js +4 -0
  31. package/lib/config/varnish/varnish-7-0.js +4 -0
  32. package/lib/config/versions/magento-2.3.0.js +5 -9
  33. package/lib/config/versions/magento-2.3.1.js +5 -9
  34. package/lib/config/versions/magento-2.3.2-p1.js +5 -9
  35. package/lib/config/versions/magento-2.3.2-p2.js +5 -9
  36. package/lib/config/versions/magento-2.3.2.js +5 -9
  37. package/lib/config/versions/magento-2.3.3-p1.js +5 -9
  38. package/lib/config/versions/magento-2.3.3.js +5 -9
  39. package/lib/config/versions/magento-2.3.4-p1.js +5 -9
  40. package/lib/config/versions/magento-2.3.4-p2.js +5 -9
  41. package/lib/config/versions/magento-2.3.4.js +5 -9
  42. package/lib/config/versions/magento-2.3.5-p1.js +5 -9
  43. package/lib/config/versions/magento-2.3.5-p2.js +5 -9
  44. package/lib/config/versions/magento-2.3.5.js +5 -9
  45. package/lib/config/versions/magento-2.3.6-p1.js +5 -9
  46. package/lib/config/versions/magento-2.3.6.js +5 -9
  47. package/lib/config/versions/magento-2.3.7-p1.js +5 -9
  48. package/lib/config/versions/magento-2.3.7-p2.js +5 -9
  49. package/lib/config/versions/magento-2.3.7-p3.js +5 -9
  50. package/lib/config/versions/magento-2.3.7-p4.js +40 -0
  51. package/lib/config/versions/magento-2.3.7.js +5 -9
  52. package/lib/config/versions/magento-2.4.0-p1.js +5 -9
  53. package/lib/config/versions/magento-2.4.0.js +5 -9
  54. package/lib/config/versions/magento-2.4.1-p1.js +5 -9
  55. package/lib/config/versions/magento-2.4.1.js +5 -9
  56. package/lib/config/versions/magento-2.4.2-p1.js +5 -9
  57. package/lib/config/versions/magento-2.4.2-p2.js +5 -9
  58. package/lib/config/versions/magento-2.4.2.js +5 -9
  59. package/lib/config/versions/magento-2.4.3-p1.js +5 -9
  60. package/lib/config/versions/magento-2.4.3-p2.js +5 -9
  61. package/lib/config/versions/magento-2.4.3-p3.js +42 -0
  62. package/lib/config/versions/magento-2.4.3.js +5 -9
  63. package/lib/config/versions/magento-2.4.4-p1.js +42 -0
  64. package/lib/config/versions/magento-2.4.4.js +5 -9
  65. package/lib/config/versions/magento-2.4.5.js +42 -0
  66. package/lib/tasks/composer/local-auth-json.js +1 -1
  67. package/lib/tasks/database/connect-to-database.js +6 -3
  68. package/lib/tasks/database/create-magento-database.js +5 -2
  69. package/lib/tasks/database/create-magento-user.js +50 -0
  70. package/lib/tasks/database/default-magento-database.js +3 -0
  71. package/lib/tasks/database/default-magento-user.js +7 -0
  72. package/lib/tasks/database/import-dump-to-database.js +3 -2
  73. package/lib/tasks/docker/api.d.ts +25 -1
  74. package/lib/tasks/docker/api.js +31 -1
  75. package/lib/tasks/docker/containers/container-api.d.ts +18 -0
  76. package/lib/tasks/docker/containers/container-api.js +76 -17
  77. package/lib/tasks/docker/containers/tasks.js +32 -1
  78. package/lib/tasks/docker/index.js +6 -1
  79. package/lib/tasks/docker/project-image-builder.js +6 -8
  80. package/lib/tasks/docker/volume/index.js +2 -1
  81. package/lib/tasks/docker/volume/tasks.js +54 -9
  82. package/lib/tasks/docker/volume/volume-api.d.ts +10 -0
  83. package/lib/tasks/docker/volume/volume-api.js +25 -1
  84. package/lib/tasks/execute.js +100 -0
  85. package/lib/tasks/file-system/create-nginx-config.js +3 -5
  86. package/lib/tasks/file-system/create-php-config.js +2 -23
  87. package/lib/tasks/file-system/create-php-debug-config.js +45 -0
  88. package/lib/tasks/file-system/create-php-fpm-config.js +2 -4
  89. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +1 -1
  90. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -7
  91. package/lib/tasks/file-system/create-varnish-config.js +4 -7
  92. package/lib/tasks/file-system/index.js +2 -0
  93. package/lib/tasks/magento/enable-magento-composer-plugins.js +85 -30
  94. package/lib/tasks/magento/install-magento-project.js +3 -2
  95. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +2 -4
  96. package/lib/tasks/magento/setup-magento/flush-redis-config.js +3 -6
  97. package/lib/tasks/magento/setup-magento/install-magento.js +8 -10
  98. package/lib/tasks/magento/setup-magento/set-base-url.js +1 -1
  99. package/lib/tasks/magento/setup-magento/varnish-config.js +4 -9
  100. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +17 -16
  101. package/lib/tasks/php/php-container.js +7 -3
  102. package/lib/tasks/php/update-env-php.js +3 -4
  103. package/lib/tasks/requirements/composer-credentials.js +7 -3
  104. package/lib/tasks/requirements/docker/context.js +88 -0
  105. package/lib/tasks/requirements/docker/index.js +110 -19
  106. package/lib/tasks/requirements/docker/install.js +21 -7
  107. package/lib/tasks/requirements/docker/permissions.js +2 -11
  108. package/lib/tasks/requirements/docker/running-status.js +94 -24
  109. package/lib/tasks/requirements/docker/version.js +1 -0
  110. package/lib/tasks/requirements/index.js +0 -2
  111. package/lib/tasks/requirements/php-version.js +4 -2
  112. package/lib/tasks/start.js +28 -7
  113. package/lib/tasks/status/index.js +13 -11
  114. package/lib/tasks/stop.js +2 -0
  115. package/lib/util/config-file-validator.js +2 -0
  116. package/lib/util/execute-in-container.js +63 -0
  117. package/lib/util/systemctl.js +62 -13
  118. package/package.json +4 -3
  119. package/typings/context.d.ts +7 -0
  120. package/typings/index.d.ts +38 -1
  121. package/lib/tasks/execute/index.js +0 -26
  122. package/lib/tasks/requirements/dependency/arch.js +0 -50
  123. package/lib/tasks/requirements/dependency/centos.js +0 -36
  124. package/lib/tasks/requirements/dependency/fedora.js +0 -36
  125. package/lib/tasks/requirements/dependency/index.js +0 -33
  126. package/lib/tasks/requirements/dependency/mac.js +0 -124
  127. package/lib/tasks/requirements/dependency/ubuntu.js +0 -83
  128. package/yarn-error.log +0 -9660
@@ -31,7 +31,7 @@ const setupPHPWorkspaceProjectConfiguration = async (workspaceConfigs, ctx) => {
31
31
  hasChanges = true;
32
32
  workspaceConfigs.push({
33
33
  [nameKey]: PHP_WORKSPACE_PROJECT_CONFIGURATION_COMPONENT_NAME,
34
- [currentInterpreterImage]: currentInterpreterImage,
34
+ [interpreterNameKey]: currentInterpreterImage,
35
35
  include_path: []
36
36
  });
37
37
  }
@@ -1,4 +1,3 @@
1
- const os = require('os');
2
1
  const path = require('path');
3
2
  const fs = require('fs');
4
3
  const setConfigFile = require('../../util/set-config');
@@ -19,8 +18,8 @@ const createSSLTerminatorConfig = () => ({
19
18
  overridenConfiguration,
20
19
  baseConfig
21
20
  },
22
- isWsl,
23
- debug
21
+ debug,
22
+ isDockerDesktop
24
23
  } = ctx;
25
24
 
26
25
  const {
@@ -65,10 +64,8 @@ const createSSLTerminatorConfig = () => ({
65
64
  }
66
65
 
67
66
  const networkToBindTo = isIpAddress(host) ? host : '127.0.0.1';
68
- const isLinux = os.platform() === 'linux';
69
- const isNativeLinux = isLinux && !isWsl;
70
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
71
- const hostPort = isNativeLinux ? ports.sslTerminator : 80;
67
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
68
+ const hostPort = !isDockerDesktop ? ports.sslTerminator : 80;
72
69
 
73
70
  try {
74
71
  await setConfigFile({
@@ -17,8 +17,7 @@ const createVarnishConfig = () => ({
17
17
  cacheDir
18
18
  }
19
19
  },
20
- isWsl,
21
- platform
20
+ isDockerDesktop
22
21
  } = ctx;
23
22
 
24
23
  const {
@@ -27,9 +26,6 @@ const createVarnishConfig = () => ({
27
26
  }
28
27
  } = overridenConfiguration;
29
28
 
30
- const isLinux = platform === 'linux';
31
- const isNativeLinux = isLinux && !isWsl;
32
-
33
29
  try {
34
30
  await setConfigFile({
35
31
  configPathname: path.join(
@@ -40,8 +36,9 @@ const createVarnishConfig = () => ({
40
36
  template: varnish.configTemplate,
41
37
  overwrite: true,
42
38
  templateArgs: {
43
- hostMachine: isNativeLinux ? '127.0.0.1' : 'host.docker.internal',
44
- nginxPort: ports.app
39
+ hostMachine: !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal',
40
+ nginxPort: ports.app,
41
+ healthCheck: varnish.healthCheck
45
42
  }
46
43
  });
47
44
  } catch (e) {
@@ -1,6 +1,7 @@
1
1
  const createMariaDBConfig = require('./create-mariadb-config');
2
2
  const createNginxConfig = require('./create-nginx-config');
3
3
  const createPhpConfig = require('./create-php-config');
4
+ const createPhpDebugConfig = require('./create-php-debug-config');
4
5
  const createPhpFpmConfig = require('./create-php-fpm-config');
5
6
  const createPhpStormConfig = require('./create-phpstorm-config');
6
7
  const createSSLTerminatorConfig = require('./create-ssl-terminator-config');
@@ -17,6 +18,7 @@ const prepareFileSystem = () => ({
17
18
  createNginxConfig(),
18
19
  createPhpFpmConfig(),
19
20
  createPhpConfig(),
21
+ createPhpDebugConfig(),
20
22
  createPhpStormConfig(),
21
23
  createVSCodeConfig(),
22
24
  createVarnishConfig(),
@@ -4,7 +4,6 @@ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
4
  const semver = require('semver');
5
5
  const pathExists = require('../../util/path-exists');
6
6
  const getJsonfileData = require('../../util/get-jsonfile-data');
7
- const KnownError = require('../../errors/known-error');
8
7
 
9
8
  const vendorPath = path.join(process.cwd(), 'vendor');
10
9
  const composerJsonPath = path.join(process.cwd(), 'composer.json');
@@ -86,29 +85,80 @@ const enableMagentoComposerPlugins = () => ({
86
85
  } = composerJsonData;
87
86
  const allowPluginsKeys = Object.keys(allowPlugins);
88
87
 
88
+ const missingPluginsFromAllowPlugins = composerPlugins.filter((plugin) => {
89
+ const [pluginVendor, pluginName] = plugin.split('/');
90
+ return !allowPluginsKeys.some((allowedPlugin) => {
91
+ const [allowedPluginVendor, allowedPluginName] = allowedPlugin.split('/');
92
+ if (allowedPluginVendor === pluginVendor) {
93
+ if (allowedPluginName === '*') {
94
+ return true;
95
+ }
96
+
97
+ return allowedPluginName === pluginName;
98
+ }
99
+
100
+ return false;
101
+ });
102
+ });
103
+
89
104
  if (
90
105
  allowPluginsKeys.length === 0
91
- || composerPlugins.some((p) => !allowPluginsKeys.includes(p))
106
+ || missingPluginsFromAllowPlugins.length > 0
92
107
  ) {
93
- const missingPlugins = composerPlugins.filter((p) => !allowPluginsKeys.includes(p));
108
+ const missingVendors = missingPluginsFromAllowPlugins.reduce((acc, val) => {
109
+ const [pluginVendor] = val.split('/');
110
+
111
+ if (acc.length === 0) {
112
+ return [pluginVendor];
113
+ }
114
+
115
+ if (!acc.includes(pluginVendor)) {
116
+ return [...acc, pluginVendor];
117
+ }
118
+
119
+ return acc;
120
+ }, []);
121
+
122
+ const pluginOptions = [
123
+ {
124
+ name: 'all-individual',
125
+ message: 'Enable all individually'
126
+ },
127
+ {
128
+ name: 'manual',
129
+ message: 'Configure manually'
130
+ },
131
+ {
132
+ name: 'skip',
133
+ message: 'Skip this step'
134
+ }
135
+ ];
136
+
137
+ if (missingVendors.length === 1) {
138
+ pluginOptions.unshift({
139
+ name: 'all',
140
+ message: `Enable all (${logger.style.code(`"${missingVendors[0]}/*"`)})`
141
+ });
142
+ }
143
+
94
144
  const answerForEnablingPlugins = await task.prompt({
95
145
  type: 'Select',
96
146
  message: `Composer 2.2 requires manually allowing composer-plugins to run.
97
147
  Magento requires the following plugins to correctly operate:
98
148
 
99
- ${missingPlugins.map((p) => logger.style.code(p)).join('\n')}
149
+ ${missingPluginsFromAllowPlugins.map((p) => logger.style.code(p)).join('\n')}
100
150
 
101
151
  Do you want to enable them all or disable some of them?`,
102
- choices: ['Enable all', 'Configure manually', 'Skip this step']
152
+ choices: pluginOptions
103
153
  });
104
154
 
105
155
  switch (answerForEnablingPlugins.toLowerCase()) {
106
- case 'enable all': {
156
+ case 'all': {
107
157
  composerJsonData.config = {
108
158
  ...(composerJsonData.config || {}),
109
159
  'allow-plugins': {
110
160
  ...allowPlugins,
111
- ...missingPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
161
+ [`${missingVendors[0]}/*`]: true
112
162
  }
113
163
  };
114
164
 
@@ -117,36 +167,41 @@ Do you want to enable them all or disable some of them?`,
117
167
  });
118
168
  break;
119
169
  }
120
- case 'configure manually': {
170
+ case 'all-individual': {
171
+ composerJsonData.config = {
172
+ ...(composerJsonData.config || {}),
173
+ 'allow-plugins': {
174
+ ...allowPlugins,
175
+ ...missingPluginsFromAllowPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
176
+ }
177
+ };
178
+
179
+ await fs.promises.writeFile(composerJsonPath, JSON.stringify(composerJsonData, null, 4), {
180
+ encoding: 'utf-8'
181
+ });
182
+ break;
183
+ }
184
+ case 'manual': {
121
185
  const userEnabledPlugins = await task.prompt({
122
186
  type: 'MultiSelect',
123
187
  message: 'Please pick plugins you want to enable!',
124
- choices: missingPlugins.map((p) => ({ name: p }))
188
+ choices: missingPluginsFromAllowPlugins.map((p) => ({ name: p }))
125
189
  });
126
190
 
127
- const userConfirmation = await task.prompt({
128
- type: 'Confirm',
129
- message: `Please confirm enabling of the following plugins:\n\n${userEnabledPlugins.map((p) => logger.style.code(p)).join('\n')}\n`
130
- });
191
+ const disabledPlugins = composerPlugins.filter((p) => !userEnabledPlugins.includes(p));
131
192
 
132
- if (userConfirmation) {
133
- const disabledPlugins = composerPlugins.filter((p) => !userEnabledPlugins.includes(p));
134
-
135
- composerJsonData.config = {
136
- ...(composerJsonData.config || {}),
137
- 'allow-plugins': {
138
- ...allowPlugins,
139
- ...disabledPlugins.reduce((acc, val) => ({ ...acc, [val]: false }), {}),
140
- ...userEnabledPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
141
- }
142
- };
193
+ composerJsonData.config = {
194
+ ...(composerJsonData.config || {}),
195
+ 'allow-plugins': {
196
+ ...allowPlugins,
197
+ ...disabledPlugins.reduce((acc, val) => ({ ...acc, [val]: false }), {}),
198
+ ...userEnabledPlugins.reduce((acc, val) => ({ ...acc, [val]: true }), {})
199
+ }
200
+ };
143
201
 
144
- await fs.promises.writeFile(composerJsonPath, JSON.stringify(composerJsonData, null, 4), {
145
- encoding: 'utf-8'
146
- });
147
- } else {
148
- throw new KnownError('Please confirm your choice or choose other option.');
149
- }
202
+ await fs.promises.writeFile(composerJsonPath, JSON.stringify(composerJsonData, null, 4), {
203
+ encoding: 'utf-8'
204
+ });
150
205
 
151
206
  break;
152
207
  }
@@ -97,8 +97,9 @@ const createMagentoProject = async (ctx, task, {
97
97
  `"${tempDir}"`
98
98
  ];
99
99
 
100
- await runPHPContainerCommand(ctx, `composer ${installCommand.join(' ')} \n
101
- && mv ${tempDir}/composer.json ${ctx.config.baseConfig.containerMagentoDir}/composer.json`);
100
+ await runPHPContainerCommand(ctx, `bash -c 'mkdir ${tempDir} && \
101
+ composer ${installCommand.join(' ')} && \
102
+ mv ${tempDir}/composer.json ${ctx.config.baseConfig.containerMagentoDir}/composer.json'`);
102
103
  };
103
104
 
104
105
  /**
@@ -7,10 +7,8 @@ module.exports = () => ({
7
7
  title: 'Configuring Elasticsearch',
8
8
  skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)),
9
9
  task: async (ctx, task) => {
10
- const { ports, databaseConnection } = ctx;
11
- const isLinux = ctx.platform === 'linux';
12
- const isNativeLinux = isLinux && !ctx.isWsl;
13
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
10
+ const { ports, databaseConnection, isDockerDesktop } = ctx;
11
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
14
12
  await updateTableValues('core_config_data', [
15
13
  { path: 'catalog/search/engine', value: 'elasticsearch7' },
16
14
  { path: 'catalog/search/elasticsearch7_server_hostname', value: hostMachine },
@@ -1,18 +1,15 @@
1
1
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
2
- const os = require('os');
3
2
  const UnknownError = require('../../../errors/unknown-error');
4
3
 
5
- const isLinux = os.platform() === 'linux';
6
-
7
4
  /**
8
5
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
9
6
  */
10
7
  module.exports = () => ({
11
8
  title: 'Flushing Magento redis cache',
12
- task: async ({ ports, config: { docker } }) => {
9
+ task: async ({ ports, config: { docker }, isDockerDesktop }) => {
13
10
  const { redis: { name } } = docker.getContainers(ports);
14
- const host = isLinux ? 'localhost' : 'host.docker.internal';
15
- const port = isLinux ? '6379' : ports.redis;
11
+ const host = !isDockerDesktop ? 'localhost' : 'host.docker.internal';
12
+ const port = !isDockerDesktop ? '6379' : ports.redis;
16
13
  const result = await execAsyncSpawn(`docker exec ${ name } redis-cli -h ${ host } -p ${ port } -n 0 flushdb`);
17
14
 
18
15
  if (!result.trim().includes('OK')) {
@@ -5,6 +5,8 @@ const UnknownError = require('../../../errors/unknown-error');
5
5
  const runMagentoCommand = require('../../../util/run-magento');
6
6
  const envPhpToJson = require('../../../util/env-php-json');
7
7
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
8
+ const { defaultMagentoDatabase } = require('../../database/default-magento-database');
9
+ const defaultMagentoUser = require('../../database/default-magento-user');
8
10
 
9
11
  /**
10
12
  * @param {Object} [param0]
@@ -20,16 +22,14 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
20
22
  const {
21
23
  magentoVersion,
22
24
  config: {
23
- docker,
24
25
  magentoConfiguration
25
26
  },
26
27
  ports,
27
- databaseConnection
28
+ databaseConnection,
29
+ isDockerDesktop
28
30
  } = ctx;
29
31
 
30
- const isLinux = ctx.platform === 'linux';
31
- const isNativeLinux = isLinux && !ctx.isWsl;
32
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
32
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
33
33
 
34
34
  const [tableResponse] = await databaseConnection.query(
35
35
  'SELECT * FROM information_schema.tables WHERE table_schema = \'magento\' AND table_name = \'admin_user\' LIMIT 1;'
@@ -73,8 +73,6 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
73
73
  await databaseConnection.query('SET FOREIGN_KEY_CHECKS = 1;');
74
74
  }
75
75
  }
76
-
77
- const { mariadb: { env } } = docker.getContainers(ports);
78
76
  const envPhpData = await envPhpToJson(ctx);
79
77
 
80
78
  const envPhpHaveEncryptionKey = envPhpData && envPhpData.crypt && envPhpData.crypt.key && envPhpData.crypt.key;
@@ -127,9 +125,9 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
127
125
  --cache-backend-redis-port='${ ports.redis }' \
128
126
  --cache-backend-redis-db='0't \
129
127
  --db-host='${ hostMachine }:${ ports.mariadb }' \
130
- --db-name='${ env.MARIADB_DATABASE }' \
131
- --db-user='${ env.MARIADB_USER }' \
132
- --db-password='${ env.MARIADB_PASSWORD }' \
128
+ --db-name='${ defaultMagentoDatabase }' \
129
+ --db-user='${ defaultMagentoUser.user }' \
130
+ --db-password='${ defaultMagentoUser.password }' \
133
131
  --backend-frontname='${ magentoConfiguration.adminuri }' \
134
132
  --no-interaction`;
135
133
 
@@ -17,7 +17,7 @@ module.exports = () => ({
17
17
  databaseConnection
18
18
  } = ctx;
19
19
  const isNgrok = host.endsWith('ngrok.io');
20
- const enableSecureFrontend = ssl.enabled ? '1' : '0';
20
+ const enableSecureFrontend = (ctx.config.overridenConfiguration.configuration.varnish.enabled && ssl.enabled) ? '1' : '0';
21
21
  const location = `${host}${ !isNgrok && ports.sslTerminator !== 80 ? `:${ports.sslTerminator }` : '' }/`;
22
22
  const secureLocation = `${host}/`; // SSL will work only on port 443, so you cannot run multiple projects with SSL at the same time.
23
23
  const httpUrl = `http://${location}`;
@@ -1,6 +1,4 @@
1
- const os = require('os');
2
1
  const { updateTableValues } = require('../../../util/database');
3
- const getIsWsl = require('../../../util/is-wsl');
4
2
 
5
3
  /**
6
4
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -20,18 +18,15 @@ const varnishConfigSetup = () => ({
20
18
  },
21
19
  databaseConnection,
22
20
  ports,
23
- debug
21
+ debug,
22
+ isDockerDesktop
24
23
  } = ctx;
25
24
 
26
- const isLinux = os.platform() === 'linux';
27
- const isWsl = await getIsWsl();
28
- const isNativeLinux = isLinux && !isWsl;
29
-
30
25
  if (!debug && varnishEnabled) {
31
26
  await updateTableValues('core_config_data', [
32
27
  {
33
28
  path: 'system/full_page_cache/varnish/backend_host',
34
- value: !isNativeLinux ? 'host.docker.internal' : 'localhost'
29
+ value: isDockerDesktop ? 'host.docker.internal' : 'localhost'
35
30
  },
36
31
  {
37
32
  path: 'system/full_page_cache/varnish/backend_port',
@@ -39,7 +34,7 @@ const varnishConfigSetup = () => ({
39
34
  },
40
35
  {
41
36
  path: 'system/full_page_cache/varnish/access_list',
42
- value: !isNativeLinux ? 'host.docker.internal,localhost' : 'localhost'
37
+ value: isDockerDesktop ? 'host.docker.internal,localhost' : 'localhost'
43
38
  },
44
39
  {
45
40
  path: 'system/full_page_cache/caching_application',
@@ -4,9 +4,9 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const { request } = require('smol-request');
6
6
  const KnownError = require('../../../errors/known-error');
7
- const { execAsyncSpawn } = require('../../../util/exec-async-command');
8
7
  const { NginxParser } = require('../../../util/nginx-logs-parser');
9
8
  const sleep = require('../../../util/sleep');
9
+ const { containerApi } = require('../../docker/containers');
10
10
 
11
11
  const pathToWorkingHealthCheckPhp = path.join(__dirname, '..', '..', 'php', 'working_health_check.php');
12
12
  const pathToProjectsHealthCheckPhp = path.join(process.cwd(), 'pub', 'health_check.php');
@@ -17,19 +17,18 @@ const pathToHealthCheckBackupPhp = path.join(process.cwd(), 'pub', 'health_check
17
17
  */
18
18
  const getIsHealthCheckRequestBroken = async (ctx) => {
19
19
  const { nginx } = ctx.config.docker.getContainers(ctx.ports);
20
-
21
- const nginxLogs = await execAsyncSpawn(`docker logs ${nginx.name}`);
22
-
23
- const healthCheckRequests = nginxLogs
24
- .split('\n')
25
- .filter((line) => line.includes('"GET /health_check.php HTTP/1.1"'));
26
-
27
- // eslint-disable-next-line max-len
28
- const parser = new NginxParser('$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"');
29
-
30
- const parsedRequests = healthCheckRequests.map((line) => parser.parseLine(line));
31
-
32
- return parsedRequests.every((parsedRequest) => parsedRequest.status !== '200');
20
+ const parser = new NginxParser(
21
+ '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'
22
+ );
23
+ const parsedLogs = await containerApi.logs({
24
+ name: nginx.name,
25
+ parser: (line) => parser.parseLine(line)
26
+ });
27
+
28
+ const healthCheckRequests = parsedLogs
29
+ .filter((line) => line.request.includes('/health_check.php'));
30
+
31
+ return healthCheckRequests.every((parsedRequest) => parsedRequest.status !== '200');
33
32
  };
34
33
 
35
34
  /**
@@ -37,12 +36,14 @@ const getIsHealthCheckRequestBroken = async (ctx) => {
37
36
  */
38
37
  const waitingForVarnish = () => ({
39
38
  title: 'Waiting for Varnish to return code 200',
40
- skip: (ctx) => ctx.debug || !ctx.config.overridenConfiguration.configuration.varnish.enabled,
39
+ skip: (ctx) => ctx.debug
40
+ || !ctx.config.overridenConfiguration.configuration.varnish.enabled
41
+ || ctx.config.overridenConfiguration.ssl.enabled
42
+ || !ctx.config.overridenConfiguration.configuration.varnish.healthCheck,
41
43
  task: async (ctx, task) => {
42
44
  const pureMagentoVersion = ctx.magentoVersion.match(/^([0-9]+\.[0-9]+\.[0-9]+)/)[1];
43
45
 
44
46
  const isMagento23 = semver.satisfies(pureMagentoVersion, '<2.4');
45
-
46
47
  let tries = 0;
47
48
  while (tries < 10) {
48
49
  try {
@@ -10,9 +10,13 @@ const { containerApi } = require('../docker/containers');
10
10
  const runPHPContainerCommand = async (ctx, command, options = {}) => {
11
11
  const { php } = ctx.config.docker.getContainers(ctx.ports);
12
12
 
13
- const containers = await containerApi.ls({ formatToJSON: true, all: true });
13
+ const containers = await containerApi.ls({
14
+ formatToJSON: true,
15
+ all: true,
16
+ filter: `name=${php.name}`
17
+ });
14
18
 
15
- if (containers.some((c) => c.Names === php.name)) {
19
+ if (containers.length > 0) {
16
20
  return execPHPContainerCommand(ctx, command, options);
17
21
  }
18
22
 
@@ -25,7 +29,7 @@ const runPHPContainerCommand = async (ctx, command, options = {}) => {
25
29
  },
26
30
  options.useXDebugContainer
27
31
  ? {
28
- image: `${ php.image }.xdebug`
32
+ image: php.debugImage
29
33
  }
30
34
  : {},
31
35
  {
@@ -19,11 +19,10 @@ const updateEnvPHP = () => ({
19
19
  return;
20
20
  }
21
21
 
22
+ const { isDockerDesktop, platform } = ctx;
22
23
  const { php } = ctx.config.docker.getContainers(ctx.ports);
23
24
 
24
- const isLinux = ctx.platform === 'linux';
25
- const isNativeLinux = isLinux && !ctx.isWsl;
26
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
25
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
27
26
 
28
27
  const useVarnish = (!ctx.debug && ctx.config.overridenConfiguration.configuration.varnish.enabled) ? '1' : '';
29
28
  const varnishHost = hostMachine;
@@ -78,7 +77,7 @@ const updateEnvPHP = () => ({
78
77
  image: php.image,
79
78
  detach: false,
80
79
  rm: true,
81
- user: isLinux ? `${os.userInfo().uid}:${os.userInfo().gid}` : ''
80
+ user: platform === 'linux' ? `${os.userInfo().uid}:${os.userInfo().gid}` : ''
82
81
  });
83
82
 
84
83
  task.output = result;
@@ -96,9 +96,9 @@ ${ logger.style.misc('Password') } (${ logger.style.misc('Private key') }):`,
96
96
  };
97
97
 
98
98
  const authJsonContent = JSON.stringify(authContent, null, 4);
99
- const authEnvContent = `export COMPOSER_AUTH='${JSON.stringify(authContent)}'`;
99
+ const authEnvContent = `export COMPOSER_AUTH='${JSON.stringify(authContent, null, 0)}'`;
100
100
 
101
- process.env.COMPOSER_AUTH = authJsonContent;
101
+ process.env.COMPOSER_AUTH = JSON.stringify(JSON.parse(authJsonContent), null, 0);
102
102
 
103
103
  if (configureLocation === 'auth.json') {
104
104
  await fs.promises.writeFile(authJsonPath, authJsonContent, 'utf-8');
@@ -175,7 +175,11 @@ Would you like to load them now?`
175
175
 
176
176
  if (loadCredentialsFrom) {
177
177
  const credentialsLine = lines.find((line) => line.startsWith('export COMPOSER_AUTH='));
178
- process.env.COMPOSER_AUTH = credentialsLine.replace('export COMPOSER_AUTH=', '').replace(/'/ig, '').trim();
178
+ process.env.COMPOSER_AUTH = JSON.stringify(
179
+ JSON.parse(credentialsLine.replace('export COMPOSER_AUTH=', '').replace(/'/ig, '').trim()),
180
+ null,
181
+ 0
182
+ );
179
183
  problems.delete(MISSING_COMPOSER_AUTH_ENV);
180
184
  }
181
185
  }
@@ -0,0 +1,88 @@
1
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
+ const os = require('os');
3
+ const { cmaGlobalConfig } = require('../../../config/cma-config');
4
+ const { getCachedPorts } = require('../../../config/get-port-config');
5
+ const { getSystemConfigTask } = require('../../../config/system-config');
6
+ const UnknownError = require('../../../errors/unknown-error');
7
+ const { execCommandTask } = require('../../../util/exec-async-command');
8
+ const createCacheFolder = require('../../cache/create-cache-folder');
9
+ const { dockerApi } = require('../../docker');
10
+ const { stopContainers } = require('../../docker/containers');
11
+ const { getDockerEngineAndDesktopServiceStatus } = require('./running-status');
12
+ const getMagentoVersionConfig = require('../../../config/get-magento-version-config');
13
+ const checkConfigurationFile = require('../../../config/check-configuration-file');
14
+ const getProjectConfiguration = require('../../../config/get-project-configuration');
15
+ const getDockerVersion = require('./version');
16
+
17
+ const USE_DEFAULT_DOCKER_DESKTOP_CONTEXT_ANSWER = 'useDefaultDockerDesktopContext';
18
+
19
+ /**
20
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
21
+ */
22
+ const checkDockerDesktopContext = () => ({
23
+ task: async (ctx, task) => {
24
+ if (os.platform() !== 'linux' || !ctx.isDockerDesktop) {
25
+ task.skip();
26
+ return;
27
+ }
28
+
29
+ task.title = 'Checking contexts for Docker Desktop';
30
+
31
+ const contexts = await dockerApi.context({ formatToJSON: true });
32
+ const currentlyUsedContext = contexts.find((c) => c.Current);
33
+
34
+ if (!currentlyUsedContext) {
35
+ throw new UnknownError('We haven\'t found contexts in Docker...');
36
+ }
37
+
38
+ const { engine } = await getDockerEngineAndDesktopServiceStatus();
39
+
40
+ if (currentlyUsedContext.Name !== 'default' && engine.exists) {
41
+ if (cmaGlobalConfig.get(USE_DEFAULT_DOCKER_DESKTOP_CONTEXT_ANSWER) === false) {
42
+ task.skip();
43
+ return;
44
+ }
45
+
46
+ const confirmContextChange = await task.prompt({
47
+ type: 'Select',
48
+ message: `Do you want to change current Docker Desktop context (${logger.style.code(currentlyUsedContext.Name)}) to ${logger.style.code('default')}?`,
49
+ choices: [
50
+ {
51
+ name: 'yes',
52
+ message: 'Yes'
53
+ },
54
+ {
55
+ name: 'no',
56
+ message: 'No, I don\'t know what this means, but you can ask again on next start.'
57
+ },
58
+ {
59
+ name: 'skip',
60
+ // eslint-disable-next-line max-len
61
+ message: 'I do know what this means and I DON\'T want to change context for Docker. Also, save this answer to never ask again.'
62
+ }
63
+ ]
64
+ });
65
+
66
+ if (confirmContextChange === 'skip') {
67
+ cmaGlobalConfig.set(USE_DEFAULT_DOCKER_DESKTOP_CONTEXT_ANSWER, false);
68
+ task.skip();
69
+ }
70
+
71
+ if (confirmContextChange === 'yes') {
72
+ return task.newListr([
73
+ getMagentoVersionConfig(),
74
+ checkConfigurationFile(),
75
+ getProjectConfiguration(),
76
+ createCacheFolder(),
77
+ getSystemConfigTask(),
78
+ getCachedPorts(),
79
+ stopContainers(),
80
+ execCommandTask('docker context use default'),
81
+ getDockerVersion()
82
+ ]);
83
+ }
84
+ }
85
+ }
86
+ });
87
+
88
+ module.exports = checkDockerDesktopContext;