@scandipwa/magento-scripts 1.14.0 → 1.14.1-alpha.10

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 (91) hide show
  1. package/index.js +13 -0
  2. package/lib/commands/cli.js +28 -1
  3. package/lib/commands/execute.js +2 -1
  4. package/lib/config/docker.js +85 -12
  5. package/lib/config/get-port-config.js +7 -2
  6. package/lib/config/port-config.js +3 -1
  7. package/lib/config/scandipwa-versions.js +2 -1
  8. package/lib/config/ssl-terminator/index.js +10 -0
  9. package/lib/config/templates/magentorc.template +3 -5
  10. package/lib/config/templates/nginx.template.conf +0 -14
  11. package/lib/config/templates/php-fpm.template.conf +1 -0
  12. package/lib/config/templates/php.template.ini +6 -4
  13. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  14. package/lib/config/templates/varnish.template.vcl +250 -0
  15. package/lib/config/varnish/varnish-6-0.js +11 -0
  16. package/lib/config/varnish/varnish-6-6.js +11 -0
  17. package/lib/config/varnish/varnish-7-0.js +11 -0
  18. package/lib/config/versions/magento-2.3.0.js +9 -1
  19. package/lib/config/versions/magento-2.3.1.js +9 -1
  20. package/lib/config/versions/magento-2.3.2-p2.js +9 -1
  21. package/lib/config/versions/magento-2.3.2.js +9 -1
  22. package/lib/config/versions/magento-2.3.3-p1.js +9 -1
  23. package/lib/config/versions/magento-2.3.3.js +9 -1
  24. package/lib/config/versions/magento-2.3.4-p2.js +9 -1
  25. package/lib/config/versions/magento-2.3.4.js +9 -1
  26. package/lib/config/versions/magento-2.3.5-p1.js +9 -1
  27. package/lib/config/versions/magento-2.3.5-p2.js +9 -1
  28. package/lib/config/versions/magento-2.3.5.js +9 -1
  29. package/lib/config/versions/magento-2.3.6-p1.js +9 -1
  30. package/lib/config/versions/magento-2.3.6.js +9 -1
  31. package/lib/config/versions/magento-2.3.7-p1.js +9 -1
  32. package/lib/config/versions/magento-2.3.7-p2.js +55 -0
  33. package/lib/config/versions/magento-2.3.7-p3.js +55 -0
  34. package/lib/config/versions/magento-2.3.7.js +9 -1
  35. package/lib/config/versions/magento-2.4.0-p1.js +9 -1
  36. package/lib/config/versions/magento-2.4.0.js +9 -1
  37. package/lib/config/versions/magento-2.4.1-p1.js +9 -1
  38. package/lib/config/versions/magento-2.4.1.js +9 -1
  39. package/lib/config/versions/magento-2.4.2-p1.js +9 -1
  40. package/lib/config/versions/magento-2.4.2-p2.js +9 -1
  41. package/lib/config/versions/magento-2.4.2.js +9 -1
  42. package/lib/config/versions/magento-2.4.3-p1.js +9 -1
  43. package/lib/config/versions/magento-2.4.3-p2.js +59 -0
  44. package/lib/config/versions/magento-2.4.3.js +9 -1
  45. package/lib/config/versions/magento-2.4.4.js +59 -0
  46. package/lib/tasks/cli/create-bashrc-config.js +5 -2
  47. package/lib/tasks/docker/containers.js +13 -8
  48. package/lib/tasks/docker/volumes.js +4 -4
  49. package/lib/tasks/file-system/create-nginx-config.js +7 -39
  50. package/lib/tasks/file-system/create-ssl-terminator-config.js +94 -0
  51. package/lib/tasks/file-system/create-varnish-config.js +74 -0
  52. package/lib/tasks/file-system/index.js +5 -1
  53. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  54. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  55. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  56. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  57. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  58. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  59. package/lib/tasks/magento/setup-magento/upgrade-magento.js +17 -3
  60. package/lib/tasks/magento/setup-magento/varnish-config.js +69 -0
  61. package/lib/tasks/mysql/fix-db.js +2 -2
  62. package/lib/tasks/php/index.js +1 -1
  63. package/lib/tasks/php/update-env-php.js +16 -1
  64. package/lib/tasks/php/update-env.php +56 -12
  65. package/lib/tasks/requirements/docker/index.js +2 -0
  66. package/lib/tasks/requirements/docker/install.js +11 -11
  67. package/lib/tasks/requirements/docker/running-status.js +137 -0
  68. package/lib/tasks/requirements/docker/version.js +2 -0
  69. package/lib/tasks/requirements/index.js +5 -5
  70. package/lib/tasks/requirements/php-version.js +3 -1
  71. package/lib/tasks/start.js +9 -10
  72. package/lib/tasks/status/index.js +25 -9
  73. package/lib/tasks/theme/build-theme.js +26 -8
  74. package/lib/tasks/theme/install-theme.js +16 -4
  75. package/lib/tasks/theme/link-theme.js +2 -2
  76. package/lib/tasks/theme/setup-persisted-query.js +3 -3
  77. package/lib/tasks/theme/setup-themes.js +3 -2
  78. package/lib/tasks/theme/symlink-theme.js +18 -3
  79. package/lib/util/config-file-validator.js +12 -1
  80. package/lib/util/config-php-json.js +19 -0
  81. package/lib/util/instance-metadata.js +9 -3
  82. package/lib/util/is-running-root.js +3 -0
  83. package/lib/util/match-filesystem.js +2 -1
  84. package/lib/util/php-task.js +6 -2
  85. package/lib/util/run-php.js +7 -1
  86. package/lib/util/systemctl.js +46 -0
  87. package/package.json +12 -2
  88. package/typings/context.d.ts +5 -1
  89. package/typings/index.d.ts +32 -1
  90. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  91. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
