@scandipwa/magento-scripts 1.14.1-alpha.0 → 1.14.1-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 (146) 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/commands/logs.js +1 -0
  5. package/lib/commands/start.js +18 -5
  6. package/lib/config/dependencies-for-platforms.js +12 -2
  7. package/lib/config/docker.js +89 -15
  8. package/lib/config/get-port-config.js +9 -3
  9. package/lib/config/index.js +2 -1
  10. package/lib/config/php/extensions/libsodium.js +2 -1
  11. package/lib/config/port-config.js +3 -1
  12. package/lib/config/scandipwa-versions.js +2 -1
  13. package/lib/config/ssl-terminator/index.js +10 -0
  14. package/lib/config/system-config.js +34 -5
  15. package/lib/config/templates/magentorc.template +3 -5
  16. package/lib/config/templates/nginx.template.conf +0 -14
  17. package/lib/config/templates/php.template.ini +6 -4
  18. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  19. package/lib/config/templates/varnish.template.vcl +250 -0
  20. package/lib/config/varnish/varnish-6-0.js +11 -0
  21. package/lib/config/varnish/varnish-6-6.js +11 -0
  22. package/lib/config/varnish/varnish-7-0.js +11 -0
  23. package/lib/config/versions/magento-2.3.0.js +9 -1
  24. package/lib/config/versions/magento-2.3.1.js +9 -1
  25. package/lib/config/versions/magento-2.3.2-p2.js +9 -1
  26. package/lib/config/versions/magento-2.3.2.js +9 -1
  27. package/lib/config/versions/magento-2.3.3-p1.js +9 -1
  28. package/lib/config/versions/magento-2.3.3.js +9 -1
  29. package/lib/config/versions/magento-2.3.4-p2.js +9 -1
  30. package/lib/config/versions/magento-2.3.4.js +9 -1
  31. package/lib/config/versions/magento-2.3.5-p1.js +9 -1
  32. package/lib/config/versions/magento-2.3.5-p2.js +9 -1
  33. package/lib/config/versions/magento-2.3.5.js +9 -1
  34. package/lib/config/versions/magento-2.3.6-p1.js +9 -1
  35. package/lib/config/versions/magento-2.3.6.js +9 -1
  36. package/lib/config/versions/magento-2.3.7-p1.js +9 -1
  37. package/lib/config/versions/magento-2.3.7-p2.js +9 -1
  38. package/lib/config/versions/magento-2.3.7-p3.js +9 -1
  39. package/lib/config/versions/magento-2.3.7.js +9 -1
  40. package/lib/config/versions/magento-2.4.0-p1.js +9 -1
  41. package/lib/config/versions/magento-2.4.0.js +9 -1
  42. package/lib/config/versions/magento-2.4.1-p1.js +9 -1
  43. package/lib/config/versions/magento-2.4.1.js +9 -1
  44. package/lib/config/versions/magento-2.4.2-p1.js +9 -1
  45. package/lib/config/versions/magento-2.4.2-p2.js +9 -1
  46. package/lib/config/versions/magento-2.4.2.js +9 -1
  47. package/lib/config/versions/magento-2.4.3-p1.js +9 -1
  48. package/lib/config/versions/magento-2.4.3-p2.js +9 -1
  49. package/lib/config/versions/magento-2.4.3.js +9 -1
  50. package/lib/config/versions/magento-2.4.4.js +9 -1
  51. package/lib/errors/known-error.js +15 -0
  52. package/lib/errors/unknown-error.js +15 -0
  53. package/lib/tasks/cli/create-bashrc-config.js +7 -3
  54. package/lib/tasks/composer/index.js +5 -3
  55. package/lib/tasks/composer/local-auth-json.js +4 -2
  56. package/lib/tasks/docker/containers.js +13 -8
  57. package/lib/tasks/docker/network.js +2 -1
  58. package/lib/tasks/docker/volumes.js +4 -4
  59. package/lib/tasks/file-system/create-nginx-config.js +9 -40
  60. package/lib/tasks/file-system/create-php-config.js +2 -1
  61. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  62. package/lib/tasks/file-system/create-php-storm-config.js +6 -5
  63. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  64. package/lib/tasks/file-system/create-varnish-config.js +53 -0
  65. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  66. package/lib/tasks/file-system/index.js +5 -1
  67. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  68. package/lib/tasks/magento/install-magento.js +7 -5
  69. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  70. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  71. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  72. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  73. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  74. package/lib/tasks/magento/setup-magento/index.js +3 -1
  75. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  76. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  77. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  78. package/lib/tasks/magento/setup-magento/upgrade-magento.js +27 -3
  79. package/lib/tasks/magento/setup-magento/varnish-config.js +69 -0
  80. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  81. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  82. package/lib/tasks/mysql/fix-db.js +2 -2
  83. package/lib/tasks/mysql/import-dump-to-mysql.js +4 -2
  84. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  85. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  86. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  87. package/lib/tasks/php/bundled-extensions.js +28 -0
  88. package/lib/tasks/php/compile-options.js +18 -48
  89. package/lib/tasks/php/compile.js +4 -3
  90. package/lib/tasks/php/configure.js +7 -66
  91. package/lib/tasks/php/extensions/index.js +71 -0
  92. package/lib/tasks/php/index.js +8 -7
  93. package/lib/tasks/php/update-env-php.js +16 -1
  94. package/lib/tasks/php/update-env.php +56 -12
  95. package/lib/tasks/php/update-phpbrew.js +2 -1
  96. package/lib/tasks/php/validate-php.js +67 -0
  97. package/lib/tasks/php-fpm/start-php-fpm.js +2 -1
  98. package/lib/tasks/requirements/composer.js +5 -3
  99. package/lib/tasks/requirements/dependency/arch.js +2 -1
  100. package/lib/tasks/requirements/dependency/centos.js +2 -1
  101. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  102. package/lib/tasks/requirements/docker/index.js +7 -4
  103. package/lib/tasks/requirements/docker/install.js +13 -12
  104. package/lib/tasks/requirements/docker/running-status.js +138 -0
  105. package/lib/tasks/requirements/docker/version.js +3 -0
  106. package/lib/tasks/requirements/index.js +5 -5
  107. package/lib/tasks/requirements/node-version.js +2 -1
  108. package/lib/tasks/requirements/php-version.js +8 -4
  109. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  110. package/lib/tasks/requirements/phpbrew/install.js +2 -1
  111. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  112. package/lib/tasks/requirements/platform.js +3 -2
  113. package/lib/tasks/start.js +11 -10
  114. package/lib/tasks/status/index.js +25 -9
  115. package/lib/tasks/theme/build-theme.js +27 -8
  116. package/lib/tasks/theme/install-theme.js +18 -5
  117. package/lib/tasks/theme/link-theme.js +2 -2
  118. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  119. package/lib/tasks/theme/setup-persisted-query.js +5 -4
  120. package/lib/tasks/theme/setup-themes.js +5 -3
  121. package/lib/tasks/theme/symlink-theme.js +20 -4
  122. package/lib/util/analytics.js +337 -0
  123. package/lib/util/config-file-validator.js +14 -2
  124. package/lib/util/config-php-json.js +20 -0
  125. package/lib/util/env-php-json.js +3 -2
  126. package/lib/util/get-installed-magento-version.js +3 -2
  127. package/lib/util/get-jsonfile-data.js +2 -1
  128. package/lib/util/install-dependencies-task.js +4 -4
  129. package/lib/util/instance-metadata.js +11 -4
  130. package/lib/util/ip.js +45 -1
  131. package/lib/util/is-running-root.js +3 -0
  132. package/lib/util/magento-task.js +20 -9
  133. package/lib/util/match-filesystem.js +2 -1
  134. package/lib/util/php-task.js +6 -2
  135. package/lib/util/request.js +0 -0
  136. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  137. package/lib/util/run-composer.js +3 -2
  138. package/lib/util/run-magento.js +3 -2
  139. package/lib/util/run-php.js +10 -3
  140. package/lib/util/systemctl.js +46 -0
  141. package/lib/util/wait-for-it.js +3 -2
  142. package/package.json +4 -3
  143. package/typings/context.d.ts +5 -1
  144. package/typings/index.d.ts +32 -1
  145. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  146. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
