@scandipwa/magento-scripts 2.0.0-alpha.0 → 2.0.0-alpha.11

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 (165) hide show
  1. package/exec.js +71 -0
  2. package/index.js +1 -1
  3. package/lib/commands/cli.js +7 -2
  4. package/lib/commands/execute.js +3 -58
  5. package/lib/commands/import-db.js +1 -1
  6. package/lib/commands/logs.js +1 -1
  7. package/lib/commands/start.js +18 -8
  8. package/lib/commands/status.js +9 -1
  9. package/lib/config/config.js +20 -2
  10. package/lib/config/docker.js +79 -85
  11. package/lib/config/index.js +2 -2
  12. package/lib/config/php/versions/php-7.2.js +1 -0
  13. package/lib/config/php/versions/php-7.3.js +1 -0
  14. package/lib/config/php/versions/php-7.4.js +1 -0
  15. package/lib/config/php/versions/php-8.1.js +1 -0
  16. package/lib/config/php-config.js +4 -3
  17. package/lib/config/port-config.js +1 -1
  18. package/lib/config/services/composer/versions/composer-1.js +8 -0
  19. package/lib/config/services/composer/versions/composer-2.js +8 -0
  20. package/lib/config/services/composer/versions/index.js +4 -0
  21. package/lib/config/services/elasticsearch/base-repo.js +3 -0
  22. package/lib/config/services/elasticsearch/default-es-env.js +6 -0
  23. package/lib/config/services/elasticsearch/versions/elasticsearch-6.8.js +19 -0
  24. package/lib/config/services/elasticsearch/versions/index.js +5 -0
  25. package/lib/config/services/nginx/versions/index.js +3 -0
  26. package/lib/config/services/nginx/versions/nginx-1.18.js +11 -0
  27. package/lib/config/{ssl-terminator → services/ssl-terminator}/index.js +3 -0
  28. package/lib/config/templates/magentorc.template +6 -5
  29. package/lib/config/templates/mariadb.template.cnf +191 -0
  30. package/lib/config/templates/php-debug.template.ini +31 -0
  31. package/lib/config/templates/php-fpm.template.conf +1 -2
  32. package/lib/config/templates/php.template.ini +6 -202
  33. package/lib/config/templates/ssl-terminator.template.conf +10 -3
  34. package/lib/config/templates/varnish.template.vcl +20 -13
  35. package/lib/config/varnish/varnish-6-0.js +4 -0
  36. package/lib/config/varnish/varnish-6-6.js +4 -0
  37. package/lib/config/varnish/varnish-7-0.js +4 -0
  38. package/lib/config/versions/magento-2.3.0.js +7 -12
  39. package/lib/config/versions/magento-2.3.1.js +7 -12
  40. package/lib/config/versions/magento-2.3.2-p1.js +7 -12
  41. package/lib/config/versions/magento-2.3.2-p2.js +7 -12
  42. package/lib/config/versions/magento-2.3.2.js +7 -12
  43. package/lib/config/versions/magento-2.3.3-p1.js +7 -12
  44. package/lib/config/versions/magento-2.3.3.js +7 -12
  45. package/lib/config/versions/magento-2.3.4-p1.js +7 -12
  46. package/lib/config/versions/magento-2.3.4-p2.js +7 -12
  47. package/lib/config/versions/magento-2.3.4.js +7 -12
  48. package/lib/config/versions/magento-2.3.5-p1.js +5 -9
  49. package/lib/config/versions/magento-2.3.5-p2.js +5 -9
  50. package/lib/config/versions/magento-2.3.5.js +5 -9
  51. package/lib/config/versions/magento-2.3.6-p1.js +5 -9
  52. package/lib/config/versions/magento-2.3.6.js +5 -9
  53. package/lib/config/versions/magento-2.3.7-p1.js +5 -9
  54. package/lib/config/versions/magento-2.3.7-p2.js +5 -9
  55. package/lib/config/versions/magento-2.3.7-p3.js +5 -9
  56. package/lib/config/versions/magento-2.3.7-p4.js +40 -0
  57. package/lib/config/versions/magento-2.3.7.js +5 -9
  58. package/lib/config/versions/magento-2.4.0-p1.js +5 -9
  59. package/lib/config/versions/magento-2.4.0.js +5 -9
  60. package/lib/config/versions/magento-2.4.1-p1.js +5 -9
  61. package/lib/config/versions/magento-2.4.1.js +5 -9
  62. package/lib/config/versions/magento-2.4.2-p1.js +5 -9
  63. package/lib/config/versions/magento-2.4.2-p2.js +5 -9
  64. package/lib/config/versions/magento-2.4.2.js +5 -9
  65. package/lib/config/versions/magento-2.4.3-p1.js +5 -9
  66. package/lib/config/versions/magento-2.4.3-p2.js +5 -9
  67. package/lib/config/versions/magento-2.4.3-p3.js +42 -0
  68. package/lib/config/versions/magento-2.4.3.js +5 -9
  69. package/lib/config/versions/magento-2.4.4-p1.js +42 -0
  70. package/lib/config/versions/magento-2.4.4.js +5 -9
  71. package/lib/config/versions/magento-2.4.5.js +42 -0
  72. package/lib/tasks/cleanup.js +1 -1
  73. package/lib/tasks/composer/local-auth-json.js +1 -1
  74. package/lib/tasks/database/connect-to-database.js +120 -0
  75. package/lib/tasks/database/create-magento-database.js +21 -0
  76. package/lib/tasks/database/create-magento-user.js +50 -0
  77. package/lib/tasks/database/default-magento-database.js +3 -0
  78. package/lib/tasks/database/default-magento-user.js +7 -0
  79. package/lib/tasks/{mysql → database}/dump-theme-config.js +3 -3
  80. package/lib/tasks/{mysql → database}/fix-db.js +2 -2
  81. package/lib/tasks/{mysql/import-dump-to-mysql.js → database/import-dump-to-database.js} +21 -20
  82. package/lib/tasks/{mysql → database}/import-remote-db/index.js +0 -0
  83. package/lib/tasks/{mysql/import-remote-db/ssh/mysqldump-command.js → database/import-remote-db/ssh/database-dump-command.js} +2 -2
  84. package/lib/tasks/{mysql → database}/import-remote-db/ssh/index.js +0 -0
  85. package/lib/tasks/{mysql → database}/import-remote-db/ssh/readymage.js +4 -4
  86. package/lib/tasks/{mysql → database}/import-remote-db/ssh/regular-server.js +2 -2
  87. package/lib/tasks/{mysql → database}/index.js +2 -2
  88. package/lib/tasks/{mysql → database}/magento-tables.js +0 -0
  89. package/lib/tasks/{mysql → database}/restore-theme-config.js +4 -4
  90. package/lib/tasks/docker/api.d.ts +25 -1
  91. package/lib/tasks/docker/api.js +31 -1
  92. package/lib/tasks/docker/containers/container-api.d.ts +18 -0
  93. package/lib/tasks/docker/containers/container-api.js +76 -17
  94. package/lib/tasks/docker/containers/tasks.js +32 -1
  95. package/lib/tasks/docker/convert-legacy-volumes.js +8 -7
  96. package/lib/tasks/docker/convert-mysql-to-mariadb.js +284 -0
  97. package/lib/tasks/docker/index.js +6 -1
  98. package/lib/tasks/docker/network/network-api.d.ts +1 -1
  99. package/lib/tasks/docker/project-image-builder.js +7 -9
  100. package/lib/tasks/docker/volume/index.js +9 -0
  101. package/lib/tasks/docker/volume/tasks.js +94 -0
  102. package/lib/tasks/docker/volume/volume-api.d.ts +49 -0
  103. package/lib/tasks/docker/volume/volume-api.js +90 -0
  104. package/lib/tasks/execute.js +100 -0
  105. package/lib/tasks/file-system/create-mariadb-config.js +23 -0
  106. package/lib/tasks/file-system/create-nginx-config.js +3 -5
  107. package/lib/tasks/file-system/create-php-config.js +2 -23
  108. package/lib/tasks/file-system/create-php-debug-config.js +45 -0
  109. package/lib/tasks/file-system/create-php-fpm-config.js +2 -4
  110. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-workspace-project-configuration-config.js +1 -1
  111. package/lib/tasks/file-system/create-ssl-terminator-config.js +4 -7
  112. package/lib/tasks/file-system/create-varnish-config.js +4 -7
  113. package/lib/tasks/file-system/index.js +5 -1
  114. package/lib/tasks/import-dump.js +6 -6
  115. package/lib/tasks/link.js +4 -2
  116. package/lib/tasks/magento/enable-magento-composer-plugins.js +85 -30
  117. package/lib/tasks/magento/install-magento-project.js +3 -2
  118. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +3 -5
  119. package/lib/tasks/magento/setup-magento/create-admin.js +1 -1
  120. package/lib/tasks/magento/setup-magento/delete-admin-users.js +2 -2
  121. package/lib/tasks/magento/setup-magento/delete-customers.js +4 -4
  122. package/lib/tasks/magento/setup-magento/delete-orders.js +4 -4
  123. package/lib/tasks/magento/setup-magento/flush-redis-config.js +3 -6
  124. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +2 -2
  125. package/lib/tasks/magento/setup-magento/index.js +2 -0
  126. package/lib/tasks/magento/setup-magento/install-magento.js +15 -17
  127. package/lib/tasks/magento/setup-magento/migrate-database.js +5 -11
  128. package/lib/tasks/magento/setup-magento/set-base-url.js +3 -3
  129. package/lib/tasks/magento/setup-magento/set-url-rewrite.js +2 -2
  130. package/lib/tasks/magento/setup-magento/varnish-config.js +8 -13
  131. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +17 -16
  132. package/lib/tasks/php/php-container.js +7 -3
  133. package/lib/tasks/php/update-env-php.js +7 -6
  134. package/lib/tasks/php/update-env.php +12 -12
  135. package/lib/tasks/requirements/composer-credentials.js +7 -3
  136. package/lib/tasks/requirements/docker/context.js +88 -0
  137. package/lib/tasks/requirements/docker/index.js +110 -19
  138. package/lib/tasks/requirements/docker/install.js +21 -7
  139. package/lib/tasks/requirements/docker/permissions.js +2 -11
  140. package/lib/tasks/requirements/docker/running-status.js +94 -24
  141. package/lib/tasks/requirements/docker/version.js +1 -0
  142. package/lib/tasks/requirements/index.js +0 -2
  143. package/lib/tasks/requirements/php-version.js +4 -2
  144. package/lib/tasks/start.js +32 -31
  145. package/lib/tasks/status/index.js +17 -13
  146. package/lib/tasks/stop.js +2 -0
  147. package/lib/tasks/theme/link-theme.js +2 -2
  148. package/lib/util/config-file-validator.js +29 -13
  149. package/lib/util/database.js +7 -7
  150. package/lib/util/execute-in-container.js +63 -0
  151. package/lib/util/prefix.js +1 -1
  152. package/lib/util/systemctl.js +62 -13
  153. package/package.json +4 -3
  154. package/typings/context.d.ts +12 -5
  155. package/typings/index.d.ts +69 -31
  156. package/lib/tasks/docker/volumes.js +0 -63
  157. package/lib/tasks/execute/index.js +0 -23
  158. package/lib/tasks/mysql/connect-to-mysql.js +0 -127
  159. package/lib/tasks/mysql/create-magento-database.js +0 -18
  160. package/lib/tasks/requirements/dependency/arch.js +0 -50
  161. package/lib/tasks/requirements/dependency/centos.js +0 -36
  162. package/lib/tasks/requirements/dependency/fedora.js +0 -36
  163. package/lib/tasks/requirements/dependency/index.js +0 -33
  164. package/lib/tasks/requirements/dependency/mac.js +0 -124
  165. package/lib/tasks/requirements/dependency/ubuntu.js +0 -83