3
  const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
4
6
 
5
7
  module.exports = ({ templateDir } = {}) => ({
6
8
  magentoVersion: '2.4.1-p1',
@@ -18,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({
18
20
  libsodium,
19
21
  xdebug: {
20
22
  version: '3.1.2'
23
+ },
24
+ apcu: {},
25
+ opcache: {
26
+ extensionName: 'Zend OPcache'
21
27
  }
22
28
  }
23
29
  },
@@ -39,7 +45,9 @@ module.exports = ({ templateDir } = {}) => ({
39
45
  },
40
46
  composer: {
41
47
  version: '1'
42
- }
48
+ },
49
+ varnish: varnish66({ templateDir }),
50
+ sslTerminator: sslTerminator({ templateDir })
43
51
  },
44
52
  magento: defaultMagentoConfig,
45
53
  host: 'localhost',
@@ -1,5 +1,7 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
+ const { sslTerminator } = require('../ssl-terminator');
4
+ const { varnish66 } = require('../varnish/varnish-6-6');
3
5
 
4
6
  module.exports = ({ templateDir } = {}) => ({
5
7
  magentoVersion: '2.4.1',
@@ -16,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
16
18
  SimpleXML: {},
17
19
  xdebug: {
18
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
19
25
  }
20
26
  }
21
27
  },
@@ -37,7 +43,9 @@ module.exports = ({ templateDir } = {}) => ({
37
43
  },
38
44
  composer: {
39
45
  version: '1'
40
- }
46
+ },
47
+ varnish: varnish66({ templateDir }),
48
+ sslTerminator: sslTerminator({ templateDir })
41
49
  },
42
50
  magento: defaultMagentoConfig,
43
51
  host: 'localhost',
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
3
  const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
4
6
 
