@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
@@ -10,9 +10,13 @@ const { containerApi } = require('../docker/containers');
10
10
  const runPHPContainerCommand = async (ctx, command, options = {}) => {
11
11
  const { php } = ctx.config.docker.getContainers(ctx.ports);
12
12
 
13
- const containers = await containerApi.ls({ formatToJSON: true, all: true });
13
+ const containers = await containerApi.ls({
14
+ formatToJSON: true,
15
+ all: true,
16
+ filter: `name=${php.name}`
17
+ });
14
18
 
15
- if (containers.some((c) => c.Names === php.name)) {
19
+ if (containers.length > 0) {
16
20
  return execPHPContainerCommand(ctx, command, options);
17
21
  }
18
22
 
@@ -25,7 +29,7 @@ const runPHPContainerCommand = async (ctx, command, options = {}) => {
25
29
  },
26
30
  options.useXDebugContainer
27
31
  ? {
28
- image: `${ php.image }.xdebug`
32
+ image: php.debugImage
29
33
  }
30
34
  : {},
31
35
  {
@@ -1,4 +1,5 @@
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');
@@ -18,11 +19,10 @@ const updateEnvPHP = () => ({
18
19
  return;
19
20
  }
20
21
 
22
+ const { isDockerDesktop, platform } = ctx;
21
23
  const { php } = ctx.config.docker.getContainers(ctx.ports);
22
24
 
23
- const isLinux = ctx.platform === 'linux';
24
- const isNativeLinux = isLinux && !ctx.isWsl;
25
- const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
25
+ const hostMachine = !isDockerDesktop ? '127.0.0.1' : 'host.docker.internal';
26
26
 
27
27
  const useVarnish = (!ctx.debug && ctx.config.overridenConfiguration.configuration.varnish.enabled) ? '1' : '';
28
28
  const varnishHost = hostMachine;
@@ -48,8 +48,8 @@ const updateEnvPHP = () => ({
48
48
  if (
49
49
  persistedQueryConfig
50
50
  && persistedQueryConfig.redis
51
- && persistedQueryConfig.redis.port === `${ ctx.ports.redis }`
52
- && persistedQueryConfig.redis.host === 'localhost'
51
+ && (persistedQueryConfig.redis.port !== `${ ctx.ports.redis }`
52
+ || persistedQueryConfig.redis.host === hostMachine)
53
53
  ) {
54
54
  SETUP_PQ = '';
55
55
  return;
@@ -76,7 +76,8 @@ const updateEnvPHP = () => ({
76
76
  ],
77
77
  image: php.image,
78
78
  detach: false,
79
- rm: true
79
+ rm: true,
80
+ user: platform === 'linux' ? `${os.userInfo().uid}:${os.userInfo().gid}` : ''
80
81
  });
81
82
 
82
83
  task.output = result;
@@ -85,18 +85,12 @@ class EnvUpdater
85
85
  $hostMachine = '127.0.0.1';
86
86
  }
87
87
 
88
- // update mysql config
88
+ // update mariadb config
89
89
  if (isset($this->config["db"]["connection"]["default"])) {
90
90
  $conn = &$this->config["db"]["connection"]["default"];
91
- $mysqlHost = $hostMachine . ":" . $this->portConfig["mysql"];
92
- if (
93
- isset($conn["engine"]) &&
94
- isset($conn["host"]) &&
95
- $conn["engine"] === "innodb" &&
96
- $conn["host"] !== $mysqlHost
97
- ) {
98
- $conn["host"] = $mysqlHost;
99
- }
91
+ $mysqlHost = $hostMachine . ":" . $this->portConfig["mariadb"];
92
+
93
+ $conn["host"] = $mysqlHost;
100
94
  }
101
95
 
102
96
  // update redis session config
@@ -132,8 +126,14 @@ class EnvUpdater
132
126
  $cacheConfig = &$this->config["cache"];
133
127
  $redisPort = getenv("REDIS_PORT");
134
128
 
135
- if (isset($cacheConfig) && isset($cacheConfig["persisted-query"]) && isset($cacheConfig["persisted-query"]["redis"]) && $cacheConfig["persisted-query"]["redis"]["port"] != $redisPort) {
136
- $cacheConfig["persisted-query"]["redis"]["port"] = $redisPort;
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
+ }
137
137
  } else {
138
138
  if (!isset($cacheConfig)) {
139
139
  $this->config["cache"] = [];
@@ -96,9 +96,9 @@ ${ logger.style.misc('Password') } (${ logger.style.misc('Private key') }):`,
96
96
  };
97
97
 
98
98
  const authJsonContent = JSON.stringify(authContent, null, 4);
99
- const authEnvContent = `export COMPOSER_AUTH='${JSON.stringify(authContent)}'`;
99
+ const authEnvContent = `export COMPOSER_AUTH='${JSON.stringify(authContent, null, 0)}'`;
100
100
 
101
- process.env.COMPOSER_AUTH = authJsonContent;
101
+ process.env.COMPOSER_AUTH = JSON.stringify(JSON.parse(authJsonContent), null, 0);
102
102
 
103
103
  if (configureLocation === 'auth.json') {
104
104
  await fs.promises.writeFile(authJsonPath, authJsonContent, 'utf-8');
@@ -175,7 +175,11 @@ Would you like to load them now?`
175
175
 
176
176
  if (loadCredentialsFrom) {
177
177
  const credentialsLine = lines.find((line) => line.startsWith('export COMPOSER_AUTH='));
178
- process.env.COMPOSER_AUTH = credentialsLine.replace('export COMPOSER_AUTH=', '').replace(/'/ig, '').trim();
178
+ process.env.COMPOSER_AUTH = JSON.stringify(
179
+ JSON.parse(credentialsLine.replace('export COMPOSER_AUTH=', '').replace(/'/ig, '').trim()),
180
+ null,
181
+ 0
182
+ );
179
183
  problems.delete(MISSING_COMPOSER_AUTH_ENV);
180
184
  }
181
185
  }
@@ -0,0 +1,88 @@
1
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
+ const os = require('os');
3
+ const { cmaGlobalConfig } = require('../../../config/cma-config');
4
+ const { getCachedPorts } = require('../../../config/get-port-config');
5
+ const { getSystemConfigTask } = require('../../../config/system-config');
6
+ const UnknownError = require('../../../errors/unknown-error');
7
+ const { execCommandTask } = require('../../../util/exec-async-command');
8
+ const createCacheFolder = require('../../cache/create-cache-folder');
9
+ const { dockerApi } = require('../../docker');
10
+ const { stopContainers } = require('../../docker/containers');
11
+ const { getDockerEngineAndDesktopServiceStatus } = require('./running-status');
12
+ const getMagentoVersionConfig = require('../../../config/get-magento-version-config');
13
+ const checkConfigurationFile = require('../../../config/check-configuration-file');
14
+ const getProjectConfiguration = require('../../../config/get-project-configuration');
15
+ const getDockerVersion = require('./version');
16
+
17
+ const USE_DEFAULT_DOCKER_DESKTOP_CONTEXT_ANSWER = 'useDefaultDockerDesktopContext';
18
+
19
+ /**
20
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
21
+ */
22
+ const checkDockerDesktopContext = () => ({
23
+ task: async (ctx, task) => {
24
+ if (os.platform() !== 'linux' || !ctx.isDockerDesktop) {
25
+ task.skip();
26
+ return;
27
+ }
28
+
29
+ task.title = 'Checking contexts for Docker Desktop';
30
+
31
+ const contexts = await dockerApi.context({ formatToJSON: true });
32
+ const currentlyUsedContext = contexts.find((c) => c.Current);
33
+
34
+ if (!currentlyUsedContext) {
35
+ throw new UnknownError('We haven\'t found contexts in Docker...');
36
+ }
37
+
38
+ const { engine } = await getDockerEngineAndDesktopServiceStatus();
39
+
40
+ if (currentlyUsedContext.Name !== 'default' && engine.exists) {
41
+ if (cmaGlobalConfig.get(USE_DEFAULT_DOCKER_DESKTOP_CONTEXT_ANSWER) === false) {
42
+ task.skip();
43
+ return;
44
+ }
45
+
46
+ const confirmContextChange = await task.prompt({
47
+ type: 'Select',
48
+ message: `Do you want to change current Docker Desktop context (${logger.style.code(currentlyUsedContext.Name)}) to ${logger.style.code('default')}?`,
49
+ choices: [
50
+ {
51
+ name: 'yes',
52
+ message: 'Yes'
53
+ },
54
+ {
55
+ name: 'no',
56
+ message: 'No, I don\'t know what this means, but you can ask again on next start.'
57
+ },
58
+ {
59
+ name: 'skip',
60
+ // eslint-disable-next-line max-len
61
+ message: 'I do know what this means and I DON\'T want to change context for Docker. Also, save this answer to never ask again.'
62
+ }
63
+ ]
64
+ });
65
+
66
+ if (confirmContextChange === 'skip') {
67
+ cmaGlobalConfig.set(USE_DEFAULT_DOCKER_DESKTOP_CONTEXT_ANSWER, false);
68
+ task.skip();
69
+ }
70
+
71
+ if (confirmContextChange === 'yes') {
72
+ return task.newListr([
73
+ getMagentoVersionConfig(),
74
+ checkConfigurationFile(),
75
+ getProjectConfiguration(),
76
+ createCacheFolder(),
77
+ getSystemConfigTask(),
78
+ getCachedPorts(),
79
+ stopContainers(),
80
+ execCommandTask('docker context use default'),
81
+ getDockerVersion()
82
+ ]);
83
+ }
84
+ }
85
+ }
86
+ });
87
+
88
+ module.exports = checkDockerDesktopContext;
@@ -1,14 +1,18 @@
1
1
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
+ const { cmaGlobalConfig } = require('../../../config/cma-config');
2
3
  const KnownError = require('../../../errors/known-error');
3
4
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
4
5
  const openBrowser = require('../../../util/open-browser');
5
- const installDocker = require('./install');
6
+ const checkDockerDesktopContext = require('./context');
7
+ const { installDockerEngine } = require('./install');
6
8
  const installDockerOnMac = require('./install-on-mac');
7
9
  const { checkDockerPerformance } = require('./performance');
8
10
  const { checkDockerSocketPermissions } = require('./permissions');
9
- const checkDockerStatus = require('./running-status');
11
+ const { checkDockerStatus, getDockerEngineAndDesktopServiceStatus } = require('./running-status');
10
12
  const getDockerVersion = require('./version');
11
13
 
14
+ const USE_DOCKER_ENGINE_WITH_DOCKER_DESKTOP_ANSWER = 'useDockerEngineWithDockerDesktop';
15
+
12
16
  const setVersionInContextTask = (task) => ({
13
17
  task: (ctx) => {
14
18
  if (ctx.platform === 'darwin' && ctx.dockerServerData && ctx.dockerServerData.Platform && ctx.dockerServerData.Platform.Name) {
@@ -19,32 +23,72 @@ const setVersionInContextTask = (task) => ({
19
23
  }
20
24
  });
21
25
 
22
- const dockerInstallPromptLinux = async (task) => {
23
- const automaticallyInstallDocker = await task.prompt({
24
- type: 'Confirm',
26
+ const dockerInstallPromptLinux = async (task, { skipPrompt = false } = {}) => {
27
+ const automaticallyInstallDocker = skipPrompt ? 'yes' : await task.prompt({
28
+ type: 'Select',
25
29
  message: `You don't have Docker installed!
26
30
  Do you want to install it automatically?
27
- NOTE: After installation it's recommended to log out and log back in so your group membership is re-evaluated!`
31
+ `,
32
+ choices: [
33
+ {
34
+ name: 'yes',
35
+ message: 'Yes, I to install Docker automatically'
36
+ },
37
+ {
38
+ name: 'no',
39
+ message: 'No, I want to install Docker myself'
40
+ },
41
+ {
42
+ name: 'skip',
43
+ message: 'Skip installing Docker'
44
+ }
45
+ ]
28
46
  });
29
47
 
30
- if (automaticallyInstallDocker) {
48
+ if (automaticallyInstallDocker === 'yes') {
31
49
  return task.newListr([
32
- installDocker(),
50
+ installDockerEngine(),
51
+ checkDockerSocketPermissions(),
33
52
  getDockerVersion(),
34
53
  {
35
- task: (ctx) => {
54
+ task: async (ctx) => {
36
55
  task.title = `Using docker version ${ctx.dockerVersion}`;
37
56
 
57
+ const confirmLogOut = await task.prompt({
58
+ type: 'Select',
59
+ message: 'Docker installed successfully!\n',
60
+ choices: [
61
+ {
62
+ name: 'log-out',
63
+ message: `${logger.style.command('[Recommended]')} Now I will log out and log back it (or restart my system) to re-evaluate group membership`
64
+ },
65
+ {
66
+ name: 'skip',
67
+ message: 'Skip log out and proceed with installation'
68
+ }
69
+ ]
70
+ });
71
+
72
+ if (confirmLogOut === 'skip') {
73
+ return;
74
+ }
75
+
38
76
  throw new KnownError(
39
77
  `Docker is installed successfully!
40
- Please log out and log back to so your group membership is re-evaluated!
78
+ Please log out and log back in (or restart your system) so your group membership is re-evaluated!
41
79
  Learn more here: ${ logger.style.link('https://docs.docker.com/engine/install/linux-postinstall/') }`
42
80
  );
43
81
  }
44
- }
82
+ },
83
+ checkDockerStatus(),
84
+ checkDockerDesktopContext()
45
85
  ]);
46
86
  }
47
87
 
88
+ if (automaticallyInstallDocker === 'skip') {
89
+ return;
90
+ }
91
+
48
92
  throw new KnownError('Docker is not installed!');
49
93
  };
50
94
 
@@ -64,7 +108,8 @@ const dockerInstallPromptMacOS = async (task) => {
64
108
  const confirmationToInstallDocker = await task.prompt({
65
109
  type: 'Select',
66
110
  message: `You don't have Docker installed!
67
- Would you like to install it automatically using brew cask or you prefer to install it manually?`,
111
+ Would you like to install it automatically using brew cask or you prefer to install it manually?
112
+ `,
68
113
  choices: [
69
114
  {
70
115
  name: 'automatic',
@@ -80,6 +125,7 @@ Would you like to install it automatically using brew cask or you prefer to inst
80
125
  if (confirmationToInstallDocker === 'automatic') {
81
126
  return task.newListr([
82
127
  installDockerOnMac(),
128
+ checkDockerSocketPermissions(),
83
129
  checkDockerStatus(),
84
130
  getDockerVersion(),
85
131
  setVersionInContextTask(task)
@@ -106,24 +152,70 @@ const checkDocker = () => ({
106
152
  });
107
153
 
108
154
  if (code !== 0) {
109
- if (ctx.platform === 'linux' && !ctx.isWsl) {
110
- const result = await dockerInstallPromptLinux(task);
111
- if (result) {
112
- return result;
155
+ if (ctx.platform === 'linux') {
156
+ if (!ctx.isWsl) {
157
+ const { engine } = await getDockerEngineAndDesktopServiceStatus();
158
+ if (!engine.exists) {
159
+ const result = await dockerInstallPromptLinux(task);
160
+ if (result) {
161
+ return result;
162
+ }
163
+ }
164
+ } else if (ctx.isWsl) {
165
+ dockerInstallPromptWindows();
113
166
  }
114
- } else if (ctx.isWsl) {
115
- dockerInstallPromptWindows();
116
167
  } else {
117
168
  const result = await dockerInstallPromptMacOS(task);
118
169
  if (result) {
119
170
  return result;
120
171
  }
121
172
  }
173
+ } else if (ctx.platform === 'linux') {
174
+ const { engine, desktop } = await getDockerEngineAndDesktopServiceStatus();
175
+ if (!engine.exists
176
+ && desktop.exists
177
+ && cmaGlobalConfig.get(USE_DOCKER_ENGINE_WITH_DOCKER_DESKTOP_ANSWER) !== false
178
+ ) {
179
+ const confirmInstallingDockerEngine = await task.prompt({
180
+ type: 'Select',
181
+ message: `Looks like you have Docker Desktop installed on Linux system, but Docker Engine is not installed.
182
+ Do you want to install it and use it's context together with Docker Desktop?
183
+ `,
184
+ choices: [
185
+ {
186
+ name: 'yes',
187
+ message: 'Sure, if it means I will have less issues with my setup!'
188
+ },
189
+ {
190
+ name: 'no',
191
+ message: 'No. But you can ask me again later.'
192
+ },
193
+ {
194
+ name: 'skip',
195
+ message: 'No. And don\'t ask me again.'
196
+ }
197
+ ]
198
+ });
199
+
200
+ if (confirmInstallingDockerEngine === 'skip') {
201
+ cmaGlobalConfig.set(USE_DOCKER_ENGINE_WITH_DOCKER_DESKTOP_ANSWER, false);
202
+ } else if (confirmInstallingDockerEngine === 'yes') {
203
+ const result = await dockerInstallPromptLinux(task, {
204
+ skipPrompt: true
205
+ });
206
+
207
+ if (result) {
208
+ return result;
209
+ }
210
+ }
211
+ }
122
212
  }
123
213
 
124
214
  return task.newListr([
215
+ checkDockerSocketPermissions(),
125
216
  checkDockerStatus(),
126
217
  getDockerVersion(),
218
+ checkDockerDesktopContext(),
127
219
  setVersionInContextTask(task)
128
220
  ]);
129
221
  }
@@ -134,7 +226,6 @@ const checkDocker = () => ({
134
226
  */
135
227
  module.exports = () => ({
136
228
  task: (ctx, task) => task.newListr([
137
- checkDockerSocketPermissions(),
138
229
  checkDocker(),
139
230
  checkDockerPerformance()
140
231
  ], {
@@ -17,8 +17,8 @@ const postInstallSteps = [
17
17
  /**
18
18
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
19
19
  */
20
- const installDocker = () => ({
21
- title: 'Installing Docker',
20
+ const installDockerEngine = () => ({
21
+ title: 'Installing Docker Engine',
22
22
  task: async (ctx, task) => {
23
23
  const distro = await osPlatform();
24
24
  switch (distro) {
@@ -32,12 +32,21 @@ const installDocker = () => ({
32
32
  ...postInstallSteps
33
33
  ]);
34
34
  }
35
- case 'Fedora':
35
+ case 'Fedora': {
36
+ return task.newListr([
37
+ executeSudoCommand('sudo dnf -y install dnf-plugins-core'),
38
+ executeSudoCommand('sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo'),
39
+ executeSudoCommand('sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin'),
40
+ enableAndStartDockerCommand(),
41
+ ...postInstallSteps
42
+ ]);
43
+ }
36
44
  case 'CentOS': {
37
45
  return task.newListr([
38
- downloadDockerInstallScriptCommand(),
39
- runDockerInstallScriptCommand(),
40
- enableAndStartDockerCommand()
46
+ executeSudoCommand('sudo yum install -y yum-utils'),
47
+ executeSudoCommand('sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'),
48
+ executeSudoCommand('sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin'),
49
+ ...postInstallSteps
41
50
  ]);
42
51
  }
43
52
  case 'Ubuntu': {
@@ -53,7 +62,12 @@ const installDocker = () => ({
53
62
  Your distro ${distro} is not supported by automatic installation.`);
54
63
  }
55
64
  }
65
+ },
66
+ options: {
67
+ bottomBar: 10
56
68
  }
57
69
  });
58
70
 
59
- module.exports = installDocker;
71
+ module.exports = {
72
+ installDockerEngine
73
+ };
@@ -2,7 +2,7 @@ const os = require('os');
2
2
  const fs = require('fs');
3
3
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
4
  const pathExists = require('../../../util/path-exists');
5
- const { execCommandTask } = require('../../../util/exec-async-command');
5
+ const executeSudoCommand = require('../../../util/execute-sudo-command');
6
6
 
7
7
  const dockerSocketPath = '/var/run/docker.sock';
8
8
 
@@ -33,16 +33,7 @@ Otherwise installation will likely fail.`
33
33
  });
34
34
 
35
35
  if (confirmPrompt) {
36
- task.output = 'Enter your sudo password!';
37
- task.output = logger.style.command(`>[sudo] password for ${ os.userInfo().username }:`);
38
- return task.newListr(
39
- execCommandTask(fixCommand, {
40
- callback: (t) => {
41
- task.output = t;
42
- },
43
- pipeInput: true
44
- })
45
- );
36
+ return task.newListr(executeSudoCommand(fixCommand));
46
37
  }
47
38
  task.skip(`Permission issue detected in ${ logger.style.file(dockerSocketPath) } but user decided not to fix it.`);
48
39
  }
@@ -10,6 +10,41 @@ const getDockerVersion = () => execAsyncSpawn('docker version --format {{.Server
10
10
  withCode: true
11
11
  });
12
12
 
13
+ const getDockerEngineAndDesktopServiceStatus = async () => {
14
+ const dockerEngineService = systemctlControl('docker');
15
+ const dockerDesktopService = systemctlControl('docker-desktop', { user: true });
16
+ const [
17
+ dockerEngineServiceExists,
18
+ dockerDesktopServiceExists,
19
+ dockerEngineServiceIsRunning,
20
+ dockerDesktopServiceIsRunning,
21
+ dockerEngineServiceIsEnabled,
22
+ dockerDesktopServiceIsEnabled
23
+ ] = await Promise.all([
24
+ dockerEngineService.exists(),
25
+ dockerDesktopService.exists(),
26
+ dockerEngineService.isRunning(),
27
+ dockerDesktopService.isRunning(),
28
+ dockerEngineService.isEnabled(),
29
+ dockerDesktopService.isEnabled()
30
+ ]);
31
+
32
+ return {
33
+ engine: {
34
+ service: dockerEngineService,
35
+ exists: dockerEngineServiceExists,
36
+ isRunning: dockerEngineServiceIsRunning,
37
+ isEnabled: dockerEngineServiceIsEnabled
38
+ },
39
+ desktop: {
40
+ service: dockerDesktopService,
41
+ exists: dockerDesktopServiceExists,
42
+ isRunning: dockerDesktopServiceIsRunning,
43
+ isEnabled: dockerDesktopServiceIsEnabled
44
+ }
45
+ };
46
+ };
47
+
13
48
  /**
14
49
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
15
50
  */
@@ -81,39 +116,71 @@ Please open Docker Desktop application for Windows and make sure that Docker is
81
116
  const checkDockerStatusLinux = () => ({
82
117
  title: 'Checking Docker status on Linux',
83
118
  task: async (ctx, task) => {
84
- const dockerService = systemctlControl('docker');
119
+ const {
120
+ engine,
121
+ desktop
122
+ } = await getDockerEngineAndDesktopServiceStatus();
123
+
124
+ if (engine.exists) {
125
+ if (!engine.isEnabled && !engine.isRunning) {
126
+ const dockerStartConfirmation = await task.prompt({
127
+ type: 'Confirm',
128
+ message: `Looks like Docker Engine is not enabled and not running, would you like to enable and run it?
85
129
 
86
- const isRunning = await dockerService.isRunning();
87
- const isEnabled = await dockerService.isEnabled();
130
+ This action requires root privileges.`
131
+ });
132
+
133
+ if (dockerStartConfirmation) {
134
+ await engine.service.enableAndStart();
88
135
 
89
- if (!isEnabled && !isRunning) {
90
- const dockerStartConfirmation = await task.prompt({
91
- type: 'Confirm',
92
- message: `Looks like Docker is not enabled and not running, would you like to enable and run it?
136
+ return;
137
+ }
138
+ task.skip('User skipped running Docker');
139
+ } else if (!engine.isRunning) {
140
+ const dockerStartConfirmation = await task.prompt({
141
+ type: 'Confirm',
142
+ message: `Looks like Docker Engine is not running, would you like to run it?
93
143
 
94
- This action requires root privileges.`
95
- });
144
+ This action requires root privileges.`
145
+ });
96
146
 
97
- if (dockerStartConfirmation) {
98
- await dockerService.enableAndStart();
147
+ if (dockerStartConfirmation) {
148
+ await engine.service.start();
99
149
 
100
- return;
150
+ return;
151
+ }
152
+ task.skip('User skipped running Docker Engine');
101
153
  }
102
- task.skip('User skipped running Docker');
103
- } else if (!isRunning) {
104
- const dockerStartConfirmation = await task.prompt({
105
- type: 'Confirm',
106
- message: `Looks like Docker is not running, would you like to run it?
154
+ } else if (desktop.exists) {
155
+ if (!desktop.isEnabled && !desktop.isRunning) {
156
+ const dockerStartConfirmation = await task.prompt({
157
+ type: 'Confirm',
158
+ message: `Looks like Docker Desktop is not enabled and not running, would you like to enable and run it?
159
+
160
+ This action requires root privileges.`
161
+ });
162
+
163
+ if (dockerStartConfirmation) {
164
+ await desktop.service.enableAndStart();
165
+
166
+ return;
167
+ }
168
+ task.skip('User skipped running Docker');
169
+ } else if (!desktop.isRunning) {
170
+ const dockerStartConfirmation = await task.prompt({
171
+ type: 'Confirm',
172
+ message: `Looks like Docker Desktop is not running, would you like to run it?
107
173
 
108
- This action requires root privileges.`
109
- });
174
+ This action requires root privileges.`
175
+ });
110
176
 
111
- if (dockerStartConfirmation) {
112
- await dockerService.start();
177
+ if (dockerStartConfirmation) {
178
+ await desktop.service.start();
113
179
 
114
- return;
180
+ return;
181
+ }
182
+ task.skip('User skipped running Docker Desktop');
115
183
  }
116
- task.skip('User skipped running Docker');
117
184
  }
118
185
  }
119
186
  });
@@ -135,4 +202,7 @@ const checkDockerStatus = () => ({
135
202
  }
136
203
  });
137
204
 
138
- module.exports = checkDockerStatus;
205
+ module.exports = {
206
+ checkDockerStatus,
207
+ getDockerEngineAndDesktopServiceStatus
208
+ };
@@ -14,6 +14,7 @@ const getDockerVersion = () => ({
14
14
  ctx.dockerServerData = dockerVersion.Server;
15
15
  ctx.dockerClientData = dockerVersion.Client;
16
16
  ctx.dockerVersion = dockerVersion.Server.Version;
17
+ ctx.isDockerDesktop = dockerVersion.Server.Platform.Name.includes('Desktop');
17
18
  } else {
18
19
  throw new UnknownError(`Got unexpected result during Docker version retrieval!\n\n${ dockerVersion }`);
19
20
  }
@@ -19,8 +19,6 @@ const checkRequirements = () => ({
19
19
  checkDocker(),
20
20
  // check for Node.js version
21
21
  checkNodeVersion(),
22
- // check installed PHP version
23
- // checkPHPVersion(),
24
22
  // check for COMPOSER_AUTH or auth.json
25
23
  localAuthJson(),
26
24
  checkComposerCredentials()