@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
@@ -0,0 +1,120 @@
1
+ const mysql2 = require('mysql2/promise');
2
+ const UnknownError = require('../../errors/unknown-error');
3
+ const { execAsyncSpawn } = require('../../util/exec-async-command');
4
+ const sleep = require('../../util/sleep');
5
+ const { createMagentoDatabase } = require('./create-magento-database');
6
+ const { createMagentoUser } = require('./create-magento-user');
7
+ const defaultMagentoUser = require('./default-magento-user');
8
+
9
+ /**
10
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
11
+ */
12
+ const waitForDatabaseInitialization = () => ({
13
+ title: 'Waiting for Database to initialize',
14
+ task: async (ctx, task) => {
15
+ const { mariadb } = ctx.config.docker.getContainers();
16
+
17
+ let databaseReadyForConnections = false;
18
+
19
+ while (!databaseReadyForConnections) {
20
+ const databaseOutput = await execAsyncSpawn(`docker logs ${mariadb.name}`);
21
+ if (databaseOutput.includes('ready for connections')) {
22
+ databaseReadyForConnections = true;
23
+ break;
24
+ } else if (databaseOutput.includes('Initializing database files')) {
25
+ task.output = `${mariadb._} is initializing database files!
26
+ Please wait, this will take some time and do not restart the ${mariadb._} container until initialization is finished!`;
27
+
28
+ let databaseFinishedInitialization = false;
29
+ while (!databaseFinishedInitialization) {
30
+ const databaseOutput2 = await execAsyncSpawn(`docker logs ${mariadb.name}`);
31
+ if (databaseOutput2.includes('init process done.') && !databaseFinishedInitialization) {
32
+ databaseFinishedInitialization = true;
33
+ break;
34
+ }
35
+ await sleep(2000);
36
+ }
37
+ }
38
+
39
+ await sleep(2000);
40
+ }
41
+ },
42
+ options: {
43
+ bottomBar: 10
44
+ }
45
+ });
46
+
47
+ /**
48
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
49
+ */
50
+ const gettingDatabaseConnection = () => ({
51
+ title: 'Getting Database connection',
52
+ task: async (ctx, task) => {
53
+ const { config: { docker }, ports } = ctx;
54
+ const { mariadb } = docker.getContainers(ctx.ports);
55
+ let tries = 0;
56
+ const maxTries = 20;
57
+ const errors = [];
58
+
59
+ while (tries < maxTries) {
60
+ tries++;
61
+ try {
62
+ const connection = await mysql2.createConnection({
63
+ host: '127.0.0.1',
64
+ port: ports.mariadb,
65
+ user: defaultMagentoUser.user,
66
+ password: defaultMagentoUser.password,
67
+ database: 'magento'
68
+ });
69
+
70
+ ctx.databaseConnection = connection;
71
+ break;
72
+ } catch (e) {
73
+ errors.push(e);
74
+ }
75
+ await sleep(1000);
76
+ }
77
+
78
+ if (tries === maxTries) {
79
+ throw new UnknownError(`Unable to connect to ${ mariadb._ } server. Check your server configuration!\n\n${ errors.join(' ') }`);
80
+ }
81
+
82
+ task.title = `${ mariadb._ } server connected!`;
83
+ }
84
+ });
85
+
86
+ /**
87
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
88
+ */
89
+ const terminatingExistingConnection = () => ({
90
+ title: 'Terminating existing Database connection',
91
+ skip: (ctx) => !ctx.databaseConnection,
92
+ task: (ctx) => {
93
+ ctx.databaseConnection.destroy();
94
+ }
95
+ });
96
+
97
+ /**
98
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
99
+ */
100
+ const connectToDatabase = () => ({
101
+ title: 'Connecting to Database server',
102
+ skip: (ctx) => ctx.skipSetup,
103
+ task: (ctx, task) => task.newListr([
104
+ waitForDatabaseInitialization(),
105
+ createMagentoDatabase(),
106
+ createMagentoUser(),
107
+ terminatingExistingConnection(),
108
+ gettingDatabaseConnection()
109
+ ], {
110
+ concurrent: false,
111
+ rendererOptions: {
112
+ collapse: true
113
+ }
114
+ }),
115
+ options: {
116
+ bottomBar: 10
117
+ }
118
+ });
119
+
120
+ module.exports = connectToDatabase;
@@ -0,0 +1,21 @@
1
+ const { containerApi } = require('../docker/containers');
2
+
3
+ /**
4
+ * Will create database 'magento' in MariaDB if it does not exist for some reason
5
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
6
+ */
7
+ const createMagentoDatabase = () => ({
8
+ title: 'Creating Magento database',
9
+ task: async (ctx, task) => {
10
+ const { mariadb } = ctx.config.docker.getContainers();
11
+ task.title = `Creating Magento database in ${ mariadb._ }`;
12
+ await containerApi.exec(
13
+ `mysql -uroot -p${ mariadb.env.MARIADB_ROOT_PASSWORD } -h 127.0.0.1 -e "CREATE DATABASE IF NOT EXISTS magento;"`,
14
+ mariadb.name
15
+ );
16
+ }
17
+ });
18
+
19
+ module.exports = {
20
+ createMagentoDatabase
21
+ };
@@ -0,0 +1,50 @@
1
+ const mysql2 = require('mysql2/promise');
2
+ const defaultMagentoUser = require('./default-magento-user');
3
+
4
+ /**
5
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
6
+ */
7
+ const createMagentoUser = () => ({
8
+ title: 'Creating Magento user',
9
+ task: async (ctx, task) => {
10
+ const { mariadb } = ctx.config.docker.getContainers();
11
+ const connection = await mysql2.createConnection({
12
+ host: '127.0.0.1',
13
+ port: ctx.ports.mariadb,
14
+ user: 'root',
15
+ password: mariadb.env.MARIADB_ROOT_PASSWORD
16
+ });
17
+
18
+ const result = await connection.query('select Host, User from mysql.user;');
19
+
20
+ if (result.length === 0) {
21
+ task.skip();
22
+ return;
23
+ }
24
+
25
+ const [users] = result;
26
+
27
+ if (users.some((user) => user.User === defaultMagentoUser.user && user.Host === '%')) {
28
+ task.skip();
29
+ return;
30
+ }
31
+
32
+ if (users.some((user) => user.User === defaultMagentoUser.user)) {
33
+ const magentoUser = users.find((user) => user.User === defaultMagentoUser.user);
34
+
35
+ await connection.query(`DROP USER '${ magentoUser.User }'@'${ magentoUser.Host }'`);
36
+ }
37
+
38
+ await connection.query(
39
+ `CREATE USER '${ defaultMagentoUser.user }'@'${ defaultMagentoUser.host }' IDENTIFIED BY '${ defaultMagentoUser.password }';`
40
+ );
41
+ await connection.query(`GRANT ALL PRIVILEGES ON *.* TO '${ defaultMagentoUser.user }'@'${ defaultMagentoUser.host }' WITH GRANT OPTION;`);
42
+ await connection.query('FLUSH PRIVILEGES;');
43
+
44
+ await connection.destroy();
45
+ }
46
+ });
47
+
48
+ module.exports = {
49
+ createMagentoUser
50
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ defaultMagentoDatabase: 'magento'
3
+ };
@@ -0,0 +1,7 @@
1
+ const defaultMagentoUser = {
2
+ user: 'magento',
3
+ password: 'magento',
4
+ host: '%'
5
+ };
6
+
7
+ module.exports = defaultMagentoUser;
@@ -6,9 +6,9 @@ const { isTableExists } = require('../../util/database');
6
6
  const dumpThemeConfig = () => ({
7
7
  title: 'Dumping themes and theme configuration',
8
8
  task: async (ctx, task) => {
9
- const { mysqlConnection } = ctx;
9
+ const { databaseConnection } = ctx;
10
10
  if (await isTableExists('magento', 'theme', ctx)) {
11
- const [themes] = await mysqlConnection.query('select * from theme;');
11
+ const [themes] = await databaseConnection.query('select * from theme;');
12
12
  if (themes.length === 0) {
13
13
  ctx.themeDump = {
14
14
  themes: [],
@@ -17,7 +17,7 @@ const dumpThemeConfig = () => ({
17
17
  }
18
18
 
19
19
  if (await isTableExists('magento', 'core_config_data', ctx)) {
20
- const [themeIdConfig] = await mysqlConnection.query('select * from core_config_data where path = \'design/theme/theme_id\';');
20
+ const [themeIdConfig] = await databaseConnection.query('select * from core_config_data where path = \'design/theme/theme_id\';');
21
21
  if (themeIdConfig.length !== 0) {
22
22
  ctx.themeDump = {
23
23
  themes,
@@ -8,14 +8,14 @@ const varnishConfigSetup = require('../magento/setup-magento/varnish-config');
8
8
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
9
9
  */
10
10
  const enableForeignKeyCheck = () => ({
11
- task: ({ mysqlConnection }) => mysqlConnection.query('SET FOREIGN_KEY_CHECKS = 0;')
11
+ task: ({ databaseConnection }) => databaseConnection.query('SET FOREIGN_KEY_CHECKS = 0;')
12
12
  });
13
13
 
14
14
  /**
15
15
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
16
16
  */
17
17
  const disableForeignKeyCheck = () => ({
18
- task: ({ mysqlConnection }) => mysqlConnection.query('SET FOREIGN_KEY_CHECKS = 1;')
18
+ task: ({ databaseConnection }) => databaseConnection.query('SET FOREIGN_KEY_CHECKS = 1;')
19
19
  });
20
20
 
21
21
  /**
@@ -4,7 +4,8 @@ const KnownError = require('../../errors/known-error');
4
4
  const UnknownError = require('../../errors/unknown-error');
5
5
  const { execAsyncSpawn, execCommandTask } = require('../../util/exec-async-command');
6
6
  const pathExists = require('../../util/path-exists');
7
- const connectToMySQL = require('./connect-to-mysql');
7
+ const connectToDatabase = require('./connect-to-database');
8
+ const defaultMagentoUser = require('./default-magento-user');
8
9
 
9
10
  /**
10
11
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -13,10 +14,10 @@ const copyDatabaseDumpIntoContainer = () => ({
13
14
  title: 'Copying database dump into container',
14
15
  task: async (ctx, task) => {
15
16
  const { config: { docker }, ports } = ctx;
16
- const { mysql } = docker.getContainers(ports);
17
+ const { mariadb } = docker.getContainers(ports);
17
18
 
18
19
  return task.newListr(
19
- execCommandTask(`docker cp ${ctx.importDb} ${mysql.name}:/dump.sql`, {
20
+ execCommandTask(`docker cp ${ctx.importDb} ${mariadb.name}:/dump.sql`, {
20
21
  logOutput: true
21
22
  })
22
23
  );
@@ -29,10 +30,10 @@ const copyDatabaseDumpIntoContainer = () => ({
29
30
  const runSetGlobalLogBinTrustFunctionCreatorsCommand = () => ({
30
31
  task: async (ctx, task) => {
31
32
  const { config: { docker }, ports } = ctx;
32
- const { mysql } = docker.getContainers(ports);
33
+ const { mariadb } = docker.getContainers(ports);
33
34
 
34
35
  return task.newListr(
35
- execCommandTask(`docker exec ${mysql.name} bash -c 'mysql -uroot -p${mysql.env.MYSQL_ROOT_PASSWORD} -e "SET GLOBAL log_bin_trust_function_creators = 1;"'`)
36
+ execCommandTask(`docker exec ${mariadb.name} bash -c 'mysql -uroot -p${mariadb.env.MARIADB_ROOT_PASSWORD} -e "SET GLOBAL log_bin_trust_function_creators = 1;"'`)
36
37
  );
37
38
  }
38
39
  });
@@ -63,8 +64,8 @@ Note that you will lose your existing database!`,
63
64
  });
64
65
 
65
66
  if (deleteDatabaseMagentoChoice === 'delete') {
66
- await ctx.mysqlConnection.query('DROP DATABASE IF EXISTS magento;');
67
- await ctx.mysqlConnection.query('CREATE DATABASE magento;');
67
+ await ctx.databaseConnection.query('DROP DATABASE IF EXISTS magento;');
68
+ await ctx.databaseConnection.query('CREATE DATABASE magento;');
68
69
  return;
69
70
  }
70
71
  task.skip();
@@ -77,28 +78,28 @@ Note that you will lose your existing database!`,
77
78
  const executeImportDumpSQL = () => ({
78
79
  task: async (ctx, task) => {
79
80
  const { config: { docker }, ports } = ctx;
80
- const { mysql } = docker.getContainers(ports);
81
+ const { mariadb } = docker.getContainers(ports);
81
82
 
82
- const userCredentialsForMySQLCLI = await task.prompt({
83
+ const userCredentialsForMariaDBCLI = await task.prompt({
83
84
  type: 'Select',
84
- message: 'Which user do you want to use to import db in MySQL client?',
85
+ message: `Which user do you want to use to import db in ${ mariadb._ } client?`,
85
86
  choices: [
86
87
  {
87
- name: `--user=root --password=${mysql.env.MYSQL_ROOT_PASSWORD}`,
88
+ name: `--user=root --password=${mariadb.env.MARIADB_ROOT_PASSWORD}`,
88
89
  message: `root (${logger.style.command('Probably safest option')})`
89
90
  },
90
91
  {
91
- name: `--user=${mysql.env.MYSQL_USER} --password=${mysql.env.MYSQL_PASSWORD}`,
92
- message: `${mysql.env.MYSQL_USER}`
92
+ name: `--user=${defaultMagentoUser.user} --password=${defaultMagentoUser.password}`,
93
+ message: `${defaultMagentoUser.user}`
93
94
  }
94
95
  ]
95
96
  });
96
97
 
97
- const importCommand = `docker exec ${mysql.name} bash -c "mysql ${userCredentialsForMySQLCLI} magento < ./dump.sql"`;
98
+ const importCommand = `docker exec ${mariadb.name} bash -c "mysql ${userCredentialsForMariaDBCLI} magento < ./dump.sql"`;
98
99
 
99
100
  const startImportTime = Date.now();
100
101
  const tickInterval = setInterval(() => {
101
- task.title = `Importing Database Dump To MySQL, ${Math.floor((Date.now() - startImportTime) / 1000)}s in progress...`;
102
+ task.title = `Importing Database Dump To ${ mariadb._ }, ${Math.floor((Date.now() - startImportTime) / 1000)}s in progress...`;
102
103
  }, 1000);
103
104
 
104
105
  try {
@@ -135,7 +136,7 @@ ${logger.style.command('sed -i \'s/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g\' dum
135
136
 
136
137
  if (confirmFixingCollation === 'yes') {
137
138
  task.output = 'Running fix command...';
138
- await execAsyncSpawn(`docker exec ${mysql.name} bash -c "sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' dump.sql"`);
139
+ await execAsyncSpawn(`docker exec ${mariadb.name} bash -c "sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g' dump.sql"`);
139
140
 
140
141
  task.output = 'Trying to import dump again...';
141
142
  try {
@@ -175,8 +176,8 @@ You can try replacing all occurrences of ${logger.style.misc('utf8mb4_0900_ai_ci
175
176
  /**
176
177
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
177
178
  */
178
- const importDumpToMySQL = () => ({
179
- title: 'Importing Database Dump To MySQL',
179
+ const importDumpToDatabase = () => ({
180
+ title: 'Importing Database Dump',
180
181
  task: async (ctx, task) => {
181
182
  if (!await pathExists(ctx.importDb)) {
182
183
  throw new KnownError(`Dump file at ${ctx.importDb} does not exist. Please provide correct relative path to the file`);
@@ -187,7 +188,7 @@ const importDumpToMySQL = () => ({
187
188
  deleteDatabaseBeforeImportingDumpPrompt(),
188
189
  runSetGlobalLogBinTrustFunctionCreatorsCommand(),
189
190
  executeImportDumpSQL(),
190
- connectToMySQL(),
191
+ connectToDatabase(),
191
192
  {
192
193
  task: () => {
193
194
  task.title = 'Database imported!';
@@ -201,4 +202,4 @@ const importDumpToMySQL = () => ({
201
202
  }
202
203
  });
203
204
 
204
- module.exports = importDumpToMySQL;
205
+ module.exports = importDumpToDatabase;
@@ -1,4 +1,4 @@
1
- const mysqlDumpCommandWithOptions = [
1
+ const databaseDumpCommandWithOptions = [
2
2
  'mysqldump',
3
3
  'magento',
4
4
  '--skip-lock-tables',
@@ -9,4 +9,4 @@ const mysqlDumpCommandWithOptions = [
9
9
  '--no-tablespaces'
10
10
  ];
11
11
 
12
- module.exports = mysqlDumpCommandWithOptions;
12
+ module.exports = databaseDumpCommandWithOptions;
@@ -1,7 +1,7 @@
1
1
  const mergeFiles = require('merge-files');
2
2
  const { orderTables, customerTables } = require('../../magento-tables');
3
3
  const { execAsyncSpawn } = require('../../../../util/exec-async-command');
4
- const mysqlDumpCommandWithOptions = require('./mysqldump-command');
4
+ const databaseDumpCommandWithOptions = require('./database-dump-command');
5
5
 
6
6
  /**
7
7
  * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext & { ssh: import('node-ssh').NodeSSH }>}
@@ -25,7 +25,7 @@ const readymageSSH = () => ({
25
25
  */
26
26
  await ssh.execCommand(
27
27
  [
28
- ...mysqlDumpCommandWithOptions,
28
+ ...databaseDumpCommandWithOptions,
29
29
  ...[...orderTables, ...customerTables].map((table) => `--ignore-table=magento.${table}`),
30
30
  '--result-file=dump-0.sql'
31
31
  ].join(' ')
@@ -33,7 +33,7 @@ const readymageSSH = () => ({
33
33
 
34
34
  await ssh.execCommand(
35
35
  [
36
- ...mysqlDumpCommandWithOptions,
36
+ ...databaseDumpCommandWithOptions,
37
37
  '--no-data',
38
38
  '--result-file=dump-1.sql',
39
39
  ...[...orderTables, ...customerTables]
@@ -41,7 +41,7 @@ const readymageSSH = () => ({
41
41
  );
42
42
  } else {
43
43
  task.output = 'Making remote database dump file with customers data...';
44
- await ssh.execCommand([...mysqlDumpCommandWithOptions, '--result-file=dump.sql'].join(' '));
44
+ await ssh.execCommand([...databaseDumpCommandWithOptions, '--result-file=dump.sql'].join(' '));
45
45
  }
46
46
 
47
47
  if (!noCompress) {
@@ -1,7 +1,7 @@
1
1
  const mergeFiles = require('merge-files');
2
2
  const { orderTables, customerTables } = require('../../magento-tables');
3
3
  const { execAsyncSpawn } = require('../../../../util/exec-async-command');
4
- const mysqlDumpCommandWithOptions = require('./mysqldump-command');
4
+ const databaseDumpCommandWithOptions = require('./database-dump-command');
5
5
  const KnownError = require('../../../../errors/known-error');
6
6
  /**
7
7
  * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext & { ssh: import('node-ssh').NodeSSH }>}
@@ -27,7 +27,7 @@ Do not enter "--result-file" option, we need to control that part.
27
27
 
28
28
  (documentation reference available here: https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html)
29
29
  `,
30
- initial: mysqlDumpCommandWithOptions.join(' ')
30
+ initial: databaseDumpCommandWithOptions.join(' ')
31
31
  });
32
32
 
33
33
  if (dumpCommand.includes('--result-file')) {
@@ -1,6 +1,6 @@
1
1
  module.exports = {
2
- connectToMySQL: require('./connect-to-mysql'),
3
- importDumpToMySQL: require('./import-dump-to-mysql'),
2
+ connectToDatabase: require('./connect-to-database'),
3
+ importDumpToDatabase: require('./import-dump-to-database'),
4
4
  fixDB: require('./fix-db'),
5
5
  dumpThemeConfig: require('./dump-theme-config'),
6
6
  restoreThemeConfig: require('./restore-theme-config')
File without changes
@@ -6,7 +6,7 @@ const { updateTableValues } = require('../../util/database');
6
6
  const restoreThemeConfig = () => ({
7
7
  title: 'Restoring themes and theme configuration',
8
8
  task: async (ctx, task) => {
9
- const { themeDump, mysqlConnection } = ctx;
9
+ const { themeDump, databaseConnection } = ctx;
10
10
 
11
11
  const { themeIdConfig, themes } = themeDump;
12
12
 
@@ -22,7 +22,7 @@ const restoreThemeConfig = () => ({
22
22
  path: themeIdConfig.path,
23
23
  value: themeIdConfig.value
24
24
  }
25
- ], { mysqlConnection, task });
25
+ ], { databaseConnection, task });
26
26
  }
27
27
 
28
28
  if (themes.length === 0) {
@@ -31,10 +31,10 @@ const restoreThemeConfig = () => ({
31
31
 
32
32
  // restore themes
33
33
  const themeKeys = Object.keys(themes[0]);
34
- await mysqlConnection.query('delete from theme;');
34
+ await databaseConnection.query('delete from theme;');
35
35
 
36
36
  for (const theme of themes) {
37
- await mysqlConnection.query(`
37
+ await databaseConnection.query(`
38
38
  insert into theme (${themeKeys.join(', ')})
39
39
  values (${themeKeys.map(() => '?').join(', ')})
40
40
  `, Object.values(theme));
@@ -1,7 +1,6 @@
1
1
  import { ExecAsyncSpawnOptions } from '../../util/exec-async-command';
2
2
 
3
3
  export interface DockerVersionOptions<T extends boolean = false> {
4
- format?: string
5
4
  format?: string
6
5
  formatToJSON?: T
7
6
  }
@@ -69,3 +68,28 @@ export function version(
69
68
  options: DockerVersionOptions<true>,
70
69
  execOptions?: ExecAsyncSpawnOptions<false>
71
70
  ): Promise<DockerVersionResult>
71
+
72
+ export interface DockerContextOptions<T extends boolean = false> {
73
+ format?: string
74
+ formatToJSON?: T
75
+ }
76
+
77
+ export interface DockerContextResult {
78
+ Current: boolean
79
+ Description: string
80
+ DockerEndpoint: string
81
+ KubernetesEndpoint: string
82
+ ContextType: string
83
+ Name: string
84
+ StackOrchestrator: string
85
+ }
86
+
87
+ export function context(
88
+ options: DockerContextOptions,
89
+ execOptions?: ExecAsyncSpawnOptions<false>
90
+ ): Promise<string>
91
+
92
+ export function context(
93
+ options: DockerContextOptions<true>,
94
+ execOptions?: ExecAsyncSpawnOptions<false>
95
+ ): Promise<DockerContextResult[]>
@@ -25,6 +25,36 @@ const version = async (options, execOptions = {}) => {
25
25
  return execAsyncSpawn(`docker version ${args}`, execOptions);
26
26
  };
27
27
 
28
+ /**
29
+ * @param {import('./api').DockerContextOptions} options
30
+ * @param {import('../../util/exec-async-command').ExecAsyncSpawnOptions} execOptions
31
+ */
32
+ const context = async (options, execOptions = {}) => {
33
+ const {
34
+ format,
35
+ formatToJSON
36
+ } = options;
37
+
38
+ const formatArg = !formatToJSON && format
39
+ ? `--format=${format}`
40
+ : formatToJSON && '--format=\'{{json .}}\'';
41
+ const args = [
42
+ formatArg
43
+ ].filter(Boolean).join(' ');
44
+
45
+ if (formatToJSON) {
46
+ const result = await execAsyncSpawn(`docker context ls ${args}`, execOptions);
47
+ if (result.startsWith('[')) {
48
+ return JSON.parse(result);
49
+ }
50
+
51
+ return JSON.parse(`[${result.split('\n').join(', ')}]`);
52
+ }
53
+
54
+ return execAsyncSpawn(`docker context ls ${args}`, execOptions);
55
+ };
56
+
28
57
  module.exports = {
29
- version
58
+ version,
59
+ context
30
60
  };
@@ -69,6 +69,8 @@ export interface ContainerRunOptions {
69
69
  * Run container in background and print container ID
70
70
  */
71
71
  detach?: boolean
72
+
73
+ tty?: boolean
72
74
  /**
73
75
  * Publish or expose port [docs](https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose)
74
76
  */
@@ -126,3 +128,19 @@ export interface ContainerRunOptions {
126
128
  }
127
129
 
128
130
  export function run(containerOptions: ContainerRunOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<false>
131
+
132
+ export function runCommand(options: ContainerRunOptions): string[]
133
+
134
+ export interface ContainerLogsOptions<T = never> {
135
+ name: string
136
+ details?: boolean
137
+ follow?: boolean
138
+ since?: string
139
+ tail?: string
140
+ timestamps?: boolean
141
+ until?: string
142
+ parser?: (line: string) => T
143
+ }
144
+
145
+ export function logs(options?: ContainerLogsOptions, execOptions?: ExecAsyncSpawnOptions<false>): Promise<string>
146
+ export function logs<T>(options?: ContainerLogsOptions<T>, execOptions?: ExecAsyncSpawnOptions<false>): Promise<T[]>