package/index.js CHANGED
@@ -5,6 +5,19 @@ const getLatestVersion = require('@scandipwa/scandipwa-dev-utils/latest-version'
5
5
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
6
6
  const semver = require('semver');
7
7
  const isInstalledGlobally = require('is-installed-globally');
8
+ const isRunningRoot = require('./lib/util/is-running-root');
9
+
10
+ if (isRunningRoot()) {
11
+ logger.error('Root privileges detected!');
12
+ console.log(`
13
+ We detected that you are running ${ logger.style.misc('magento-scripts') } as root user.
14
+ We cannot allow you to run ${ logger.style.misc('magento-scripts') } with root privileges, this will only cause more problems.
15
+
16
+ If you are experiencing problems with ${ logger.style.misc('Docker') }, ${ logger.style.misc('PHPBrew') } and ${ logger.style.misc('PHP') } compilation or ${ logger.style.misc('Magento') } setup, running ${ logger.style.misc('magento-scripts') } as root will not solve those problems.
17
+ `);
18
+
19
+ process.exit(1);
20
+ }
8
21
 
9
22
  const commands = [
10
23
  require('./lib/commands/link'),
@@ -7,6 +7,7 @@ const getProjectConfiguration = require('../config/get-project-configuration');
7
7
  const localAuthJson = require('../tasks/composer/local-auth-json');
8
8
  const checkConfigurationFile = require('../config/check-configuration-file');
9
9
  const { installComposer, installPrestissimo } = require('../tasks/composer');
10
+ const ConsoleBlock = require('../util/console-block');
10
11
 
11
12
  /**
12
13
  * @param {import('yargs')} yargs
@@ -30,13 +31,39 @@ module.exports = (yargs) => {
30
31
  rendererOptions: { collapse: false, clearOutput: true }
31
32
  });
32
33
 
34
+ let ctx;
33
35
  try {
34
- await tasks.run();
36
+ ctx = await tasks.run();
35
37
  } catch (e) {
36
38
  logger.error(e.message || e);
37
39
  process.exit(1);
38
40
  }
39
41
 
42
+ const block = new ConsoleBlock();
43
+
44
+ block
45
+ .addHeader('Create Magento App CLI')
46
+ .addEmptyLine()
47
+ .addLine(`Available aliases: ${logger.style.command('php')}, ${logger.style.command('magento')}, ${logger.style.command('composer')}`)
48
+ .addLine(`Available shortcuts: magento -> ${logger.style.command('m')}, composer -> ${logger.style.command('c')}`)
49
+ .addEmptyLine();
50
+
51
+ if (ctx.config.overridenConfiguration.configuration.varnish.enabled) {
52
+ block.addLine(`Clear Varnish cache: ${logger.style.command('cvc')}`);
53
+ }
54
+
55
+ block
56
+ .addLine(`Clear Magento cache: ${logger.style.command('m c:c')}`)
57
+ .addLine(`Magento setup upgrade: ${logger.style.command('m se:up')}`)
58
+ .addLine(`Magento DI compile: ${logger.style.command('m s:d:c')}`);
59
+
60
+ block
61
+ .addEmptyLine()
62
+ .addLine(`Clear Composer cache: ${logger.style.command('c cc')}`)
63
+ .addEmptyLine();
64
+
65
+ block.log();
66
+
40
67
  return cli();
41
68
  });
42
69
  };
@@ -16,7 +16,8 @@ Available containers:
16
16
  - mysql
17
17
  - nginx
18
18
  - redis
19
- - elasticsearch`);
19
+ - elasticsearch
20
+ - varnish (if enabled)`);
20
21
  },
21
22
  async (argv) => {
22
23
  const containers = (await docker).getContainers();
@@ -18,6 +18,7 @@ Available scopes:
18
18
  - redis
19
19
  - nginx
20
20
  - elasticsearch
21
+ - varnish (if enabled)
21
22
 
22
23
  And you can use name matching:
23
24
  npm run logs ma (will match magento)
@@ -4,12 +4,14 @@ const { Listr } = require('listr2');
4
4
  const { start } = require('../tasks/start');
5
5
  const pathExists = require('../util/path-exists');
6
6
  const { baseConfig } = require('../config');
7
- const googleAnalytics = require('@scandipwa/scandipwa-dev-utils/analytics');
7
+ const googleAnalytics = require('../util/analytics');
8
8
  const systeminformation = require('systeminformation');
9
9
  const { getCSAThemes } = require('../util/CSA-theme');
10
10
  const shouldUseYarn = require('@scandipwa/scandipwa-dev-utils/should-use-yarn');
11
11
  const ConsoleBlock = require('../util/console-block');
12
12
  const { getInstanceMetadata } = require('../util/instance-metadata');
13
+ const UnknownError = require('../errors/unknown-error');
14
+ const KnownError = require('../errors/known-error');
13
15
 
14
16
  const cmaGaTrackingId = 'UA-127741417-7';
15
17
 
@@ -156,8 +158,8 @@ module.exports = (yargs) => {
156
158
  }
157
159
 
158
160
  try {
161
+ await googleAnalytics.trackTiming('CMA start time', Date.now() - timeStamp);
159
162
  if (!process.isFirstStart) {
160
- await googleAnalytics.trackTiming('CMA start time', Date.now() - timeStamp);
161
163
  googleAnalytics.printAboutAnalytics();
162
164
  process.exit(0);
163
165
  }
@@ -171,7 +173,6 @@ module.exports = (yargs) => {
171
173
  const paramInfo = `Platform: ${platform} ${kernel}, CPU model: ${manufacturer} ${brand}, RAM amount: ${totalRam}MB`;
172
174
 
173
175
  await googleAnalytics.trackEvent('Params', paramInfo, 0, 'OS');
174
- await googleAnalytics.trackTiming('CMA first start time', Date.now() - timeStamp);
175
176
  googleAnalytics.printAboutAnalytics();
176
177
  } catch (e) {
177
178
  await googleAnalytics.trackError(e.message || e);
@@ -179,8 +180,20 @@ module.exports = (yargs) => {
179
180
 
180
181
  process.exit(0);
181
182
  } catch (e) {
182
- logger.error(e.message || e);
183
- await googleAnalytics.trackError(e.message || e);
183
+ if (e instanceof UnknownError || e instanceof KnownError) {
184
+ logger.error(e.message);
185
+ if (e instanceof UnknownError) {
186
+ await googleAnalytics.trackError(`Unknown Error: ${e.stack}`);
187
+ } else {
188
+ await googleAnalytics.trackError(`Known Error: ${e.message}`);
189
+ }
190
+ } else if (e instanceof Error) {
191
+ logger.error(e.message);
192
+ await googleAnalytics.trackError(`Regular Error: ${e.message}`);
193
+ } else {
194
+ logger.error(e);
195
+ await googleAnalytics.trackError(`Non Error: ${e}`); // track non-errors throws
196
+ }
184
197
  process.exit(1);
185
198
  }
186
199
  }
@@ -51,7 +51,12 @@ const dependenciesForPlatforms = {
51
51
  'libsodium',
52
52
  'libsodium-devel',
53
53
  'libtool-ltdl-devel',
54
- 'oniguruma-devel'
54
+ 'oniguruma-devel',
55
+ 'libxml2-devel',
56
+ 'bzip2-devel',
57
+ 'curl-devel',
58
+ 'libxslt-devel',
59
+ 'autoconf'
55
60
  ],
56
61
  installCommand: (deps) => `sudo yum install ${deps} -y`,
57
62
  packageManager: 'yum'
@@ -68,7 +73,12 @@ const dependenciesForPlatforms = {
68
73
  'libsodium',
69
74
  'libsodium-devel',
70
75
  'libtool-ltdl-devel',
71
- 'oniguruma-devel'
76
+ 'oniguruma-devel',
77
+ 'libxml2-devel',
78
+ 'bzip2-devel',
79
+ 'curl-devel',
80
+ 'libxslt-devel',
81
+ 'autoconf'
72
82
  ],
73
83
  installCommand: (deps) => `sudo yum install --enablerepo=PowerTools ${deps} -y`,
74
84
  packageManager: 'yum'
@@ -12,7 +12,8 @@ module.exports = async ({ configuration, ssl, host }, config) => {
12
12
  redis,
13
13
  mysql,
14
14
  elasticsearch,
15
- mariadb
15
+ mariadb,
16
+ varnish
16
17
  } = configuration;
17
18
 
18
19
  const {
@@ -42,7 +43,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
42
43
  const isLinux = os.platform() === 'linux';
43
44
  const isWsl = await getIsWsl();
44
45
  const isArm = (await getArch()) === 'arm64';
45
- const isArmMac = (os.platform() === 'darwin') && isArm;
46
+ const isNotNativeLinux = (!isLinux || isWsl);
46
47
 
47
48
  if (!isLinux) {
48
49
  /**
@@ -53,7 +54,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
53
54
  name: `${ prefix }_nginx-data`,
54
55
  opts: {
55
56
  type: 'nfs',
56
- device: `${cacheDir}/nginx/conf.d`,
57
+ device: path.join(cacheDir, 'nginx', 'conf.d'),
57
58
  o: 'bind'
58
59
  }
59
60
  };
@@ -61,7 +62,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
61
62
  name: `${ prefix }_pub-data`,
62
63
  opts: {
63
64
  type: 'nfs',
64
- device: `${ path.join(magentoDir, 'pub') }`,
65
+ device: path.join(magentoDir, 'pub'),
65
66
  o: 'bind'
66
67
  }
67
68
  };
@@ -69,18 +70,62 @@ module.exports = async ({ configuration, ssl, host }, config) => {
69
70
  name: `${ prefix }_setup-data`,
70
71
  opts: {
71
72
  type: 'nfs',
72
- device: `${path.join(magentoDir, 'setup')}`,
73
+ device: path.join(magentoDir, 'setup'),
73
74
  o: 'bind'
74
75
  }
75
76
  };
77
+ volumes.sslTerminator = {
78
+ name: `${ prefix }_ssl-terminator-data`,
79
+ opts: {
80
+ type: 'nfs',
81
+ device: path.join(cacheDir, 'ssl-terminator', 'conf.d'),
82
+ o: 'bind'
83
+ }
84
+ };
85
+
86
+ if (varnish.enabled) {
87
+ volumes.varnish = {
88
+ name: `${ prefix }_varnish-data`,
89
+ opts: {
90
+ type: 'nfs',
91
+ device: path.join(cacheDir, 'varnish'),
92
+ o: 'bind'
93
+ }
94
+ };
95
+ }
76
96
  }
77
97
 
78
98
  const getContainers = (ports = {}) => {
79
99
  const dockerConfig = {
100
+ sslTerminator: {
101
+ _: 'SSL Terminator (Nginx)',
102
+ ports: isNotNativeLinux ? [
103
+ `${ isIpAddress(host) ? host : '127.0.0.1' }:${ ports.sslTerminator }:80`
104
+ ] : [],
105
+ healthCheck: {
106
+ cmd: 'service nginx status'
107
+ },
108
+ /**
109
+ * Mount volumes directly on linux
110
+ */
111
+ mountVolumes: [
112
+ `${ isLinux ? path.join(cacheDir, 'ssl-terminator', 'conf.d') : volumes.sslTerminator.name }:/etc/nginx/conf.d`
113
+ ],
114
+ restart: 'on-failure:5',
115
+ // TODO: use connect instead
116
+ network: isNotNativeLinux ? network.name : 'host',
117
+ image: `nginx:${ nginx.version }`,
118
+ imageDetails: {
119
+ name: 'nginx',
120
+ tag: nginx.version
121
+ },
122
+ name: `${ prefix }_ssl-terminator`,
123
+ command: "nginx -g 'daemon off;'"
124
+ },
80
125
  nginx: {
81
126
  _: 'Nginx',
82
- ports: (!isLinux || isWsl) ? [
83
- `${isIpAddress(host) ? host : '127.0.0.1'}:${ ports.app }:80`
127
+ ports: isNotNativeLinux ? [
128
+ `${ isIpAddress(host) ? host : '127.0.0.1' }:${ ports.app }:80`
84
129
  ] : [],
85
130
  healthCheck: {
86
131
  cmd: 'service nginx status'
@@ -99,7 +144,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
99
144
  ],
100
145
  restart: 'on-failure:5',
101
146
  // TODO: use connect instead
102
- network: (!isLinux || isWsl) ? network.name : 'host',
147
+ network: isNotNativeLinux ? network.name : 'host',
103
148
  image: `nginx:${ nginx.version }`,
104
149
  imageDetails: {
105
150
  name: 'nginx',
@@ -126,7 +171,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
126
171
  connectCommand: ['redis-cli']
127
172
  },
128
173
  mysql: {
129
- _: !isArmMac ? 'MySQL' : 'MariaDB',
174
+ _: !isArm ? 'MySQL' : 'MariaDB',
130
175
  healthCheck: {
131
176
  cmd: 'mysqladmin ping --silent'
132
177
  },
@@ -148,21 +193,22 @@ module.exports = async ({ configuration, ssl, host }, config) => {
148
193
  command: [
149
194
  '--log_bin_trust_function_creators=1',
150
195
  '--default-authentication-plugin=mysql_native_password',
151
- '--max_allowed_packet=1GB'
196
+ '--max_allowed_packet=1GB',
197
+ '--bind-address=0.0.0.0'
152
198
  ].join(' '),
153
199
  securityOptions: [
154
200
  'seccomp=unconfined'
155
201
  ],
156
202
  network: network.name,
157
- image: !isArmMac ? `mysql:${ mysql.version }` : `mariadb:${ mariadb.version }`,
158
- imageDetails: !isArmMac ? {
203
+ image: !isArm ? `mysql:${ mysql.version }` : `mariadb:${ mariadb.version }`,
204
+ imageDetails: !isArm ? {
159
205
  name: 'mysql',
160
206
  tag: mysql.version
161
207
  } : {
162
208
  name: 'mariadb',
163
209
  tag: mariadb.version
164
210
  },
165
- name: !isArmMac ? `${ prefix }_mysql` : `${ prefix }_mariadb`
211
+ name: !isArm ? `${ prefix }_mysql` : `${ prefix }_mariadb`
166
212
  },
167
213
  elasticsearch: {
168
214
  _: 'ElasticSearch',
@@ -180,9 +226,9 @@ module.exports = async ({ configuration, ssl, host }, config) => {
180
226
  'xpack.ml.enabled': ['sse4.2', 'sse4_2'].some((sse42Flag) => cpuSupportedFlags.includes(sse42Flag))
181
227
  },
182
228
  network: network.name,
183
- image: `docker.elastic.co/elasticsearch/elasticsearch:${ elasticsearch.version }`,
229
+ image: `elasticsearch:${ elasticsearch.version }`,
184
230
  imageDetails: {
185
- name: 'docker.elastic.co/elasticsearch/elasticsearch',
231
+ name: 'elasticsearch',
186
232
  tag: elasticsearch.version
187
233
  },
188
234
  name: `${ prefix }_elasticsearch`
@@ -195,6 +241,34 @@ module.exports = async ({ configuration, ssl, host }, config) => {
195
241
  );
196
242
  }
197
243
 
244
+ if (varnish.enabled) {
245
+ dockerConfig.varnish = {
246
+ _: 'Varnish',
247
+ image: `varnish:${ varnish.version }`,
248
+ imageDetails: {
249
+ name: 'varnish',
250
+ tag: varnish.version
251
+ },
252
+ name: `${ prefix }_varnish`,
253
+ mountVolumes: [
254
+ `${ isLinux ? path.join(cacheDir, 'varnish') : volumes.varnish.name }:/etc/varnish`
255
+ ],
256
+ ports: isNotNativeLinux ? [
257
+ `${ isIpAddress(host) ? host : '127.0.0.1' }:${ ports.varnish }:80`
258
+ ] : [],
259
+ env: {
260
+ VARNISH_SIZE: '2G'
261
+ },
262
+ restart: 'on-failure:30',
263
+ network: isNotNativeLinux ? network.name : 'host',
264
+ // eslint-disable-next-line max-len
265
+ command: `/bin/bash -c "varnishd -a :${ isNotNativeLinux ? 80 : ports.varnish } -t 600 -f /etc/varnish/default.vcl -s malloc,512m && varnishlog"`,
266
+ tmpfs: [
267
+ '/var/lib/varnish:exec'
268
+ ]
269
+ };
270
+ }
271
+
198
272
  return dockerConfig;
199
273
  };
200
274
 
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { baseConfig } = require('.');
4
+ const KnownError = require('../errors/known-error');
4
5
  const pathExists = require('../util/path-exists');
5
6
  const {
6
7
  getPort,
@@ -26,6 +27,10 @@ const getAvailablePorts = () => ({
26
27
  'utf-8'
27
28
  )
28
29
  );
30
+ if (!ports.sslTerminator) {
31
+ ports.sslTerminator = ports.app;
32
+ ports.app = defaultPorts.app;
33
+ }
29
34
  }
30
35
  const {
31
36
  systemConfiguration: {
@@ -39,9 +44,9 @@ const getAvailablePorts = () => ({
39
44
  if (ctx.port) {
40
45
  const isPortAvailable = (await getPort(ctx.port)) === ctx.port;
41
46
  if (!isPortAvailable) {
42
- throw new Error(`Port ${ctx.port} is not available`);
47
+ throw new KnownError(`Port ${ctx.port} is not available`);
43
48
  } else {
44
- availablePorts.app = ctx.port;
49
+ availablePorts.sslTerminator = ctx.port;
45
50
  }
46
51
  }
47
52
 
@@ -51,7 +56,7 @@ const getAvailablePorts = () => ({
51
56
  });
52
57
 
53
58
  /**
54
- * @type {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
59
+ * @type {() => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
55
60
  */
56
61
  const getCachedPorts = () => ({
57
62
  title: 'Getting cached ports',
@@ -65,6 +70,7 @@ const getCachedPorts = () => ({
65
70
  'utf-8'
66
71
  )
67
72
  );
73
+ ctx.cachedPorts = { ...ports };
68
74
  } else {
69
75
  ports = { ...defaultPorts };
70
76
  }
@@ -10,6 +10,7 @@ const { getMagentoConfig } = require('./magento-config');
10
10
  const { getPhpStormConfig } = require('./phpstorm/debug-config');
11
11
  const resolveConfigurationWithOverrides = require('../util/resolve-configuration-with-overrides');
12
12
  const { getPrefix, folderName } = require('../util/prefix');
13
+ const UnknownError = require('../errors/unknown-error');
13
14
 
14
15
  const platforms = ['linux', 'darwin'];
15
16
  const darwinMinimalVersion = '10.5';
@@ -38,7 +39,7 @@ module.exports = {
38
39
  const newBaseConfig = getBaseConfig(projectPath, prefix);
39
40
  const configurations = getConfigurations(newBaseConfig);
40
41
  if (!configurations[magentoVersion]) {
41
- throw new Error(`No config found for magento version ${magentoVersion}`);
42
+ throw new UnknownError(`No config found for magento version ${magentoVersion}`);
42
43
  }
43
44
 
44
45
  const {
@@ -2,6 +2,7 @@ const path = require('path');
2
2
  const fs = require('fs');
3
3
  const os = require('os');
4
4
  const pathExists = require('../../../util/path-exists');
5
+ const UnknownError = require('../../../errors/unknown-error');
5
6
 
6
7
  /**
7
8
  * @type {import('../../../../typings/index').PHPExtension}
@@ -21,7 +22,7 @@ module.exports = {
21
22
  );
22
23
 
23
24
  if (!await pathExists(sodiumDynamicLibraryPath)) {
24
- throw new Error(`libsodium dynamic library file configuration not found: ${sodiumDynamicLibraryPath}`);
25
+ throw new UnknownError(`libsodium dynamic library file configuration not found: ${sodiumDynamicLibraryPath}`);
25
26
  }
26
27
  const fileContent = await fs.promises.readFile(sodiumDynamicLibraryPath, 'utf-8');
27
28
 
@@ -54,7 +54,9 @@ const savePortsConfig = async (ports) => {
54
54
 
55
55
  // Map of default ports (key:value)
56
56
  const defaultPorts = {
57
- app: 80,
57
+ app: 3031,
58
+ varnish: 8080,
59
+ sslTerminator: 80,
58
60
  fpm: 9000,
59
61
  xdebug: 9111,
60
62
  mysql: 3306,
@@ -9,7 +9,8 @@ const scandipwaMagentoVersionMapping = {
9
9
  '2.4.0': '3.1.0 - 3.1.6',
10
10
  '2.4.1': '3.2.0 - 4.2.1',
11
11
  '2.4.2': '4.3.0 - 5.0.3',
12
- '2.4.3': '5.0.4'
12
+ '2.4.3': '5.0.4 - 5.2.7',
13
+ '2.4.4': '5.3.0+'
13
14
  };
14
15
 
15
16
  module.exports = scandipwaMagentoVersionMapping;
@@ -0,0 +1,10 @@
1
+ const path = require('path');
2
+
3
+ const sslTerminator = ({ templateDir }) => ({
4
+ version: '1.18.0',
5
+ configTemplate: path.join(templateDir || '', 'ssl-terminator.template.conf')
6
+ });
7
+
8
+ module.exports = {
9
+ sslTerminator
10
+ };
@@ -4,6 +4,8 @@ const fs = require('fs');
4
4
  const pathExists = require('../util/path-exists');
5
5
  const { systemConfigurationSchema } = require('../util/config-file-validator');
6
6
  const { deepmerge } = require('../util/deepmerge');
7
+ const pathExistsSync = require('../util/path-exists-sync');
8
+ const KnownError = require('../errors/known-error');
7
9
 
8
10
  const defaultSystemConfig = {
9
11
  analytics: true,
@@ -14,19 +16,45 @@ const systemConfigPath = path.join(os.homedir(), '.cmarc');
14
16
  /**
15
17
  * @returns {Promise<typeof defaultSystemConfig>}
16
18
  */
17
- const getSystemConfig = async () => {
19
+ const getSystemConfig = async ({ validate = true } = {}) => {
18
20
  if (await pathExists(systemConfigPath)) {
19
21
  const userSystemConfig = await fs.promises.readFile(systemConfigPath, 'utf-8');
20
22
  let userSystemConfigParsed;
21
23
  try {
22
24
  userSystemConfigParsed = JSON.parse(userSystemConfig);
23
25
  } catch (e) {
24
- throw new Error(`System configuration file is not a valid JSON!\n\nFile location: ${systemConfigPath}`);
26
+ throw new KnownError(`System configuration file is not a valid JSON!\n\nFile location: ${systemConfigPath}`);
25
27
  }
28
+
29
+ if (validate) {
30
+ try {
31
+ await systemConfigurationSchema.validateAsync(userSystemConfigParsed);
32
+ } catch (e) {
33
+ throw new KnownError(`Configuration file validation error!\n\n${e.message}`);
34
+ }
35
+ }
36
+
37
+ return deepmerge(defaultSystemConfig, userSystemConfigParsed);
38
+ }
39
+
40
+ return defaultSystemConfig;
41
+ };
42
+
43
+ const getSystemConfigSync = ({ validate = true } = {}) => {
44
+ if (pathExistsSync(systemConfigPath)) {
45
+ const userSystemConfig = fs.readFileSync(systemConfigPath, { encoding: 'utf-8' });
46
+ let userSystemConfigParsed;
26
47
  try {
27
- await systemConfigurationSchema.validateAsync(userSystemConfigParsed);
48
+ userSystemConfigParsed = JSON.parse(userSystemConfig);
28
49
  } catch (e) {
29
- throw new Error(`Configuration file validation error!\n\n${e.message}`);
50
+ throw new KnownError(`System configuration file is not a valid JSON!\n\nFile location: ${systemConfigPath}`);
51
+ }
52
+ if (validate) {
53
+ try {
54
+ systemConfigurationSchema.validate(userSystemConfigParsed);
55
+ } catch (e) {
56
+ throw new KnownError(`Configuration file validation error!\n\n${e.message}`);
57
+ }
30
58
  }
31
59
 
32
60
  return deepmerge(defaultSystemConfig, userSystemConfigParsed);
@@ -48,5 +76,6 @@ const getSystemConfigTask = () => ({
48
76
  module.exports = {
49
77
  defaultSystemConfig,
50
78
  getSystemConfigTask,
51
- getSystemConfig
79
+ getSystemConfig,
80
+ getSystemConfigSync
52
81
  };
@@ -3,10 +3,8 @@ alias magento="php $PWD/bin/magento"
3
3
  alias m="magento"
4
4
  alias composer="php $PWD/node_modules/.create-magento-app-cache/composer/composer.phar"
5
5
  alias c="composer"
6
+ <% if (it.varnishEnabled) { %>
7
+ alias cvc="npm run exec varnish varnishadm ban req.url '~ /' && echo 'Varnish cache cleared!'"
8
+ <% } %>
6
9
 
7
10
  export BASH_SILENCE_DEPRECATION_WARNING=1
8
-
9
- echo ""
10
- echo "Available aliases: php, magento, composer"
11
- echo "Available shortcuts: magento -> m, composer -> c"
12
- echo ""
@@ -1,8 +1,3 @@
1
- real_ip_header X-Forwarded-For;
2
- set_real_ip_from 10.0.0.0/8;
3
- set_real_ip_from 172.0.0.0/8;
4
- real_ip_recursive on;
5
-
6
1
  upstream fastcgi_backend {
7
2
  # use tcp connection
8
3
  server <%= it.hostMachine %>:<%= it.ports.fpm %>;
@@ -10,16 +5,7 @@ upstream fastcgi_backend {
10
5
 
11
6
  server {
12
7
  listen <%= it.hostPort %>;
13
- <% if (it.config.ssl.enabled) { %>listen 443 ssl;<% } %>
14
-
15
- <% if (it.config.ssl.enabled) { %>server_name <%= it.networkToBindTo %>;
16
-
17
- ssl_certificate /etc/nginx/conf.d/ssl_certificate.pem;
18
- ssl_certificate_key /etc/nginx/conf.d/ssl_certificate-key.pem;
19
- ssl_protocols TLSv1.2;<% } else if (it.config.host) { %>server_name <%= it.config.host %>;
20
- <% } else { %>
21
8
  server_name _;
22
- <% } %>
23
9
 
24
10
  set $MAGE_ROOT <%= it.mageRoot %>;
25
11
  resolver 127.0.0.11;
@@ -1812,7 +1812,7 @@ ldap.max_links = -1
1812
1812
 
1813
1813
  [opcache]
1814
1814
  ; Determines if Zend OPCache is enabled
1815
- ; opcache.enable=1
1815
+ opcache.enable=1
1816
1816
 
1817
1817
  ; Determines if Zend OPCache is enabled for the CLI version of PHP
1818
1818
  ;opcache.enable_cli=0
@@ -1838,19 +1838,19 @@ ldap.max_links = -1
1838
1838
 
1839
1839
  ; When disabled, you must reset the OPcache manually or restart the
1840
1840
  ; webserver for changes to the filesystem to take effect.
1841
- ;opcache.validate_timestamps=1
1841
+ opcache.validate_timestamps=1
1842
1842
 
1843
1843
  ; How often (in seconds) to check file timestamps for changes to the shared
1844
1844
  ; memory storage allocation. ("1" means validate once per second, but only
1845
1845
  ; once per request. "0" means always validate)
1846
- ;opcache.revalidate_freq=2
1846
+ opcache.revalidate_freq=2
1847
1847
 
1848
1848
  ; Enables or disables file search in include_path optimization
1849
1849
  ;opcache.revalidate_path=0
1850
1850
 
1851
1851
  ; If disabled, all PHPDoc comments are dropped from the code to reduce the
1852
1852
  ; size of the optimized code.
1853
- ; opcache.save_comments=1
1853
+ opcache.save_comments=1
1854
1854
 
1855
1855
  ; If enabled, compilation warnings (including notices and deprecations) will
1856
1856
  ; be recorded and replayed each time a file is included. Otherwise, compilation
@@ -2038,3 +2038,5 @@ xdebug.mode=off
2038
2038
  <% } %>
2039
2039
 
2040
2040
  <% } %>
2041
+
2042
+ apc.enabled=1
@@ -0,0 +1,27 @@
1
+ real_ip_header X-Forwarded-For;
2
+ set_real_ip_from 10.0.0.0/8;
3
+ set_real_ip_from 172.0.0.0/8;
4
+ real_ip_recursive on;
5
+
6
+ server {
7
+ listen <%= it.hostPort %>;
8
+ <% if (it.config.ssl.enabled) { %> listen 443 ssl;
9
+ server_name <%= it.networkToBindTo %>;
10
+
11
+ ssl_certificate /etc/nginx/conf.d/ssl_certificate.pem;
12
+ ssl_certificate_key /etc/nginx/conf.d/ssl_certificate-key.pem;
13
+ ssl_protocols TLSv1.2;<% } %>
14
+
15
+ server_name <% if (it.config.host) { %><%= it.config.host %><% } else { %>_<% } %>;
16
+
17
+ location / {
18
+ proxy_buffer_size 128k;
19
+ proxy_buffers 4 256k;
20
+ proxy_busy_buffers_size 256k;
21
+ proxy_set_header X-Real-IP $remote_addr;
22
+ proxy_set_header X-Forwarded-For $remote_addr;
23
+ proxy_set_header Host $http_host;
24
+
25
+ proxy_pass http://<%= it.hostMachine %>:<% if (it.config.configuration.varnish.enabled) { %><%= it.ports.varnish %><% } else { %><%= it.ports.app %><% } %>;
26
+ }
27
+ }