@scandipwa/magento-scripts 1.14.1-alpha.1 → 1.14.1-alpha.4

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 (110) 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 +45 -9
  5. package/lib/config/get-port-config.js +2 -1
  6. package/lib/config/port-config.js +1 -0
  7. package/lib/config/templates/magentorc.template +3 -5
  8. package/lib/config/templates/php.template.ini +6 -4
  9. package/lib/config/templates/varnish.template.vcl +241 -0
  10. package/lib/config/versions/magento-2.3.0.js +9 -0
  11. package/lib/config/versions/magento-2.3.1.js +9 -0
  12. package/lib/config/versions/magento-2.3.2-p2.js +9 -0
  13. package/lib/config/versions/magento-2.3.2.js +9 -0
  14. package/lib/config/versions/magento-2.3.3-p1.js +9 -0
  15. package/lib/config/versions/magento-2.3.3.js +9 -0
  16. package/lib/config/versions/magento-2.3.4-p2.js +9 -0
  17. package/lib/config/versions/magento-2.3.4.js +9 -0
  18. package/lib/config/versions/magento-2.3.5-p1.js +9 -0
  19. package/lib/config/versions/magento-2.3.5-p2.js +9 -0
  20. package/lib/config/versions/magento-2.3.5.js +9 -0
  21. package/lib/config/versions/magento-2.3.6-p1.js +9 -0
  22. package/lib/config/versions/magento-2.3.6.js +9 -0
  23. package/lib/config/versions/magento-2.3.7-p1.js +9 -0
  24. package/lib/config/versions/magento-2.3.7-p2.js +9 -0
  25. package/lib/config/versions/magento-2.3.7-p3.js +9 -0
  26. package/lib/config/versions/magento-2.3.7.js +9 -0
  27. package/lib/config/versions/magento-2.4.0-p1.js +9 -0
  28. package/lib/config/versions/magento-2.4.0.js +9 -0
  29. package/lib/config/versions/magento-2.4.1-p1.js +9 -0
  30. package/lib/config/versions/magento-2.4.1.js +9 -0
  31. package/lib/config/versions/magento-2.4.2-p1.js +9 -0
  32. package/lib/config/versions/magento-2.4.2-p2.js +9 -0
  33. package/lib/config/versions/magento-2.4.2.js +9 -0
  34. package/lib/config/versions/magento-2.4.3-p1.js +9 -0
  35. package/lib/config/versions/magento-2.4.3-p2.js +9 -0
  36. package/lib/config/versions/magento-2.4.3.js +9 -0
  37. package/lib/config/versions/magento-2.4.4.js +9 -0
  38. package/lib/tasks/cli/create-bashrc-config.js +5 -2
  39. package/lib/tasks/docker/containers.js +10 -8
  40. package/lib/tasks/docker/volumes.js +4 -4
  41. package/lib/tasks/file-system/create-nginx-config.js +5 -0
  42. package/lib/tasks/file-system/create-php-storm-config.js +82 -0
  43. package/lib/tasks/file-system/create-varnish-config.js +51 -0
  44. package/lib/tasks/file-system/index.js +4 -2
  45. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  46. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  47. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  48. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  49. package/lib/tasks/magento/setup-magento/migrate-database.js +21 -6
  50. package/lib/tasks/magento/setup-magento/varnish-config.js +63 -0
  51. package/lib/tasks/mysql/fix-db.js +2 -2
  52. package/lib/tasks/php/index.js +1 -1
  53. package/lib/tasks/php/update-env-php.js +16 -1
  54. package/lib/tasks/php/update-env.php +54 -12
  55. package/lib/tasks/requirements/docker/index.js +2 -0
  56. package/lib/tasks/requirements/docker/install.js +11 -11
  57. package/lib/tasks/requirements/docker/running-status.js +137 -0
  58. package/lib/tasks/requirements/docker/version.js +2 -0
  59. package/lib/tasks/requirements/index.js +5 -5
  60. package/lib/tasks/requirements/php-version.js +3 -1
  61. package/lib/tasks/start.js +2 -6
  62. package/lib/tasks/status/index.js +1 -1
  63. package/lib/tasks/theme/link-theme.js +2 -2
  64. package/lib/tasks/theme/setup-persisted-query.js +3 -3
  65. package/lib/tasks/theme/setup-themes.js +2 -2
  66. package/lib/util/config-file-validator.js +11 -1
  67. package/lib/util/config-php-json.js +19 -0
  68. package/lib/util/instance-metadata.js +1 -7
  69. package/lib/util/is-running-root.js +3 -0
  70. package/lib/util/php-task.js +6 -2
  71. package/lib/util/run-php.js +7 -1
  72. package/lib/util/systemctl.js +46 -0
  73. package/package.json +2 -3
  74. package/typings/context.d.ts +1 -2
  75. package/typings/index.d.ts +19 -0
  76. package/lib/config/xml-parser.js +0 -61
  77. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +0 -248
  78. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +0 -83
  79. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +0 -154
  80. package/lib/tasks/file-system/create-phpstorm-config/index.js +0 -27
  81. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +0 -29
  82. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +0 -54
  83. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +0 -31
  84. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +0 -42
  85. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +0 -37
  86. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +0 -80
  87. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +0 -29
  88. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +0 -145
  89. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +0 -20
  90. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +0 -60
  91. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +0 -119
  92. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +0 -37
  93. package/lib/tasks/file-system/create-phpstorm-config/keys.js +0 -14
  94. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +0 -67
  95. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +0 -57
  96. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +0 -76
  97. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +0 -63
  98. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +0 -69
  99. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +0 -77
  100. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +0 -98
  101. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +0 -57
  102. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +0 -66
  103. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +0 -64
  104. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +0 -60
  105. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +0 -51
  106. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +0 -74
  107. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +0 -5
  108. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  109. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
  110. package/typings/phpstorm.d.ts +0 -33
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();
@@ -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,6 @@ 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
46
 