5
7
  module.exports = ({ templateDir } = {}) => ({
6
8
  magentoVersion: '2.4.2-p1',
@@ -20,6 +22,10 @@ module.exports = ({ templateDir } = {}) => ({
20
22
  fileinfo: {},
21
23
  xdebug: {
22
24
  version: '3.1.2'
25
+ },
26
+ apcu: {},
27
+ opcache: {
28
+ extensionName: 'Zend OPcache'
23
29
  }
24
30
  }
25
31
  },
@@ -41,7 +47,9 @@ module.exports = ({ templateDir } = {}) => ({
41
47
  },
42
48
  composer: {
43
49
  version: '2'
44
- }
50
+ },
51
+ varnish: varnish66({ templateDir }),
52
+ sslTerminator: sslTerminator({ templateDir })
45
53
  },
46
54
  magento: defaultMagentoConfig,
47
55
  host: 'localhost',
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
3
  const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
4
6
 
5
7
  module.exports = ({ templateDir } = {}) => ({
6
8
  magentoVersion: '2.4.2-p2',
@@ -20,6 +22,10 @@ module.exports = ({ templateDir } = {}) => ({
20
22
  fileinfo: {},
21
23
  xdebug: {
22
24
  version: '3.1.2'
25
+ },
26
+ apcu: {},
27
+ opcache: {
28
+ extensionName: 'Zend OPcache'
23
29
  }
24
30
  }
25
31
  },
@@ -41,7 +47,9 @@ module.exports = ({ templateDir } = {}) => ({
41
47
  },
42
48
  composer: {
43
49
  version: '2'
44
- }
50
+ },
51
+ varnish: varnish66({ templateDir }),
52
+ sslTerminator: sslTerminator({ templateDir })
45
53
  },
46
54
  magento: defaultMagentoConfig,
47
55
  host: 'localhost',
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
3
  const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
4
6
 
5
7
  module.exports = ({ templateDir } = {}) => ({
6
8
  magentoVersion: '2.4.2',
@@ -19,6 +21,10 @@ module.exports = ({ templateDir } = {}) => ({
19
21
  fileinfo: {},
20
22
  xdebug: {
21
23
  version: '3.1.2'
24
+ },
25
+ apcu: {},
26
+ opcache: {
27
+ extensionName: 'Zend OPcache'
22
28
  }
23
29
  }
24
30
  },
@@ -40,7 +46,9 @@ module.exports = ({ templateDir } = {}) => ({
40
46
  },
41
47
  composer: {
42
48
  version: '2'
43
- }
49
+ },
50
+ varnish: varnish66({ templateDir }),
51
+ sslTerminator: sslTerminator({ templateDir })
44
52
  },
45
53
  magento: defaultMagentoConfig,
46
54
  host: 'localhost',
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
3
  const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
4
6
 
5
7
  module.exports = ({ templateDir } = {}) => ({
6
8
  magentoVersion: '2.4.3-p1',
@@ -20,6 +22,10 @@ module.exports = ({ templateDir } = {}) => ({
20
22
  fileinfo: {},
21
23
  xdebug: {
22
24
  version: '3.1.2'
25
+ },
26
+ apcu: {},
27
+ opcache: {
28
+ extensionName: 'Zend OPcache'
23
29
  }
24
30
  }
25
31
  },
@@ -41,7 +47,9 @@ module.exports = ({ templateDir } = {}) => ({
41
47
  },
42
48
  composer: {
43
49
  version: '2'
44
- }
50
+ },
51
+ varnish: varnish66({ templateDir }),
52
+ sslTerminator: sslTerminator({ templateDir })
45
53
  },
46
54
  magento: defaultMagentoConfig,
47
55
  host: 'localhost',
@@ -0,0 +1,59 @@
1
+ const path = require('path');
2
+ const { defaultMagentoConfig } = require('../magento-config');
3
+ const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
6
+
7
+ module.exports = ({ templateDir } = {}) => ({
8
+ magentoVersion: '2.4.3-p2',
9
+ isDefault: true,
10
+ configuration: {
11
+ php: {
12
+ version: '7.4.27',
13
+ configTemplate: path.join(templateDir || '', 'php.template.ini'),
14
+ extensions: {
15
+ gd: {},
16
+ intl: {},
17
+ zlib: {},
18
+ openssl: {},
19
+ sockets: {},
20
+ SimpleXML: {},
21
+ libsodium,
22
+ fileinfo: {},
23
+ xdebug: {
24
+ version: '3.1.2'
25
+ },
26
+ apcu: {},
27
+ opcache: {
28
+ extensionName: 'Zend OPcache'
29
+ }
30
+ }
31
+ },
32
+ nginx: {
33
+ version: '1.18.0',
34
+ configTemplate: path.join(templateDir || '', 'nginx.template.conf')
35
+ },
36
+ redis: {
37
+ version: '6.0'
38
+ },
39
+ mysql: {
40
+ version: '8.0'
41
+ },
42
+ mariadb: {
43
+ version: '10.4'
44
+ },
45
+ elasticsearch: {
46
+ version: '7.12.1'
47
+ },
48
+ composer: {
49
+ version: '2'
50
+ },
51
+ varnish: varnish66({ templateDir }),
52
+ sslTerminator: sslTerminator({ templateDir })
53
+ },
54
+ magento: defaultMagentoConfig,
55
+ host: 'localhost',
56
+ ssl: {
57
+ enabled: false
58
+ }
59
+ });
@@ -1,6 +1,8 @@
1
1
  const path = require('path');
2
2
  const { defaultMagentoConfig } = require('../magento-config');
3
3
  const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish66 } = require('../varnish/varnish-6-6');
4
6
 
5
7
  module.exports = ({ templateDir } = {}) => ({
6
8
  magentoVersion: '2.4.3',
@@ -20,6 +22,10 @@ module.exports = ({ templateDir } = {}) => ({
20
22
  fileinfo: {},
21
23
  xdebug: {
22
24
  version: '3.1.2'
25
+ },
26
+ apcu: {},
27
+ opcache: {
28
+ extensionName: 'Zend OPcache'
23
29
  }
24
30
  }
25
31
  },
@@ -41,7 +47,9 @@ module.exports = ({ templateDir } = {}) => ({
41
47
  },
42
48
  composer: {
43
49
  version: '2'
44
- }
50
+ },
51
+ varnish: varnish66({ templateDir }),
52
+ sslTerminator: sslTerminator({ templateDir })
45
53
  },
46
54
  magento: defaultMagentoConfig,
47
55
  host: 'localhost',
@@ -0,0 +1,59 @@
1
+ const path = require('path');
2
+ const { defaultMagentoConfig } = require('../magento-config');
3
+ const { libsodium } = require('../php/extensions');
4
+ const { sslTerminator } = require('../ssl-terminator');
5
+ const { varnish70 } = require('../varnish/varnish-7-0');
6
+
7
+ module.exports = ({ templateDir } = {}) => ({
8
+ magentoVersion: '2.4.4',
9
+ isDefault: true,
10
+ configuration: {
11
+ php: {
12
+ version: '8.1.4',
13
+ configTemplate: path.join(templateDir || '', 'php.template.ini'),
14
+ extensions: {
15
+ gd: {},
16
+ intl: {},
17
+ zlib: {},
18
+ openssl: {},
19
+ sockets: {},
20
+ SimpleXML: {},
21
+ libsodium,
22
+ fileinfo: {},
23
+ xdebug: {
24
+ version: '3.1.4'
25
+ },
26
+ apcu: {},
27
+ opcache: {
28
+ extensionName: 'Zend OPcache'
29
+ }
30
+ }
31
+ },
32
+ nginx: {
33
+ version: '1.18.0',
34
+ configTemplate: path.join(templateDir || '', 'nginx.template.conf')
35
+ },
36
+ redis: {
37
+ version: '6.0'
38
+ },
39
+ mysql: {
40
+ version: '8.0'
41
+ },
42
+ mariadb: {
43
+ version: '10.4'
44
+ },
45
+ elasticsearch: {
46
+ version: '7.16.3'
47
+ },
48
+ composer: {
49
+ version: '2'
50
+ },
51
+ varnish: varnish70({ templateDir }),
52
+ sslTerminator: sslTerminator({ templateDir })
53
+ },
54
+ magento: defaultMagentoConfig,
55
+ host: 'localhost',
56
+ ssl: {
57
+ enabled: false
58
+ }
59
+ });
@@ -6,14 +6,17 @@ const setConfigFile = require('../../util/set-config');
6
6
  */
7
7
  const createBashrcConfigFile = () => ({
8
8
  title: 'Setting Bashrc config',
9
- task: async ({ config: { php, baseConfig } }) => {
9
+ task: async (ctx) => {
10
+ const { config: { php, baseConfig, overridenConfiguration } } = ctx;
11
+ const varnishEnabled = overridenConfiguration.configuration.varnish.enabled;
10
12
  try {
11
13
  await setConfigFile({
12
14
  configPathname: path.join(baseConfig.cacheDir, '.magentorc'),
13
15
  template: path.join(baseConfig.templateDir, 'magentorc.template'),
14
16
  overwrite: true,
15
17
  templateArgs: {
16
- php
18
+ php,
19
+ varnishEnabled
17
20
  }
18
21
  });
19
22
  } catch (e) {
@@ -14,6 +14,7 @@ const { execAsyncSpawn } = require('../../util/exec-async-command');
14
14
  * @param {string} [options.command] Container command
15
15
  * @param {Record<"cmd" | "interval" | "retries" | "start-period" | "timeout", string>} [options.healthCheck] Container heathcheck properties
16
16
  * @param {string[]} [options.securityOptions] Security options [docs](https://docs.docker.com/engine/reference/commandline/run/#optional-security-options---security-opt)
17
+ * @param {string[]} [options.tmpfs]
17
18
  */
18
19
  const run = (options) => {
19
20
  const {
@@ -28,9 +29,12 @@ const run = (options) => {
28
29
  entrypoint,
29
30
  command = '',
30
31
  healthCheck,
31
- securityOptions = []
32
+ securityOptions = [],
33
+ tmpfs = [],
34
+ expose = []
32
35
  } = options;
33
36
 
37
+ const exposeArg = expose && expose.map((e) => `--expose=${ e }`);
34
38
  const restartArg = restart && `--restart ${ restart }`;
35
39
  const networkArg = network && `--network ${ network }`;
36
40
  const portsArgs = ports.map((port) => `-p ${ port }`).join(' ');
@@ -41,6 +45,7 @@ const run = (options) => {
41
45
  const entrypointArg = entrypoint && `--entrypoint "${entrypoint}"`;
42
46
  const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key} '${value}'`).join(' ');
43
47
  const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt ${opt}`).join(' ');
48
+ const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs ${t}`).join(' ');
44
49
 
45
50
  const dockerCommand = [
46
51
  'docker',
@@ -50,12 +55,14 @@ const run = (options) => {
50
55
  networkArg,
51
56
  restartArg,
52
57
  portsArgs,
58
+ exposeArg,
53
59
  mountsArgs,
54
60
  mountVolumesArgs,
55
61
  envArgs,
56
62
  entrypointArg,
57
63
  healthCheckArg,
58
64
  securityArg,
65
+ tmpfsArg,
59
66
  image,
60
67
  command
61
68
  ].filter(Boolean).join(' ');
@@ -107,7 +114,7 @@ const pullContainers = () => ({
107
114
  const startContainers = () => ({
108
115
  title: 'Starting containers',
109
116
  task: async ({ ports, config: { docker } }, task) => {
110
- const containerList = await execAsyncSpawn('docker container ls');
117
+ const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n');
111
118
 
112
119
  const missingContainers = Object.values(docker.getContainers(ports)).filter(
113
120
  ({ name }) => !containerList.includes(name)
@@ -133,19 +140,17 @@ const startContainers = () => ({
133
140
  */
134
141
  const stopContainers = () => ({
135
142
  title: 'Stopping Docker containers',
136
- task: async ({ ports, config: { docker } }, task) => {
137
- const containerList = await execAsyncSpawn('docker container ls -a');
143
+ task: async ({ config: { baseConfig: { prefix } } }, task) => {
144
+ const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n');
138
145
 
139
- const runningContainers = Object.values(docker.getContainers(ports)).filter(
140
- ({ name }) => containerList.includes(name)
141
- );
146
+ const runningContainers = containerList.filter((containerName) => containerName.startsWith(prefix));
142
147
 
143
148
  if (runningContainers.length === 0) {
144
149
  task.skip();
145
150
  return;
146
151
  }
147
152
 
148
- await stop(runningContainers.map(({ name }) => name));
153
+ await stop(runningContainers);
149
154
  }
150
155
  });
151
156
 
@@ -20,10 +20,10 @@ const create = ({
20
20
  const createVolumes = () => ({
21
21
  title: 'Creating volumes',
22
22
  task: async ({ config: { docker } }, task) => {
23
- const volumeList = (await execAsyncSpawn('docker volume ls -q')).split('\n');
23
+ const volumeList = (await execAsyncSpawn('docker volume ls --format "{{.Name}}"')).split('\n');
24
24
 
25
25
  const missingVolumes = Object.values(docker.volumes).filter(
26
- ({ name }) => !volumeList.some((volume) => volume === name)
26
+ ({ name }) => !volumeList.includes(name)
27
27
  );
28
28
 
29
29
  if (missingVolumes.length === 0) {
@@ -41,10 +41,10 @@ const createVolumes = () => ({
41
41
  const removeVolumes = () => ({
42
42
  title: 'Removing volumes',
43
43
  task: async ({ config: { docker } }, task) => {
44
- const volumeList = (await execAsyncSpawn('docker volume ls -q')).split('\n');
44
+ const volumeList = (await execAsyncSpawn('docker volume ls --format "{{.Name}}"')).split('\n');
45
45
 
46
46
  const deployedVolumes = Object.values(docker.volumes).filter(
47
- ({ name }) => volumeList.some((volume) => volume === name)
47
+ ({ name }) => volumeList.includes(name)
48
48
  );
49
49
 
50
50
  if (deployedVolumes.length === 0) {
@@ -1,9 +1,6 @@
1
1
  const os = require('os');
2
2
  const path = require('path');
3
- const fs = require('fs');
4
3
  const setConfigFile = require('../../util/set-config');
5
- const pathExists = require('../../util/path-exists');
6
- const { isIpAddress } = require('../../util/ip');
7
4
 
8
5
  /**
9
6
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -23,41 +20,13 @@ const createNginxConfig = () => ({
23
20
  const {
24
21
  configuration: {
25
22
  nginx
26
- },
27
- ssl,
28
- host
29
- } = overridenConfiguration;
30
-
31
- if (ssl.enabled) {
32
- if (!(await pathExists(ssl.ssl_certificate))) {
33
- throw new Error('ssl.ssl_certificate file does not exist!');
34
- }
35
- if (!(await pathExists(ssl.ssl_certificate_key))) {
36
- throw new Error('ssl.ssl_certificate_key file does not exist!');
37
23
  }
24
+ } = overridenConfiguration;
38
25
 
39
- await fs.promises.copyFile(
40
- ssl.ssl_certificate,
41
- path.join(
42
- baseConfig.cacheDir,
43
- 'nginx',
44
- 'conf.d',
45
- 'ssl_certificate.pem'
46
- )
47
- );
48
- await fs.promises.copyFile(
49
- ssl.ssl_certificate_key,
50
- path.join(
51
- baseConfig.cacheDir,
52
- 'nginx',
53
- 'conf.d',
54
- 'ssl_certificate-key.pem'
55
- )
56
- );
57
- }
58
-
59
- const networkToBindTo = isIpAddress(host) ? host : '127.0.0.1';
60
26
  const isLinux = os.platform() === 'linux';
27
+ const isNativeLinux = isLinux && !isWsl;
28
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
29
+ const hostPort = isNativeLinux ? ports.app : 80;
61
30
 
62
31
  try {
63
32
  await setConfigFile({
@@ -72,10 +41,9 @@ const createNginxConfig = () => ({
72
41
  templateArgs: {
73
42
  ports,
74
43
  mageRoot: baseConfig.magentoDir,
75
- hostMachine: (isLinux && !isWsl) ? '127.0.0.1' : 'host.docker.internal',
76
- hostPort: (isLinux && !isWsl) ? ports.app : 80,
77
- config: overridenConfiguration,
78
- networkToBindTo
44
+ hostMachine,
45
+ hostPort,
46
+ config: overridenConfiguration
79
47
  }
80
48
  });
81
49
  } catch (e) {
@@ -0,0 +1,94 @@
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const setConfigFile = require('../../util/set-config');
5
+ const pathExists = require('../../util/path-exists');
6
+ const { isIpAddress } = require('../../util/ip');
7
+
8
+ /**
9
+ * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
10
+ */
11
+ const createSSLTerminatorConfig = () => ({
12
+ title: 'Setting ssl terminator config',
13
+ task: async (ctx) => {
14
+ const {
15
+ ports,
16
+ config: {
17
+ overridenConfiguration,
18
+ baseConfig
19
+ },
20
+ isWsl
21
+ } = ctx;
22
+
23
+ const {
24
+ configuration: {
25
+ sslTerminator
26
+ },
27
+ ssl,
28
+ host
29
+ } = overridenConfiguration;
30
+
31
+ if (ssl.enabled) {
32
+ if (!(await pathExists(ssl.ssl_certificate))) {
33
+ throw new Error('ssl.ssl_certificate file does not exist!');
34
+ }
35
+ if (!(await pathExists(ssl.ssl_certificate_key))) {
36
+ throw new Error('ssl.ssl_certificate_key file does not exist!');
37
+ }
38
+
39
+ const nginxCacheDir = path.join(baseConfig.cacheDir, 'nginx', 'conf.d');
40
+ if (!await pathExists(nginxCacheDir)) {
41
+ await fs.promises.mkdir(nginxCacheDir, { recursive: true });
42
+ }
43
+
44
+ await fs.promises.copyFile(
45
+ ssl.ssl_certificate,
46
+ path.join(
47
+ baseConfig.cacheDir,
48
+ 'ssl-terminator',
49
+ 'conf.d',
50
+ 'ssl_certificate.pem'
51
+ )
52
+ );
53
+ await fs.promises.copyFile(
54
+ ssl.ssl_certificate_key,
55
+ path.join(
56
+ baseConfig.cacheDir,
57
+ 'ssl-terminator',
58
+ 'conf.d',
59
+ 'ssl_certificate-key.pem'
60
+ )
61
+ );
62
+ }
63
+
64
+ const networkToBindTo = isIpAddress(host) ? host : '127.0.0.1';
65
+ const isLinux = os.platform() === 'linux';
66
+ const isNativeLinux = isLinux && !isWsl;
67
+ const hostMachine = isNativeLinux ? '127.0.0.1' : 'host.docker.internal';
68
+ const hostPort = isNativeLinux ? ports.sslTerminator : 80;
69
+
70
+ try {
71
+ await setConfigFile({
72
+ configPathname: path.join(
73
+ baseConfig.cacheDir,
74
+ 'ssl-terminator',
75
+ 'conf.d',
76
+ 'default.conf'
77
+ ),
78
+ template: sslTerminator.configTemplate,
79
+ overwrite: true,
80
+ templateArgs: {
81
+ ports,
82
+ hostMachine,
83
+ hostPort,
84
+ config: overridenConfiguration,
85
+ networkToBindTo
86
+ }
87
+ });
88
+ } catch (e) {
89
+ throw new Error(`Unexpected error accrued during ssl terminator config creation\n\n${e}`);
90
+ }
91
+ }
92
+ });
93
+
94
+ module.exports = createSSLTerminatorConfig;