@scandipwa/magento-scripts 1.16.1 → 2.0.0-alpha.2

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 (226) hide show
  1. package/lib/commands/cli.js +4 -6
  2. package/lib/commands/execute.js +29 -4
  3. package/lib/commands/import-db.js +1 -1
  4. package/lib/commands/logs.js +1 -1
  5. package/lib/commands/start.js +38 -20
  6. package/lib/commands/status.js +2 -0
  7. package/lib/config/docker.js +102 -84
  8. package/lib/config/get-project-configuration.js +3 -1
  9. package/lib/config/index.js +10 -7
  10. package/lib/config/magento/required-php-extensions/index.js +29 -0
  11. package/lib/config/magento/required-php-extensions/magento-2.3.js +19 -0
  12. package/lib/config/magento/required-php-extensions/magento-2.4.js +29 -0
  13. package/lib/config/php/base-repo.js +3 -0
  14. package/lib/config/php/extensions/apcu.js +12 -0
  15. package/lib/config/php/extensions/bcmath.js +7 -0
  16. package/lib/config/php/extensions/curl.js +11 -0
  17. package/lib/config/php/extensions/gd.js +14 -0
  18. package/lib/config/php/extensions/index.js +18 -2
  19. package/lib/config/php/extensions/intl.js +10 -0
  20. package/lib/config/php/extensions/opcache.js +10 -0
  21. package/lib/config/php/extensions/pdo_mysql.js +7 -0
  22. package/lib/config/php/extensions/soap.js +10 -0
  23. package/lib/config/php/extensions/sodium.js +10 -0
  24. package/lib/config/php/extensions/xdebug.js +8 -5
  25. package/lib/config/php/extensions/xsl.js +10 -0
  26. package/lib/config/php/extensions/zip.js +10 -0
  27. package/lib/config/php/{releases → versions}/index.js +0 -0
  28. package/lib/config/php/versions/php-7.2.js +23 -0
  29. package/lib/config/php/versions/php-7.3.js +23 -0
  30. package/lib/config/php/versions/php-7.4.js +23 -0
  31. package/lib/config/php/versions/php-8.1.js +23 -0
  32. package/lib/config/php-config.js +8 -12
  33. package/lib/config/port-config.js +2 -6
  34. package/lib/config/services/elasticsearch/base-repo.js +3 -0
  35. package/lib/config/services/elasticsearch/default-es-env.js +6 -0
  36. package/lib/config/services/elasticsearch/versions/elasticsearch-6.8.js +19 -0
  37. package/lib/config/services/elasticsearch/versions/index.js +5 -0
  38. package/lib/config/templates/magentorc.template +5 -5
  39. package/lib/config/templates/mariadb.template.cnf +191 -0
  40. package/lib/config/templates/php-fpm.template.conf +3 -3
  41. package/lib/config/templates/php.template.ini +12 -6
  42. package/lib/config/templates/ssl-terminator.template.conf +1 -1
  43. package/lib/config/templates/vscode-launch.template.json +3 -1
  44. package/lib/config/versions/magento-2.3.0.js +10 -5
  45. package/lib/config/versions/magento-2.3.1.js +10 -5
  46. package/lib/config/versions/magento-2.3.2-p1.js +43 -0
  47. package/lib/config/versions/magento-2.3.2-p2.js +10 -5
  48. package/lib/config/versions/magento-2.3.2.js +10 -5
  49. package/lib/config/versions/magento-2.3.3-p1.js +10 -5
  50. package/lib/config/versions/magento-2.3.3.js +10 -5
  51. package/lib/config/versions/magento-2.3.4-p1.js +43 -0
  52. package/lib/config/versions/magento-2.3.4-p2.js +10 -5
  53. package/lib/config/versions/magento-2.3.4.js +10 -5
  54. package/lib/config/versions/magento-2.3.5-p1.js +8 -2
  55. package/lib/config/versions/magento-2.3.5-p2.js +8 -2
  56. package/lib/config/versions/magento-2.3.5.js +8 -2
  57. package/lib/config/versions/magento-2.3.6-p1.js +8 -2
  58. package/lib/config/versions/magento-2.3.6.js +8 -2
  59. package/lib/config/versions/magento-2.3.7-p1.js +8 -2
  60. package/lib/config/versions/magento-2.3.7-p2.js +8 -2
  61. package/lib/config/versions/magento-2.3.7-p3.js +8 -2
  62. package/lib/config/versions/magento-2.3.7.js +8 -2
  63. package/lib/config/versions/magento-2.4.0-p1.js +9 -3
  64. package/lib/config/versions/magento-2.4.0.js +9 -3
  65. package/lib/config/versions/magento-2.4.1-p1.js +6 -5
  66. package/lib/config/versions/magento-2.4.1.js +9 -2
  67. package/lib/config/versions/magento-2.4.2-p1.js +6 -5
  68. package/lib/config/versions/magento-2.4.2-p2.js +6 -6
  69. package/lib/config/versions/magento-2.4.2.js +6 -6
  70. package/lib/config/versions/magento-2.4.3-p1.js +7 -7
  71. package/lib/config/versions/magento-2.4.3-p2.js +7 -7
  72. package/lib/config/versions/magento-2.4.3.js +7 -7
  73. package/lib/config/versions/magento-2.4.4.js +9 -2
  74. package/lib/tasks/cleanup.js +3 -3
  75. package/lib/tasks/composer/index.js +14 -104
  76. package/lib/tasks/database/connect-to-database.js +117 -0
  77. package/lib/tasks/database/create-magento-database.js +18 -0
  78. package/lib/tasks/{mysql → database}/dump-theme-config.js +3 -3
  79. package/lib/tasks/{mysql → database}/fix-db.js +2 -2
  80. package/lib/tasks/{mysql/import-dump-to-mysql.js → database/import-dump-to-database.js} +65 -22
  81. package/lib/tasks/{mysql → database}/import-remote-db/index.js +0 -0
  82. package/lib/tasks/{mysql/import-remote-db/ssh/mysqldump-command.js → database/import-remote-db/ssh/database-dump-command.js} +2 -2
  83. package/lib/tasks/{mysql → database}/import-remote-db/ssh/index.js +0 -0
  84. package/lib/tasks/{mysql → database}/import-remote-db/ssh/readymage.js +4 -4
  85. package/lib/tasks/{mysql → database}/import-remote-db/ssh/regular-server.js +2 -2
  86. package/lib/tasks/{mysql → database}/index.js +2 -2
  87. package/lib/tasks/{mysql → database}/magento-tables.js +0 -0
  88. package/lib/tasks/{mysql → database}/restore-theme-config.js +4 -4
  89. package/lib/tasks/docker/api.d.ts +71 -0
  90. package/lib/tasks/docker/api.js +30 -0
  91. package/lib/tasks/docker/containers/container-api.d.ts +128 -0
  92. package/lib/tasks/docker/containers/container-api.js +153 -0
  93. package/lib/tasks/docker/containers/index.js +19 -0
  94. package/lib/tasks/docker/containers/tasks.js +215 -0
  95. package/lib/tasks/docker/convert-legacy-volumes.js +15 -10
  96. package/lib/tasks/docker/convert-mysql-to-mariadb.js +284 -0
  97. package/lib/tasks/docker/image/image-api.d.ts +34 -0
  98. package/lib/tasks/docker/image/image-api.js +49 -0
  99. package/lib/tasks/docker/image/index.js +5 -0
  100. package/lib/tasks/docker/index.js +1 -13
  101. package/lib/tasks/docker/network/index.js +7 -0
  102. package/lib/tasks/docker/network/network-api.d.ts +103 -0
  103. package/lib/tasks/docker/network/network-api.js +99 -0
  104. package/lib/tasks/docker/{network.js → network/tasks.js} +17 -10
  105. package/lib/tasks/docker/project-image-builder.js +167 -0
  106. package/lib/tasks/docker/volume/index.js +8 -0
  107. package/lib/tasks/docker/{volumes.js → volume/tasks.js} +5 -19
  108. package/lib/tasks/docker/volume/volume-api.d.ts +39 -0
  109. package/lib/tasks/docker/volume/volume-api.js +66 -0
  110. package/lib/tasks/execute/index.js +5 -2
  111. package/lib/tasks/file-system/create-mariadb-config.js +23 -0
  112. package/lib/tasks/file-system/create-nginx-config.js +2 -3
  113. package/lib/tasks/file-system/create-php-config.js +20 -5
  114. package/lib/tasks/file-system/create-php-fpm-config.js +8 -4
  115. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +41 -29
  116. package/lib/tasks/file-system/create-phpstorm-config/index.js +2 -0
  117. package/lib/tasks/file-system/create-phpstorm-config/keys.js +15 -1
  118. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +4 -1
  119. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-config.js +3 -3
  120. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-interpreters-config.js +81 -0
  121. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/index.js +42 -0
  122. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/php-docker-settings-config.js +9 -0
  123. package/lib/tasks/file-system/create-phpstorm-config/php-docker-settings-config/setup-php-docker-container-settings-config.js +66 -0
  124. package/lib/tasks/file-system/create-phpstorm-config/setup-xml-structure.js +11 -9
  125. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +2 -1
  126. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +15 -30
  127. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +24 -5
  128. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/mess-detector-project-configuration-config.js +50 -0
  129. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-code-sniffer-project-configuration-config.js +50 -0
  130. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-cs-fixer-project-configuration-config.js +50 -0
  131. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +15 -15
  132. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +29 -3
  133. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-stan-project-configuration-config.js.js +50 -0
  134. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +42 -0
  135. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/psalm-project-configuration-config.js.js +50 -0
  136. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/workspace-config.js +0 -2
  137. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -2
  138. package/lib/tasks/file-system/create-vscode-config.js +57 -42
  139. package/lib/tasks/file-system/index.js +5 -2
  140. package/lib/tasks/import-dump.js +6 -6
  141. package/lib/tasks/link.js +5 -4
  142. package/lib/tasks/magento/install-magento-project.js +31 -63
  143. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +4 -4
  144. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +7 -3
  145. package/lib/tasks/magento/setup-magento/create-admin.js +5 -6
  146. package/lib/tasks/magento/setup-magento/delete-admin-users.js +2 -2
  147. package/lib/tasks/magento/setup-magento/delete-customers.js +4 -4
  148. package/lib/tasks/magento/setup-magento/delete-orders.js +4 -4
  149. package/lib/tasks/magento/setup-magento/disable-2fa.js +3 -5
  150. package/lib/tasks/magento/setup-magento/disable-maintenance-mode.js +3 -4
  151. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +2 -2
  152. package/lib/tasks/magento/setup-magento/index.js +2 -0
  153. package/lib/tasks/magento/setup-magento/install-magento.js +21 -20
  154. package/lib/tasks/magento/setup-magento/migrate-database.js +7 -14
  155. package/lib/tasks/magento/setup-magento/set-base-url.js +2 -2
  156. package/lib/tasks/magento/setup-magento/set-deployment-mode.js +4 -4
  157. package/lib/tasks/magento/setup-magento/set-url-rewrite.js +2 -2
  158. package/lib/tasks/magento/setup-magento/varnish-config.js +10 -8
  159. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +128 -3
  160. package/lib/tasks/php/php-container.js +108 -0
  161. package/lib/tasks/php/update-env-php.js +39 -21
  162. package/lib/tasks/php/update-env.php +66 -61
  163. package/lib/tasks/php/working_health_check.php +85 -0
  164. package/lib/tasks/requirements/{composer.js → composer-credentials.js} +3 -1
  165. package/lib/tasks/requirements/docker/index.js +15 -12
  166. package/lib/tasks/requirements/docker/performance.js +54 -0
  167. package/lib/tasks/requirements/docker/version.js +8 -8
  168. package/lib/tasks/requirements/index.js +5 -8
  169. package/lib/tasks/requirements/php-version.js +8 -116
  170. package/lib/tasks/requirements/platform.js +12 -25
  171. package/lib/tasks/start.js +21 -50
  172. package/lib/tasks/status/index.js +8 -12
  173. package/lib/tasks/stop.js +0 -2
  174. package/lib/tasks/theme/install-theme.js +1 -1
  175. package/lib/tasks/theme/link-theme.js +2 -2
  176. package/lib/tasks/theme/symlink-theme.js +2 -3
  177. package/lib/util/config-file-validator.js +27 -13
  178. package/lib/util/config-php-json.js +13 -4
  179. package/lib/util/database.js +7 -7
  180. package/lib/util/dockerfile-builder/build-instructions.js +197 -0
  181. package/lib/util/dockerfile-builder/index.js +276 -0
  182. package/lib/util/dockerfile-builder/types.d.ts +123 -0
  183. package/lib/util/env-php-json.js +10 -6
  184. package/lib/util/exec-async-command.js +3 -9
  185. package/lib/util/macos-version.js +20 -0
  186. package/lib/util/magento-task.js +3 -4
  187. package/lib/util/nginx-logs-parser.js +122 -0
  188. package/lib/util/php-task.js +3 -6
  189. package/lib/util/run-composer.js +6 -14
  190. package/lib/util/run-container-image.js +17 -0
  191. package/lib/util/run-magento.js +6 -14
  192. package/lib/util/run-php.js +6 -17
  193. package/package.json +9 -9
  194. package/typings/context.d.ts +7 -13
  195. package/typings/index.d.ts +67 -85
  196. package/yarn-error.log +9660 -0
  197. package/lib/config/composer.js +0 -11
  198. package/lib/config/php/extensions/libsodium.js +0 -36
  199. package/lib/config/php/releases/php-7.2.js +0 -25
  200. package/lib/config/php/releases/php-7.3.js +0 -25
  201. package/lib/config/php/releases/php-7.4.js +0 -23
  202. package/lib/config/php/releases/php-8.1.js +0 -25
  203. package/lib/config/phpbrew.js +0 -12
  204. package/lib/tasks/composer/install-prestissimo.js +0 -103
  205. package/lib/tasks/docker/containers.js +0 -231
  206. package/lib/tasks/mysql/connect-to-mysql.js +0 -114
  207. package/lib/tasks/mysql/create-magento-database.js +0 -18
  208. package/lib/tasks/php/bundled-extensions.js +0 -27
  209. package/lib/tasks/php/compile-options.js +0 -56
  210. package/lib/tasks/php/compile.js +0 -55
  211. package/lib/tasks/php/configure.js +0 -89
  212. package/lib/tasks/php/extensions/disable.js +0 -49
  213. package/lib/tasks/php/extensions/enable.js +0 -52
  214. package/lib/tasks/php/extensions/index.js +0 -80
  215. package/lib/tasks/php/extensions/install.js +0 -54
  216. package/lib/tasks/php/index.js +0 -79
  217. package/lib/tasks/php/install-sodium.js +0 -93
  218. package/lib/tasks/php/update-phpbrew.js +0 -45
  219. package/lib/tasks/php/validate-php.js +0 -67
  220. package/lib/tasks/php-fpm/get-process-id.js +0 -14
  221. package/lib/tasks/php-fpm/index.js +0 -4
  222. package/lib/tasks/php-fpm/start-php-fpm.js +0 -49
  223. package/lib/tasks/php-fpm/stop-php-fpm.js +0 -48
  224. package/lib/tasks/requirements/phpbrew/index.js +0 -61
  225. package/lib/tasks/requirements/phpbrew/install.js +0 -159
  226. package/lib/tasks/requirements/phpbrew/version.js +0 -28