47
47
  if (!isLinux) {
48
48
  /**
@@ -53,7 +53,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
53
53
  name: `${ prefix }_nginx-data`,
54
54
  opts: {
55
55
  type: 'nfs',
56
- device: `${cacheDir}/nginx/conf.d`,
56
+ device: `${ path.join(cacheDir, 'nginx', 'conf.d') }`,
57
57
  o: 'bind'
58
58
  }
59
59
  };
@@ -69,10 +69,20 @@ module.exports = async ({ configuration, ssl, host }, config) => {
69
69
  name: `${ prefix }_setup-data`,
70
70
  opts: {
71
71
  type: 'nfs',
72
- device: `${path.join(magentoDir, 'setup')}`,
72
+ device: `${ path.join(magentoDir, 'setup') }`,
73
73
  o: 'bind'
74
74
  }
75
75
  };
76
+
77
+ if (varnish.enabled) {
78
+ volumes.varnish = {
79
+ name: `${ prefix }_varnish-vcl-data`,
80
+ opts: {
81
+ type: 'nfs',
82
+ device: `${ path.join(cacheDir, 'varnish', 'default.vcl') }`
83
+ }
84
+ };
85
+ }
76
86
  }
77
87
 
78
88
  const getContainers = (ports = {}) => {
@@ -80,7 +90,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
80
90
  nginx: {
81
91
  _: 'Nginx',
82
92
  ports: (!isLinux || isWsl) ? [
83
- `${isIpAddress(host) ? host : '127.0.0.1'}:${ ports.app }:80`
93
+ `${ isIpAddress(host) ? host : '127.0.0.1' }:${ ports.app }:80`
84
94
  ] : [],
85
95
  healthCheck: {
86
96
  cmd: 'service nginx status'
@@ -126,7 +136,7 @@ module.exports = async ({ configuration, ssl, host }, config) => {
126
136
  connectCommand: ['redis-cli']
127
137
  },
128
138
  mysql: {
129
- _: !isArmMac ? 'MySQL' : 'MariaDB',
139
+ _: !isArm ? 'MySQL' : 'MariaDB',
130
140
  healthCheck: {
131
141
  cmd: 'mysqladmin ping --silent'
132
142
  },
@@ -154,15 +164,15 @@ module.exports = async ({ configuration, ssl, host }, config) => {
154
164
  'seccomp=unconfined'
155
165
  ],
156
166
  network: network.name,
157
- image: !isArmMac ? `mysql:${ mysql.version }` : `mariadb:${ mariadb.version }`,
158
- imageDetails: !isArmMac ? {
167
+ image: !isArm ? `mysql:${ mysql.version }` : `mariadb:${ mariadb.version }`,
168
+ imageDetails: !isArm ? {
159
169
  name: 'mysql',
160
170
  tag: mysql.version
161
171
  } : {
162
172
  name: 'mariadb',
163
173
  tag: mariadb.version
164
174
  },
165
- name: !isArmMac ? `${ prefix }_mysql` : `${ prefix }_mariadb`
175
+ name: !isArm ? `${ prefix }_mysql` : `${ prefix }_mariadb`
166
176
  },
167
177
  elasticsearch: {
168
178
  _: 'ElasticSearch',
@@ -195,6 +205,32 @@ module.exports = async ({ configuration, ssl, host }, config) => {
195
205
  );
196
206
  }
197
207
 
208
+ if (varnish.enabled) {
209
+ dockerConfig.varnish = {
210
+ _: 'Varnish',
211
+ image: `varnish:${ varnish.version }`,
212
+ imageDetails: {
213
+ name: 'varnish',
214
+ tag: varnish.version
215
+ },
216
+ name: `${ prefix }_varnish`,
217
+ mountVolumes: isLinux ? [
218
+ `${ path.join(cacheDir, 'varnish', 'default.vcl') }:/etc/varnish/default.vcl:ro`
219
+ ] : [
220
+ `${ volumes.varnish.name }:/etc/varnish/default.vcl`
221
+ ],
222
+ env: {
223
+ VARNISH_SIZE: '2G'
224
+ },
225
+ restart: 'on-failure:30',
226
+ network: (!isLinux || isWsl) ? network.name : 'host',
227
+ command: `varnishd -F -a :${ ports.varnish } -t 600 -f /etc/varnish/default.vcl`,
228
+ tmpfs: [
229
+ '/var/lib/varnish:exec'
230
+ ]
231
+ };
232
+ }
233
+
198
234
  return dockerConfig;
199
235
  };
200
236
 
@@ -51,7 +51,7 @@ const getAvailablePorts = () => ({
51
51
  });
52
52
 
53
53
  /**
54
- * @type {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
54
+ * @type {() => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
55
55
  */
56
56
  const getCachedPorts = () => ({
57
57
  title: 'Getting cached ports',
@@ -65,6 +65,7 @@ const getCachedPorts = () => ({
65
65
  'utf-8'
66
66
  )
67
67
  );
68
+ ctx.cachedPorts = { ...ports };
68
69
  } else {
69
70
  ports = { ...defaultPorts };
70
71
  }
@@ -55,6 +55,7 @@ const savePortsConfig = async (ports) => {
55
55
  // Map of default ports (key:value)
56
56
  const defaultPorts = {
57
57
  app: 80,
58
+ varnish: 8080,
58
59
  fpm: 9000,
59
60
  xdebug: 9111,
60
61
  mysql: 3306,
@@ -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 ""
@@ -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,241 @@
1
+ # VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 6
2
+ vcl 4.0;
3
+
4
+ import std;
5
+ # The minimal Varnish version is 6.0
6
+ # For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'
7
+
8
+ backend default {
9
+ .host = "<%= it.hostMachine %>";
10
+ .port = "<%= it.hostPort %>";
11
+ .first_byte_timeout = 600s;
12
+ .probe = {
13
+ .url = "/health_check.php";
14
+ .timeout = 2s;
15
+ .interval = 5s;
16
+ .window = 10;
17
+ .threshold = 5;
18
+ }
19
+ }
20
+
21
+ acl purge {
22
+ "<%= it.hostMachine %>";
23
+ }
24
+
25
+ sub vcl_recv {
26
+ if (req.restarts > 0) {
27
+ set req.hash_always_miss = true;
28
+ }
29
+
30
+ if (req.method == "PURGE") {
31
+ if (client.ip !~ purge) {
32
+ return (synth(405, "Method not allowed"));
33
+ }
34
+ # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
35
+ # has been added to the response in your backend server config. This is used, for example, by the
36
+ # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
37
+ if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
38
+ return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
39
+ }
40
+ if (req.http.X-Magento-Tags-Pattern) {
41
+ ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
42
+ }
43
+ if (req.http.X-Pool) {
44
+ ban("obj.http.X-Pool ~ " + req.http.X-Pool);
45
+ }
46
+ return (synth(200, "Purged"));
47
+ }
48
+
49
+ if (req.method != "GET" &&
50
+ req.method != "HEAD" &&
51
+ req.method != "PUT" &&
52
+ req.method != "POST" &&
53
+ req.method != "TRACE" &&
54
+ req.method != "OPTIONS" &&
55
+ req.method != "DELETE") {
56
+ /* Non-RFC2616 or CONNECT which is weird. */
57
+ return (pipe);
58
+ }
59
+
60
+ # We only deal with GET and HEAD by default
61
+ if (req.method != "GET" && req.method != "HEAD") {
62
+ return (pass);
63
+ }
64
+
65
+ # Bypass customer, shopping cart, checkout
66
+ if (req.url ~ "/customer" || req.url ~ "/checkout") {
67
+ return (pass);
68
+ }
69
+
70
+ # Bypass health check requests
71
+ if (req.url ~ "^/(pub/)?(health_check.php)$") {
72
+ return (pass);
73
+ }
74
+
75
+ # Set initial grace period usage status
76
+ set req.http.grace = "none";
77
+
78
+ # normalize url in case of leading HTTP scheme and domain
79
+ set req.url = regsub(req.url, "^http[s]?://", "");
80
+
81
+ # collect all cookies
82
+ std.collect(req.http.Cookie);
83
+
84
+ # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
85
+ if (req.http.Accept-Encoding) {
86
+ if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
87
+ # No point in compressing these
88
+ unset req.http.Accept-Encoding;
89
+ } elsif (req.http.Accept-Encoding ~ "gzip") {
90
+ set req.http.Accept-Encoding = "gzip";
91
+ } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
92
+ set req.http.Accept-Encoding = "deflate";
93
+ } else {
94
+ # unknown algorithm
95
+ unset req.http.Accept-Encoding;
96
+ }
97
+ }
98
+
99
+ # Remove all marketing get parameters to minimize the cache objects
100
+ if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") {
101
+ set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
102
+ set req.url = regsub(req.url, "[?|&]+$", "");
103
+ }
104
+
105
+ # Static files caching
106
+ if (req.url ~ "^/(pub/)?(media|static)/") {
107
+ # Static files should not be cached by default
108
+ return (pass);
109
+
110
+ # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
111
+ #unset req.http.Https;
112
+ #unset req.http.X-Forwarded-Proto;
113
+ #unset req.http.Cookie;
114
+ }
115
+
116
+ # Authenticated GraphQL requests should not be cached by default
117
+ if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") {
118
+ return (pass);
119
+ }
120
+
121
+ return (hash);
122
+ }
123
+
124
+ sub vcl_hash {
125
+ if (req.http.cookie ~ "X-Magento-Vary=") {
126
+ hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
127
+ }
128
+
129
+ # To make sure http users don't see ssl warning
130
+ if (req.http.X-Forwarded-Proto) {
131
+ hash_data(req.http.X-Forwarded-Proto);
132
+ }
133
+
134
+ if (req.url ~ "/graphql") {
135
+ call process_graphql_headers;
136
+ }
137
+ }
138
+
139
+ sub process_graphql_headers {
140
+ if (req.http.Store) {
141
+ hash_data(req.http.Store);
142
+ }
143
+ if (req.http.Content-Currency) {
144
+ hash_data(req.http.Content-Currency);
145
+ }
146
+ }
147
+
148
+ sub vcl_backend_response {
149
+
150
+ set beresp.grace = 3d;
151
+
152
+ if (beresp.http.content-type ~ "text") {
153
+ set beresp.do_esi = true;
154
+ }
155
+
156
+ if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
157
+ set beresp.do_gzip = true;
158
+ }
159
+
160
+ if (beresp.http.X-Magento-Debug) {
161
+ set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
162
+ }
163
+
164
+ # cache only successfully responses and 404s
165
+ if (beresp.status != 200 && beresp.status != 404) {
166
+ set beresp.ttl = 0s;
167
+ set beresp.uncacheable = true;
168
+ return (deliver);
169
+ } elsif (beresp.http.Cache-Control ~ "private") {
170
+ set beresp.uncacheable = true;
171
+ set beresp.ttl = 86400s;
172
+ return (deliver);
173
+ }
174
+
175
+ # validate if we need to cache it and prevent from setting cookie
176
+ if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
177
+ unset beresp.http.set-cookie;
178
+ }
179
+
180
+ # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
181
+ if (beresp.ttl <= 0s ||
182
+ beresp.http.Surrogate-control ~ "no-store" ||
183
+ (!beresp.http.Surrogate-Control &&
184
+ beresp.http.Cache-Control ~ "no-cache|no-store") ||
185
+ beresp.http.Vary == "*") {
186
+ # Mark as Hit-For-Pass for the next 2 minutes
187
+ set beresp.ttl = 120s;
188
+ set beresp.uncacheable = true;
189
+ }
190
+
191
+ return (deliver);
192
+ }
193
+
194
+ sub vcl_deliver {
195
+ if (resp.http.X-Magento-Debug) {
196
+ if (resp.http.x-varnish ~ " ") {
197
+ set resp.http.X-Magento-Cache-Debug = "HIT";
198
+ set resp.http.Grace = req.http.grace;
199
+ } else {
200
+ set resp.http.X-Magento-Cache-Debug = "MISS";
201
+ }
202
+ } else {
203
+ unset resp.http.Age;
204
+ }
205
+
206
+ # Not letting browser to cache non-static files.
207
+ if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
208
+ set resp.http.Pragma = "no-cache";
209
+ set resp.http.Expires = "-1";
210
+ set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
211
+ }
212
+
213
+ unset resp.http.X-Magento-Debug;
214
+ unset resp.http.X-Magento-Tags;
215
+ unset resp.http.X-Powered-By;
216
+ unset resp.http.Server;
217
+ unset resp.http.X-Varnish;
218
+ unset resp.http.Via;
219
+ unset resp.http.Link;
220
+ }
221
+
222
+ sub vcl_hit {
223
+ if (obj.ttl >= 0s) {
224
+ # Hit within TTL period
225
+ return (deliver);
226
+ }
227
+ if (std.healthy(req.backend_hint)) {
228
+ if (obj.ttl + 300s > 0s) {
229
+ # Hit after TTL expiration, but within grace period
230
+ set req.http.grace = "normal (healthy server)";
231
+ return (deliver);
232
+ } else {
233
+ # Hit after TTL and grace expiration
234
+ return (restart);
235
+ }
236
+ } else {
237
+ # server is not healthy, retrieve from cache
238
+ set req.http.grace = "unlimited (unhealthy server)";
239
+ return (deliver);
240
+ }
241
+ }
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '5',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '5',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '5',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '5',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '6.2',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '6.2',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,
@@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({
18
18
  SimpleXML: {},
19
19
  xdebug: {
20
20
  version: '3.1.2'
21
+ },
22
+ apcu: {},
23
+ opcache: {
24
+ extensionName: 'Zend OPcache'
21
25
  }
22
26
  }
23
27
  },
@@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({
39
43
  },
40
44
  composer: {
41
45
  version: '1'
46
+ },
47
+ varnish: {
48
+ enabled: true,
49
+ version: '6.2',
50
+ configTemplate: path.join(templateDir || '', 'varnish.template.vcl')
42
51
  }
43
52
  },
44
53
  magento: defaultMagentoConfig,