@@ -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 /var/www/html/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,14 +7,12 @@ 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, mysqlConnection } = 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 },
17
15
  { path: 'catalog/search/elasticsearch7_server_port', value: `${ports.elasticsearch}` }
18
- ], { mysqlConnection, task });
16
+ ], { databaseConnection, task });
19
17
  }
20
18
  });
@@ -7,7 +7,7 @@ module.exports = () => ({
7
7
  title: 'Creating admin user',
8
8
  task: async (ctx, task) => {
9
9
  const { config: { magentoConfiguration } } = ctx;
10
- const [[{ userCount }]] = await ctx.mysqlConnection.query(`
10
+ const [[{ userCount }]] = await ctx.databaseConnection.query(`
11
11
  SELECT count(*) AS userCount
12
12
  FROM admin_user
13
13
  WHERE username = ?;
@@ -7,8 +7,8 @@ const deleteAdminUsers = () => ({
7
7
  title: 'Deleting old admin users',
8
8
  skip: async (ctx) => !(await isTableExists('magento', 'admin_user', ctx)),
9
9
  task: async (ctx) => {
10
- const { mysqlConnection } = ctx;
11
- await mysqlConnection.query(`
10
+ const { databaseConnection } = ctx;
11
+ await databaseConnection.query(`
12
12
  TRUNCATE TABLE admin_user;
13
13
  `);
14
14
  }
@@ -1,4 +1,4 @@
1
- const { customerTables } = require('../../mysql/magento-tables');
1
+ const { customerTables } = require('../../database/magento-tables');
2
2
 
3
3
  /**
4
4
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -6,19 +6,19 @@ const { customerTables } = require('../../mysql/magento-tables');
6
6
  const deleteCustomers = () => ({
7
7
  title: 'Deleting customers',
8
8
  task: async (ctx, task) => {
9
- const { mysqlConnection, withCustomersData } = ctx;
9
+ const { databaseConnection, withCustomersData } = ctx;
10
10
 
11
11
  if (withCustomersData) {
12
12
  task.skip();
13
13
  return;
14
14
  }
15
15
 
16
- const [rows] = await mysqlConnection.query('select TABLE_NAME from information_schema.TABLES;');
16
+ const [rows] = await databaseConnection.query('select TABLE_NAME from information_schema.TABLES;');
17
17
 
18
18
  await Promise.all(
19
19
  customerTables
20
20
  .filter((tableName) => rows.some((row) => row.TABLE_NAME === tableName))
21
- .map((tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
21
+ .map((tableName) => databaseConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
22
22
  );
23
23
  }
24
24
  });
@@ -1,4 +1,4 @@
1
- const { orderTables } = require('../../mysql/magento-tables');
1
+ const { orderTables } = require('../../database/magento-tables');
2
2
 
3
3
  /**
4
4
  * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -6,19 +6,19 @@ const { orderTables } = require('../../mysql/magento-tables');
6
6
  const deleteOrders = () => ({
7
7
  title: 'Deleting orders',
8
8
  task: async (ctx, task) => {
9
- const { mysqlConnection, withCustomersData } = ctx;
9
+ const { databaseConnection, withCustomersData } = ctx;
10
10
 
11
11
  if (withCustomersData) {
12
12
  task.skip();
13
13
  return;
14
14
  }
15
15
 
16
- const [rows] = await mysqlConnection.query('select TABLE_NAME from information_schema.TABLES;');
16
+ const [rows] = await databaseConnection.query('select TABLE_NAME from information_schema.TABLES;');
17
17
 
18
18
  await Promise.all(
19
19
  orderTables
20
20
  .filter((tableName) => rows.some((row) => row.TABLE_NAME === tableName))
21
- .map((tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
21
+ .map((tableName) => databaseConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
22
22
  );
23
23
  }
24
24
  });
@@ -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,7 +5,7 @@ const { updateTableValues } = require('../../../util/database');
5
5
  */
6
6
  const increaseAdminSessionLifetime = () => ({
7
7
  title: 'Increase admin session lifetime to 1 month',
8
- task: async ({ mysqlConnection }, task) => updateTableValues('core_config_data', [
8
+ task: async ({ databaseConnection }, task) => updateTableValues('core_config_data', [
9
9
  {
10
10
  path: 'admin/security/session_lifetime',
11
11
  value: '2800000'
@@ -15,7 +15,7 @@ const increaseAdminSessionLifetime = () => ({
15
15
  value: null
16
16
  }
17
17
  ], {
18
- mysqlConnection,
18
+ databaseConnection,
19
19
  task
20
20
  })
21
21
 
@@ -11,6 +11,7 @@ const increaseAdminSessionLifetime = require('./increase-admin-session-lifetime'
11
11
  const magentoTask = require('../../../util/magento-task');
12
12
  const urnHighlighter = require('./urn-highlighter');
13
13
  const adjustFullPageCache = require('./adjust-full-page-cache');
14
+ const updateEnvPHP = require('../../php/update-env-php');
14
15
 
15
16
  /**
16
17
  * @param {Object} [options]
@@ -32,6 +33,7 @@ const setupMagento = (options = {}) => ({
32
33
  return task.newListr([
33
34
  flushRedisConfig(),
34
35
  waitingForRedis(),
36
+ updateEnvPHP(),
35
37
  migrateDatabase(),
36
38
  {
37
39
  title: 'Configuring Magento settings',
@@ -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,23 +22,21 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
20
22
  const {
21
23
  magentoVersion,
22
24
  config: {
23
- docker,
24
25
  magentoConfiguration
25
26
  },
26
27
  ports,
27
- mysqlConnection
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
- const [tableResponse] = await mysqlConnection.query(
34
+ const [tableResponse] = await databaseConnection.query(
35
35
  'SELECT * FROM information_schema.tables WHERE table_schema = \'magento\' AND table_name = \'admin_user\' LIMIT 1;'
36
36
  );
37
37
 
38
38
  if (tableResponse.length > 0) {
39
- const response = await mysqlConnection.query(
39
+ const response = await databaseConnection.query(
40
40
  'select * from admin_user where username=\'admin\';'
41
41
  );
42
42
 
@@ -58,23 +58,21 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
58
58
  ]
59
59
  });
60
60
 
61
- await mysqlConnection.query('SET FOREIGN_KEY_CHECKS = 0;');
61
+ await databaseConnection.query('SET FOREIGN_KEY_CHECKS = 0;');
62
62
 
63
63
  if (confirmDeleteAdminUsers === 'delete-all') {
64
- await mysqlConnection.query(`
64
+ await databaseConnection.query(`
65
65
  TRUNCATE TABLE admin_user;
66
66
  `);
67
67
  } else {
68
- await mysqlConnection.query(`
68
+ await databaseConnection.query(`
69
69
  DELETE FROM admin_user WHERE username='admin';
70
70
  `);
71
71
  }
72
72
 
73
- await mysqlConnection.query('SET FOREIGN_KEY_CHECKS = 1;');
73
+ await databaseConnection.query('SET FOREIGN_KEY_CHECKS = 1;');
74
74
  }
75
75
  }
76
-
77
- const { mysql: { 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;
@@ -126,10 +124,10 @@ const installMagento = ({ isDbEmpty = false } = {}) => ({
126
124
  --cache-backend-redis-server='${ hostMachine }' \
127
125
  --cache-backend-redis-port='${ ports.redis }' \
128
126
  --cache-backend-redis-db='0't \
129
- --db-host='${ hostMachine }:${ ports.mysql }' \
130
- --db-name='${ env.MYSQL_DATABASE }' \
131
- --db-user='${ env.MYSQL_USER }' \
132
- --db-password='${ env.MYSQL_PASSWORD }' \
127
+ --db-host='${ hostMachine }:${ ports.mariadb }' \
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
 
@@ -8,6 +8,7 @@ const upgradeMagento = require('./upgrade-magento');
8
8
  const varnishConfigSetup = require('./varnish-config');
9
9
  const pathExists = require('../../../util/path-exists');
10
10
  const updateEnvPHP = require('../../php/update-env-php');
11
+ const UnknownError = require('../../../errors/unknown-error');
11
12
 
12
13
  /**
13
14
  * @param {Object} [options]
@@ -17,9 +18,9 @@ const updateEnvPHP = require('../../php/update-env-php');
17
18
  const migrateDatabase = (options = {}) => ({
18
19
  title: 'Migrating database',
19
20
  task: async (ctx, task) => {
20
- const { mysqlConnection } = ctx;
21
+ const { databaseConnection } = ctx;
21
22
 
22
- const [[{ tableCount }]] = await mysqlConnection.query(`
23
+ const [[{ tableCount }]] = await databaseConnection.query(`
23
24
  SELECT count(*) AS tableCount
24
25
  FROM INFORMATION_SCHEMA.TABLES
25
26
  WHERE TABLE_SCHEMA = 'magento';
@@ -33,13 +34,11 @@ const migrateDatabase = (options = {}) => ({
33
34
  if (options.onlyInstallMagento) {
34
35
  ctx.isSetupUpgradeNeeded = false;
35
36
  return task.newListr([
36
- updateEnvPHP(),
37
37
  installMagento({ isDbEmpty: true })
38
38
  ]);
39
39
  }
40
40
 
41
41
  return task.newListr([
42
- updateEnvPHP(),
43
42
  installMagento({ isDbEmpty: true }),
44
43
  updateEnvPHP(),
45
44
  varnishConfigSetup(),
@@ -56,7 +55,7 @@ const migrateDatabase = (options = {}) => ({
56
55
  });
57
56
  }
58
57
 
59
- const { code } = await runMagentoCommand(ctx, 'setup:db:status', {
58
+ const { code, result } = await runMagentoCommand(ctx, 'setup:db:status', {
60
59
  throwNonZeroCode: false
61
60
  });
62
61
 
@@ -65,7 +64,6 @@ const migrateDatabase = (options = {}) => ({
65
64
  ctx.isSetupUpgradeNeeded = false;
66
65
  // no setup is needed, but still to be sure configure ES
67
66
  return task.newListr([
68
- updateEnvPHP(),
69
67
  varnishConfigSetup(),
70
68
  configureElasticsearch()
71
69
  ], {
@@ -88,7 +86,6 @@ const migrateDatabase = (options = {}) => ({
88
86
 
89
87
  return task.newListr([
90
88
  installMagentoProject(),
91
- updateEnvPHP(),
92
89
  installMagento(),
93
90
  updateEnvPHP(),
94
91
  varnishConfigSetup(),
@@ -106,7 +103,6 @@ const migrateDatabase = (options = {}) => ({
106
103
  }
107
104
  case 2: {
108
105
  return task.newListr([
109
- updateEnvPHP(),
110
106
  varnishConfigSetup(),
111
107
  configureElasticsearch(),
112
108
  upgradeMagento()
@@ -120,9 +116,7 @@ const migrateDatabase = (options = {}) => ({
120
116
  });
121
117
  }
122
118
  default: {
123
- // TODO: handle these statuses ?
124
- task.title = 'Migrating database failed: manual action is required!';
125
- break;
119
+ throw new UnknownError(`Migrating database failed: manual action is required!\n\n${result}`);
126
120
  }
127
121
  }
128
122
  },
@@ -14,10 +14,10 @@ module.exports = () => ({
14
14
  ssl
15
15
  }
16
16
  },
17
- mysqlConnection
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}`;
@@ -29,6 +29,6 @@ module.exports = () => ({
29
29
  { path: 'web/secure/use_in_frontend', value: enableSecureFrontend },
30
30
  { path: 'web/secure/use_in_adminhtml', value: enableSecureFrontend },
31
31
  { path: 'web/cookie/cookie_domain', value: null }
32
- ], { mysqlConnection, task });
32
+ ], { databaseConnection, task });
33
33
  }
34
34
  });
@@ -5,13 +5,13 @@ const { updateTableValues } = require('../../../util/database');
5
5
  */
6
6
  const setUrlRewrite = () => ({
7
7
  title: 'Setting up url-rewrites',
8
- task: async ({ mysqlConnection }, task) => {
8
+ task: async ({ databaseConnection }, task) => {
9
9
  await updateTableValues('core_config_data', [
10
10
  {
11
11
  path: 'web/seo/use_rewrites',
12
12
  value: '1'
13
13
  }
14
- ], { mysqlConnection, task });
14
+ ], { databaseConnection, task });
15
15
  }
16
16
  });
17
17
 
@@ -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>}
@@ -18,20 +16,17 @@ const varnishConfigSetup = () => ({
18
16
  }
19
17
  }
20
18
  },
21
- mysqlConnection,
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,16 +34,16 @@ 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',
46
41
  value: '2'
47
42
  }
48
- ], { mysqlConnection, task });
43
+ ], { databaseConnection, task });
49
44
  } else {
50
45
  // delete varnish configuration if exists
51
- await mysqlConnection.query(`
46
+ await databaseConnection.query(`
52
47
  DELETE FROM core_config_data WHERE path LIKE '%varnish%';
53
48
  `);
54
49
 
@@ -59,7 +54,7 @@ const varnishConfigSetup = () => ({
59
54
  path: 'system/full_page_cache/caching_application',
60
55
  value: '0'
61
56
  }
62
- ], { mysqlConnection, task });
57
+ ], { databaseConnection, task });
63
58
  }
64
59
  },
65
60
  options: {
@@ -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 {