@@ -18,18 +18,20 @@ const varnishConfigSetup = () => ({
18
18
  }
19
19
  }
20
20
  },
21
- mysqlConnection,
22
- ports
21
+ databaseConnection,
22
+ ports,
23
+ debug
23
24
  } = ctx;
24
25
 
25
26
  const isLinux = os.platform() === 'linux';
26
27
  const isWsl = await getIsWsl();
28
+ const isNativeLinux = isLinux && !isWsl;
27
29
 
28
- if (varnishEnabled) {
30
+ if (!debug && varnishEnabled) {
29
31
  await updateTableValues('core_config_data', [
30
32
  {
31
33
  path: 'system/full_page_cache/varnish/backend_host',
32
- value: 'localhost'
34
+ value: !isNativeLinux ? 'host.docker.internal' : 'localhost'
33
35
  },
34
36
  {
35
37
  path: 'system/full_page_cache/varnish/backend_port',
@@ -37,16 +39,16 @@ const varnishConfigSetup = () => ({
37
39
  },
38
40
  {
39
41
  path: 'system/full_page_cache/varnish/access_list',
40
- value: (!isLinux || isWsl) ? 'host.docker.internal,localhost' : 'localhost'
42
+ value: !isNativeLinux ? 'host.docker.internal,localhost' : 'localhost'
41
43
  },
42
44
  {
43
45
  path: 'system/full_page_cache/caching_application',
44
46
  value: '2'
45
47
  }
46
- ], { mysqlConnection, task });
48
+ ], { databaseConnection, task });
47
49
  } else {
48
50
  // delete varnish configuration if exists
49
- await mysqlConnection.query(`
51
+ await databaseConnection.query(`
50
52
  DELETE FROM core_config_data WHERE path LIKE '%varnish%';
51
53
  `);
52
54
 
@@ -57,7 +59,7 @@ const varnishConfigSetup = () => ({
57
59
  path: 'system/full_page_cache/caching_application',
58
60
  value: '0'
59
61
  }
60
- ], { mysqlConnection, task });
62
+ ], { databaseConnection, task });
61
63
  }
62
64
  },
63
65
  options: {
@@ -1,14 +1,48 @@
1
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
+ const semver = require('semver');
3
+ const fs = require('fs');
4
+ const path = require('path');
1
5
  const { request } = require('smol-request');
2
6
  const KnownError = require('../../../errors/known-error');
7
+ const { execAsyncSpawn } = require('../../../util/exec-async-command');
8
+ const { NginxParser } = require('../../../util/nginx-logs-parser');
3
9
  const sleep = require('../../../util/sleep');
4
10
 
11
+ const pathToWorkingHealthCheckPhp = path.join(__dirname, '..', '..', 'php', 'working_health_check.php');
12
+ const pathToProjectsHealthCheckPhp = path.join(process.cwd(), 'pub', 'health_check.php');
13
+ const pathToHealthCheckBackupPhp = path.join(process.cwd(), 'pub', 'health_check-super-backup-file.php');
14
+
15
+ /**
16
+ * @param {import('../../../../typings/context').ListrContext} ctx
17
+ */
18
+ const getIsHealthCheckRequestBroken = async (ctx) => {
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');
33
+ };
34
+
5
35
  /**
6
36
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
37
  */
8
38
  const waitingForVarnish = () => ({
9
39
  title: 'Waiting for Varnish to return code 200',
10
- skip: (ctx) => !ctx.config.overridenConfiguration.configuration.varnish.enabled,
11
- task: async (ctx) => {
40
+ skip: (ctx) => ctx.debug || !ctx.config.overridenConfiguration.configuration.varnish.enabled,
41
+ task: async (ctx, task) => {
42
+ const pureMagentoVersion = ctx.magentoVersion.match(/^([0-9]+\.[0-9]+\.[0-9]+)/)[1];
43
+
44
+ const isMagento23 = semver.satisfies(pureMagentoVersion, '<2.4');
45
+
12
46
  let tries = 0;
13
47
  while (tries < 10) {
14
48
  try {
@@ -28,6 +62,94 @@ const waitingForVarnish = () => ({
28
62
  }
29
63
  }
30
64
 
65
+ if (tries === 10 && isMagento23) {
66
+ const isHealthCheckRequestBroken = await getIsHealthCheckRequestBroken(ctx);
67
+ if (isHealthCheckRequestBroken) {
68
+ const confirm = await task.prompt({
69
+ type: 'Select',
70
+ message: `We detected that your Magento instance is experiencing problems with Varnish server.
71
+ Health Check request is returning status 500.
72
+
73
+ Do you want to try resolving this issue by replacing ${logger.style.file('./pub/health_check.php')} file content with content from newer Magento version (2.4.4)?`,
74
+ choices: [
75
+ {
76
+ name: 'yes',
77
+ message: 'Okay, let\'s try that'
78
+ },
79
+ {
80
+ name: 'no',
81
+ message: 'I will try to fix this myself, thanks for the info!'
82
+ }
83
+ ]
84
+ });
85
+
86
+ if (confirm === 'yes') {
87
+ await fs.promises.writeFile(
88
+ pathToHealthCheckBackupPhp,
89
+ await fs.promises.readFile(pathToProjectsHealthCheckPhp, 'utf-8'),
90
+ 'utf-8'
91
+ );
92
+
93
+ task.output = `Backup made! Available at ${logger.style.file(pathToHealthCheckBackupPhp)}`;
94
+
95
+ await fs.promises.writeFile(
96
+ pathToProjectsHealthCheckPhp,
97
+ await fs.promises.readFile(pathToWorkingHealthCheckPhp, 'utf-8'),
98
+ 'utf-8'
99
+ );
100
+
101
+ task.output = `${logger.style.file('./pub/health_check.php')} content is replaced, waiting for nginx logs...`;
102
+
103
+ let connectionFixed = false;
104
+
105
+ for (let i = 0; i < 10; i++) {
106
+ try {
107
+ const response = await request(`http://localhost:${ctx.ports.sslTerminator}/`, {
108
+ responseType: 'headers'
109
+ });
110
+
111
+ if (response.status !== 200) {
112
+ await sleep(2000);
113
+ } else {
114
+ connectionFixed = true;
115
+ break;
116
+ }
117
+ } catch (e) {
118
+ await sleep(200);
119
+ }
120
+ }
121
+
122
+ if (connectionFixed) {
123
+ task.output = 'Connection looks good!';
124
+ const secondConfirm = await task.prompt({
125
+ type: 'Select',
126
+ message: `Okay, looks like it helped!
127
+ Do you want to keep backed up ${logger.style.file('health_check.php')} file?`,
128
+ choices: [
129
+ {
130
+ name: 'no',
131
+ message: 'I don\'t think I will need it anymore, thanks'
132
+ },
133
+ {
134
+ name: 'yes',
135
+ message: 'I will keep it, maybe it will be useful (X to doubt)'
136
+ }
137
+ ]
138
+ });
139
+
140
+ if (secondConfirm === 'no') {
141
+ await fs.promises.rm(pathToHealthCheckBackupPhp);
142
+ }
143
+ }
144
+
145
+ return;
146
+ }
147
+
148
+ task.skip('User choose to fix issue himself');
149
+ return;
150
+ }
151
+ }
152
+
31
153
  if (tries === 10) {
32
154
  throw new KnownError(`After 20 seconds website is still responding with non-200 code, which might indicate issue with setup.
33
155
  Or Varnish is still loading...
@@ -35,7 +157,10 @@ Or Varnish is still loading...
35
157
  Please check the logs!`);
36
158
  }
37
159
  },
38
- exitOnError: false
160
+ exitOnError: false,
161
+ options: {
162
+ bottomBar: 10
163
+ }
39
164
  });
40
165
 
41
166
  module.exports = waitingForVarnish;
@@ -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
+ };
@@ -1,10 +1,12 @@
1
1
  const path = require('path');
2
+ const os = require('os');
2
3
  const envPhpToJson = require('../../util/env-php-json');
3
4
  const getJsonfileData = require('../../util/get-jsonfile-data');
4
5
  const pathExists = require('../../util/path-exists');
5
- const phpTask = require('../../util/php-task');
6
+ const { containerApi } = require('../docker/containers');
6
7
 
7
8
  const composerLockPath = path.join(process.cwd(), 'composer.lock');
9
+ const envPhpPath = path.join(process.cwd(), 'app', 'etc', 'env.php');
8
10
  /**
9
11
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
10
12
  */
@@ -12,13 +14,19 @@ const updateEnvPHP = () => ({
12
14
  title: 'Updating env.php',
13
15
  task: async (ctx, task) => {
14
16
  // update env.php only if it's exist
15
- if (!await pathExists(path.join(process.cwd(), 'app', 'etc', 'env.php'))) {
17
+ if (!await pathExists(envPhpPath)) {
16
18
  task.skip();
17
19
  return;
18
20
  }
19
21
 
20
- const useVarnish = ctx.config.overridenConfiguration.configuration.varnish.enabled ? '1' : '';
21
- const varnishHost = '127.0.0.1';
22
+ const { php } = ctx.config.docker.getContainers(ctx.ports);
23
+
24
+ const isLinux = ctx.platform === 'linux';
25
+ const isNativeLinux = isLinux && !ctx.isWsl;
26
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
27
+
28
+ const useVarnish = (!ctx.debug && ctx.config.overridenConfiguration.configuration.varnish.enabled) ? '1' : '';
29
+ const varnishHost = hostMachine;
22
30
  const varnishPort = ctx.ports.varnish;
23
31
  const previousVarnishPort = ctx.cachedPorts
24
32
  ? ctx.cachedPorts.varnish
@@ -34,15 +42,15 @@ const updateEnvPHP = () => ({
34
42
  ctx.CSAThemeInstalled = true;
35
43
  }
36
44
 
37
- const envPhp = await envPhpToJson(process.cwd(), { magentoVersion: ctx.magentoVersion });
45
+ const envPhp = await envPhpToJson(ctx);
38
46
 
39
47
  const persistedQueryConfig = envPhp.cache && envPhp.cache['persisted-query'];
40
48
 
41
49
  if (
42
50
  persistedQueryConfig
43
51
  && persistedQueryConfig.redis
44
- && persistedQueryConfig.redis.port === `${ ctx.ports.redis }`
45
- && persistedQueryConfig.redis.host === 'localhost'
52
+ && (persistedQueryConfig.redis.port !== `${ ctx.ports.redis }`
53
+ || persistedQueryConfig.redis.host === hostMachine)
46
54
  ) {
47
55
  SETUP_PQ = '';
48
56
  return;
@@ -50,20 +58,30 @@ const updateEnvPHP = () => ({
50
58
  }
51
59
  }
52
60
 
53
- return task.newListr(
54
- phpTask(`-f ${ path.join(__dirname, 'update-env.php') }`, {
55
- noTitle: true,
56
- env: {
57
- USE_VARNISH: useVarnish,
58
- VARNISH_PORT: `${ varnishPort }`,
59
- VARNISH_HOST: varnishHost,
60
- PREVIOUS_VARNISH_PORT: `${ previousVarnishPort }`,
61
- SETUP_PQ,
62
- REDIS_PORT: ctx.ports.redis,
63
- ADMIN_URI: ctx.config.overridenConfiguration.magento.adminuri
64
- }
65
- })
66
- );
61
+ const result = await containerApi.run({
62
+ env: {
63
+ USE_VARNISH: useVarnish,
64
+ VARNISH_PORT: `${ varnishPort }`,
65
+ VARNISH_HOST: varnishHost,
66
+ PREVIOUS_VARNISH_PORT: `${ previousVarnishPort }`,
67
+ SETUP_PQ,
68
+ REDIS_PORT: ctx.ports.redis,
69
+ ADMIN_URI: ctx.config.overridenConfiguration.magento.adminuri,
70
+ HOST_MACHINE: hostMachine,
71
+ PORTS: JSON.stringify(ctx.ports)
72
+ },
73
+ command: 'php ./update-env-php.php',
74
+ mountVolumes: [
75
+ `${path.join(__dirname, 'update-env.php')}:${ctx.config.baseConfig.containerMagentoDir}/update-env-php.php`,
76
+ `${envPhpPath}:/${ctx.config.baseConfig.containerMagentoDir}/env.php`
77
+ ],
78
+ image: php.image,
79
+ detach: false,
80
+ rm: true,
81
+ user: isLinux ? `${os.userInfo().uid}:${os.userInfo().gid}` : ''
82
+ });
83
+
84
+ task.output = result;
67
85
  }
68
86
  });
69
87
 
@@ -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", '$1$1$2', $export);
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, ']$1', ' => ['], $array);
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('#/+#', '/', join('/', $paths));
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 './app/etc/env.php';
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 = file_get_contents('./node_modules/.create-magento-app-cache/port-config.json');
66
+ $portConfigContent = getenv("PORTS");
67
67
  if ($portConfigContent === false) {
68
- throw new Error('Port config file does not exists in cache directory');
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('Port config file is not content');
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['backend']['frontName'] = getenv('ADMIN_URI');
83
-
84
- // update mysql config
85
- if (isset($this->config['db']['connection']['default'])) {
86
- $conn = &$this->config['db']['connection']['default'];
87
- if (
88
- isset($conn['engine']) &&
89
- isset($conn['host']) &&
90
- $conn['engine'] === 'innodb' &&
91
- $conn['host'] !== '127.0.0.1:' . $this->portConfig['mysql']
92
- ) {
93
- $conn['host'] = '127.0.0.1:' . $this->portConfig['mysql'];
94
- }
82
+ $this->config["backend"]["frontName"] = getenv("ADMIN_URI");
83
+ $hostMachine = getenv("HOST_MACHINE");
84
+ if ($hostMachine === false) {
85
+ $hostMachine = '127.0.0.1';
86
+ }
87
+
88
+ // update mariadb config
89
+ if (isset($this->config["db"]["connection"]["default"])) {
90
+ $conn = &$this->config["db"]["connection"]["default"];
91
+ $mysqlHost = $hostMachine . ":" . $this->portConfig["mariadb"];
92
+
93
+ $conn["host"] = $mysqlHost;
95
94
  }
96
95
 
97
96
  // update redis session config
98
97
  if (
99
- isset($this->config['session']) &&
100
- $this->config['session']['save'] === 'redis' &&
101
- $this->config['session']['redis']['port'] !== strval($this->portConfig['redis'])
98
+ isset($this->config["session"]) &&
99
+ $this->config["session"]["save"] === "redis" &&
100
+ $this->config["session"]["redis"]["port"] !== strval($this->portConfig["redis"])
102
101
  ) {
103
- $this->config['session']['redis']['port'] = strval($this->portConfig['redis']);
102
+ $this->config["session"]["redis"]["port"] = strval($this->portConfig["redis"]);
104
103
  }
105
104
 
106
105
  if (
107
- isset($this->config['session']) &&
108
- $this->config['session']['save'] === 'redis' &&
109
- $this->config['session']['redis']['host'] !== '127.0.0.1'
106
+ isset($this->config["session"]) &&
107
+ $this->config["session"]["save"] === "redis" &&
108
+ $this->config["session"]["redis"]["host"] !== $hostMachine
110
109
  ) {
111
- $this->config['session']['redis']['host'] = '127.0.0.1';
110
+ $this->config["session"]["redis"]["host"] = $hostMachine;
112
111
  }
113
112
 
114
113
  // update redis frontend config
115
- if (isset($this->config['cache']['frontend']['default'])) {
116
- $frontendCache = &$this->config['cache']['frontend']['default'];
117
- if ($frontendCache['backend_options']['port'] !== strval($this->portConfig['redis'])) {
118
- $frontendCache['backend_options']['port'] = strval($this->portConfig['redis']);
114
+ if (isset($this->config["cache"]["frontend"]["default"])) {
115
+ $frontendCache = &$this->config["cache"]["frontend"]["default"];
116
+ if ($frontendCache["backend_options"]["port"] !== strval($this->portConfig["redis"])) {
117
+ $frontendCache["backend_options"]["port"] = strval($this->portConfig["redis"]);
119
118
  }
120
- if ($frontendCache['backend_options']['server'] !== '127.0.0.1') {
121
- $frontendCache['backend_options']['server'] = '127.0.0.1';
119
+ if ($frontendCache["backend_options"]["server"] !== $hostMachine) {
120
+ $frontendCache["backend_options"]["server"] = $hostMachine;
122
121
  }
123
122
  }
124
123
 
125
124
  // update persisted query redis config
126
- if (getenv('SETUP_PQ') == '1') {
127
- $cacheConfig = &$this->config['cache'];
128
- $redisPort = getenv('REDIS_PORT');
125
+ if (getenv("SETUP_PQ") == "1") {
126
+ $cacheConfig = &$this->config["cache"];
127
+ $redisPort = getenv("REDIS_PORT");
129
128
 
130
- if (isset($cacheConfig) && isset($cacheConfig['persisted-query']) && isset($cacheConfig['persisted-query']['redis']) && $cacheConfig['persisted-query']['redis']['port'] != $redisPort) {
131
- $cacheConfig['persisted-query']['redis']['port'] = $redisPort;
129
+ if (isset($cacheConfig) && isset($cacheConfig["persisted-query"]) && isset($cacheConfig["persisted-query"]["redis"])) {
130
+ if ($cacheConfig["persisted-query"]["redis"]["port"] !== $redisPort) {
131
+ $cacheConfig["persisted-query"]["redis"]["port"] = $redisPort;
132
+ }
133
+
134
+ if ($cacheConfig["persisted-query"]["redis"]["host"] !== $hostMachine) {
135
+ $cacheConfig["persisted-query"]["redis"]["host"] = $hostMachine;
136
+ }
132
137
  } else {
133
138
  if (!isset($cacheConfig)) {
134
- $this->config['cache'] = [];
139
+ $this->config["cache"] = [];
135
140
  }
136
- $this->config['cache']['persisted-query'] = [
137
- 'redis' => [
138
- 'host' => 'localhost',
139
- 'port' => $redisPort,
140
- 'database' => '5',
141
- 'scheme' => 'tcp'
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['cache']['persisted-query']);
151
+ unset($this->config["cache"]["persisted-query"]);
147
152
  }
148
153
 
149
154
  // set varnish config
150
- $httpCacheHosts = &$this->config['http_cache_hosts'];
155
+ $httpCacheHosts = &$this->config["http_cache_hosts"];
151
156
  $httpCacheHosts = [];
152
157
 
153
- if (getenv('USE_VARNISH') == '1') {
154
- $varnishHost = getenv('VARNISH_HOST');
155
- $varnishPort = getenv('VARNISH_PORT');
156
- $previousVarnishPort = getenv('PREVIOUS_VARNISH_PORT');
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
- 'host' => $varnishHost,
159
- 'port' => $varnishPort
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['host'] == $varnishHost && $host['port'] == $previousVarnishPort) {
166
- $host['port'] = $varnishPort;
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['http_cache_hosts'] = [$varnishConfig];
181
+ $this->config["http_cache_hosts"] = [$varnishConfig];
177
182
  }
178
183
  } else {
179
- unset($this->config['http_cache_hosts']);
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
- '<?php'.PHP_EOL.'return '.varexport($this->config, true).';' . PHP_EOL
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(joinpaths(getcwd(), './app/etc/env.php'));
201
+ $this->saveConfig("./env.php");
197
202
  }
198
203
  }
199
204