diff --git a/build-packages/magento-scripts/lib/commands/cli.js b/build-packages/magento-scripts/lib/commands/cli.js index 853790b6..d9d414f4 100644 --- a/build-packages/magento-scripts/lib/commands/cli.js +++ b/build-packages/magento-scripts/lib/commands/cli.js @@ -7,6 +7,7 @@ const getProjectConfiguration = require('../config/get-project-configuration'); const localAuthJson = require('../tasks/composer/local-auth-json'); const checkConfigurationFile = require('../config/check-configuration-file'); const { installComposer, installPrestissimo } = require('../tasks/composer'); +const ConsoleBlock = require('../util/console-block'); /** * @param {import('yargs')} yargs @@ -30,13 +31,39 @@ module.exports = (yargs) => { rendererOptions: { collapse: false, clearOutput: true } }); + let ctx; try { - await tasks.run(); + ctx = await tasks.run(); } catch (e) { logger.error(e.message || e); process.exit(1); } + const block = new ConsoleBlock(); + + block + .addHeader('Create Magento App CLI') + .addEmptyLine() + .addLine(`Available aliases: ${logger.style.command('php')}, ${logger.style.command('magento')}, ${logger.style.command('composer')}`) + .addLine(`Available shortcuts: magento -> ${logger.style.command('m')}, composer -> ${logger.style.command('c')}`) + .addEmptyLine(); + + if (ctx.config.overridenConfiguration.configuration.varnish.enabled) { + block.addLine(`Clear Varnish cache: ${logger.style.command('cvc')}`); + } + + block + .addLine(`Clear Magento cache: ${logger.style.command('m c:c')}`) + .addLine(`Magento setup upgrade: ${logger.style.command('m se:up')}`) + .addLine(`Magento DI compile: ${logger.style.command('m s:d:c')}`); + + block + .addEmptyLine() + .addLine(`Clear Composer cache: ${logger.style.command('c cc')}`) + .addEmptyLine(); + + block.log(); + return cli(); }); }; diff --git a/build-packages/magento-scripts/lib/commands/execute.js b/build-packages/magento-scripts/lib/commands/execute.js index 73985d68..a633c270 100644 --- a/build-packages/magento-scripts/lib/commands/execute.js +++ b/build-packages/magento-scripts/lib/commands/execute.js @@ -16,7 +16,8 @@ Available containers: - mysql - nginx - redis -- elasticsearch`); +- elasticsearch +- varnish (if enabled)`); }, async (argv) => { const containers = (await docker).getContainers(); diff --git a/build-packages/magento-scripts/lib/config/docker.js b/build-packages/magento-scripts/lib/config/docker.js index 8b8c80e5..efb9ce01 100644 --- a/build-packages/magento-scripts/lib/config/docker.js +++ b/build-packages/magento-scripts/lib/config/docker.js @@ -12,7 +12,8 @@ module.exports = async ({ configuration, ssl, host }, config) => { redis, mysql, elasticsearch, - mariadb + mariadb, + varnish } = configuration; const { @@ -42,7 +43,6 @@ module.exports = async ({ configuration, ssl, host }, config) => { const isLinux = os.platform() === 'linux'; const isWsl = await getIsWsl(); const isArm = (await getArch()) === 'arm64'; - const isArmMac = (os.platform() === 'darwin') && isArm; if (!isLinux) { /** @@ -53,7 +53,7 @@ module.exports = async ({ configuration, ssl, host }, config) => { name: `${ prefix }_nginx-data`, opts: { type: 'nfs', - device: `${cacheDir}/nginx/conf.d`, + device: `${ path.join(cacheDir, 'nginx', 'conf.d') }`, o: 'bind' } }; @@ -69,10 +69,20 @@ module.exports = async ({ configuration, ssl, host }, config) => { name: `${ prefix }_setup-data`, opts: { type: 'nfs', - device: `${path.join(magentoDir, 'setup')}`, + device: `${ path.join(magentoDir, 'setup') }`, o: 'bind' } }; + + if (varnish.enabled) { + volumes.varnish = { + name: `${ prefix }_varnish-vcl-data`, + opts: { + type: 'nfs', + device: `${ path.join(cacheDir, 'varnish', 'default.vcl') }` + } + }; + } } const getContainers = (ports = {}) => { @@ -80,7 +90,7 @@ module.exports = async ({ configuration, ssl, host }, config) => { nginx: { _: 'Nginx', ports: (!isLinux || isWsl) ? [ - `${isIpAddress(host) ? host : '127.0.0.1'}:${ ports.app }:80` + `${ isIpAddress(host) ? host : '127.0.0.1' }:${ ports.app }:80` ] : [], healthCheck: { cmd: 'service nginx status' @@ -126,7 +136,7 @@ module.exports = async ({ configuration, ssl, host }, config) => { connectCommand: ['redis-cli'] }, mysql: { - _: !isArmMac ? 'MySQL' : 'MariaDB', + _: !isArm ? 'MySQL' : 'MariaDB', healthCheck: { cmd: 'mysqladmin ping --silent' }, @@ -154,15 +164,15 @@ module.exports = async ({ configuration, ssl, host }, config) => { 'seccomp=unconfined' ], network: network.name, - image: !isArmMac ? `mysql:${ mysql.version }` : `mariadb:${ mariadb.version }`, - imageDetails: !isArmMac ? { + image: !isArm ? `mysql:${ mysql.version }` : `mariadb:${ mariadb.version }`, + imageDetails: !isArm ? { name: 'mysql', tag: mysql.version } : { name: 'mariadb', tag: mariadb.version }, - name: !isArmMac ? `${ prefix }_mysql` : `${ prefix }_mariadb` + name: !isArm ? `${ prefix }_mysql` : `${ prefix }_mariadb` }, elasticsearch: { _: 'ElasticSearch', @@ -195,6 +205,32 @@ module.exports = async ({ configuration, ssl, host }, config) => { ); } + if (varnish.enabled) { + dockerConfig.varnish = { + _: 'Varnish', + image: `varnish:${ varnish.version }`, + imageDetails: { + name: 'varnish', + tag: varnish.version + }, + name: `${ prefix }_varnish`, + mountVolumes: isLinux ? [ + `${ path.join(cacheDir, 'varnish', 'default.vcl') }:/etc/varnish/default.vcl:ro` + ] : [ + `${ volumes.varnish.name }:/etc/varnish/default.vcl` + ], + env: { + VARNISH_SIZE: '2G' + }, + restart: 'on-failure:30', + network: (!isLinux || isWsl) ? network.name : 'host', + command: `varnishd -F -a :${ ports.varnish } -t 600 -f /etc/varnish/default.vcl`, + tmpfs: [ + '/var/lib/varnish:exec' + ] + }; + } + return dockerConfig; }; diff --git a/build-packages/magento-scripts/lib/config/get-port-config.js b/build-packages/magento-scripts/lib/config/get-port-config.js index 0ac8f4e5..5dc4453e 100644 --- a/build-packages/magento-scripts/lib/config/get-port-config.js +++ b/build-packages/magento-scripts/lib/config/get-port-config.js @@ -51,7 +51,7 @@ const getAvailablePorts = () => ({ }); /** - * @type {import('listr2').ListrTask} + * @type {() => import('listr2').ListrTask} */ const getCachedPorts = () => ({ title: 'Getting cached ports', @@ -65,6 +65,7 @@ const getCachedPorts = () => ({ 'utf-8' ) ); + ctx.cachedPorts = { ...ports }; } else { ports = { ...defaultPorts }; } diff --git a/build-packages/magento-scripts/lib/config/port-config.js b/build-packages/magento-scripts/lib/config/port-config.js index c47cefca..2dfd4922 100644 --- a/build-packages/magento-scripts/lib/config/port-config.js +++ b/build-packages/magento-scripts/lib/config/port-config.js @@ -55,6 +55,7 @@ const savePortsConfig = async (ports) => { // Map of default ports (key:value) const defaultPorts = { app: 80, + varnish: 8080, fpm: 9000, xdebug: 9111, mysql: 3306, diff --git a/build-packages/magento-scripts/lib/config/templates/magentorc.template b/build-packages/magento-scripts/lib/config/templates/magentorc.template index 522c9902..7828ab25 100644 --- a/build-packages/magento-scripts/lib/config/templates/magentorc.template +++ b/build-packages/magento-scripts/lib/config/templates/magentorc.template @@ -3,10 +3,8 @@ alias magento="php $PWD/bin/magento" alias m="magento" alias composer="php $PWD/node_modules/.create-magento-app-cache/composer/composer.phar" alias c="composer" +<% if (it.varnishEnabled) { %> +alias cvc="npm run exec varnish varnishadm ban req.url '~ /' && echo 'Varnish cache cleared!'" +<% } %> export BASH_SILENCE_DEPRECATION_WARNING=1 - -echo "" -echo "Available aliases: php, magento, composer" -echo "Available shortcuts: magento -> m, composer -> c" -echo "" diff --git a/build-packages/magento-scripts/lib/config/templates/php.template.ini b/build-packages/magento-scripts/lib/config/templates/php.template.ini index a77d5788..14cfa29e 100644 --- a/build-packages/magento-scripts/lib/config/templates/php.template.ini +++ b/build-packages/magento-scripts/lib/config/templates/php.template.ini @@ -1812,7 +1812,7 @@ ldap.max_links = -1 [opcache] ; Determines if Zend OPCache is enabled -; opcache.enable=1 +opcache.enable=1 ; Determines if Zend OPCache is enabled for the CLI version of PHP ;opcache.enable_cli=0 @@ -1838,19 +1838,19 @@ ldap.max_links = -1 ; When disabled, you must reset the OPcache manually or restart the ; webserver for changes to the filesystem to take effect. -;opcache.validate_timestamps=1 +opcache.validate_timestamps=1 ; How often (in seconds) to check file timestamps for changes to the shared ; memory storage allocation. ("1" means validate once per second, but only ; once per request. "0" means always validate) -;opcache.revalidate_freq=2 +opcache.revalidate_freq=2 ; Enables or disables file search in include_path optimization ;opcache.revalidate_path=0 ; If disabled, all PHPDoc comments are dropped from the code to reduce the ; size of the optimized code. -; opcache.save_comments=1 +opcache.save_comments=1 ; If enabled, compilation warnings (including notices and deprecations) will ; be recorded and replayed each time a file is included. Otherwise, compilation @@ -2038,3 +2038,5 @@ xdebug.mode=off <% } %> <% } %> + +apc.enabled=1 diff --git a/build-packages/magento-scripts/lib/config/templates/varnish.template.vcl b/build-packages/magento-scripts/lib/config/templates/varnish.template.vcl new file mode 100644 index 00000000..713e9975 --- /dev/null +++ b/build-packages/magento-scripts/lib/config/templates/varnish.template.vcl @@ -0,0 +1,241 @@ +# VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 6 +vcl 4.0; + +import std; +# The minimal Varnish version is 6.0 +# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https' + +backend default { + .host = "<%= it.hostMachine %>"; + .port = "<%= it.hostPort %>"; + .first_byte_timeout = 600s; + .probe = { + .url = "/health_check.php"; + .timeout = 2s; + .interval = 5s; + .window = 10; + .threshold = 5; + } +} + +acl purge { + "<%= it.hostMachine %>"; +} + +sub vcl_recv { + if (req.restarts > 0) { + set req.hash_always_miss = true; + } + + if (req.method == "PURGE") { + if (client.ip !~ purge) { + return (synth(405, "Method not allowed")); + } + # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header + # has been added to the response in your backend server config. This is used, for example, by the + # capistrano-magento2 gem for purging old content from varnish during it's deploy routine. + if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) { + return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required")); + } + if (req.http.X-Magento-Tags-Pattern) { + ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern); + } + if (req.http.X-Pool) { + ban("obj.http.X-Pool ~ " + req.http.X-Pool); + } + return (synth(200, "Purged")); + } + + if (req.method != "GET" && + req.method != "HEAD" && + req.method != "PUT" && + req.method != "POST" && + req.method != "TRACE" && + req.method != "OPTIONS" && + req.method != "DELETE") { + /* Non-RFC2616 or CONNECT which is weird. */ + return (pipe); + } + + # We only deal with GET and HEAD by default + if (req.method != "GET" && req.method != "HEAD") { + return (pass); + } + + # Bypass customer, shopping cart, checkout + if (req.url ~ "/customer" || req.url ~ "/checkout") { + return (pass); + } + + # Bypass health check requests + if (req.url ~ "^/(pub/)?(health_check.php)$") { + return (pass); + } + + # Set initial grace period usage status + set req.http.grace = "none"; + + # normalize url in case of leading HTTP scheme and domain + set req.url = regsub(req.url, "^http[s]?://", ""); + + # collect all cookies + std.collect(req.http.Cookie); + + # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression + if (req.http.Accept-Encoding) { + if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") { + # No point in compressing these + unset req.http.Accept-Encoding; + } elsif (req.http.Accept-Encoding ~ "gzip") { + set req.http.Accept-Encoding = "gzip"; + } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") { + set req.http.Accept-Encoding = "deflate"; + } else { + # unknown algorithm + unset req.http.Accept-Encoding; + } + } + + # Remove all marketing get parameters to minimize the cache objects + if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_[a-z]+|utm_[a-z]+|_bta_[a-z]+)=") { + 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+()%.]+&?", ""); + set req.url = regsub(req.url, "[?|&]+$", ""); + } + + # Static files caching + if (req.url ~ "^/(pub/)?(media|static)/") { + # Static files should not be cached by default + return (pass); + + # 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 + #unset req.http.Https; + #unset req.http.X-Forwarded-Proto; + #unset req.http.Cookie; + } + + # Authenticated GraphQL requests should not be cached by default + if (req.url ~ "/graphql" && req.http.Authorization ~ "^Bearer") { + return (pass); + } + + return (hash); +} + +sub vcl_hash { + if (req.http.cookie ~ "X-Magento-Vary=") { + hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1")); + } + + # To make sure http users don't see ssl warning + if (req.http.X-Forwarded-Proto) { + hash_data(req.http.X-Forwarded-Proto); + } + + if (req.url ~ "/graphql") { + call process_graphql_headers; + } +} + +sub process_graphql_headers { + if (req.http.Store) { + hash_data(req.http.Store); + } + if (req.http.Content-Currency) { + hash_data(req.http.Content-Currency); + } +} + +sub vcl_backend_response { + + set beresp.grace = 3d; + + if (beresp.http.content-type ~ "text") { + set beresp.do_esi = true; + } + + if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") { + set beresp.do_gzip = true; + } + + if (beresp.http.X-Magento-Debug) { + set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control; + } + + # cache only successfully responses and 404s + if (beresp.status != 200 && beresp.status != 404) { + set beresp.ttl = 0s; + set beresp.uncacheable = true; + return (deliver); + } elsif (beresp.http.Cache-Control ~ "private") { + set beresp.uncacheable = true; + set beresp.ttl = 86400s; + return (deliver); + } + + # validate if we need to cache it and prevent from setting cookie + if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) { + unset beresp.http.set-cookie; + } + + # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass + if (beresp.ttl <= 0s || + beresp.http.Surrogate-control ~ "no-store" || + (!beresp.http.Surrogate-Control && + beresp.http.Cache-Control ~ "no-cache|no-store") || + beresp.http.Vary == "*") { + # Mark as Hit-For-Pass for the next 2 minutes + set beresp.ttl = 120s; + set beresp.uncacheable = true; + } + + return (deliver); +} + +sub vcl_deliver { + if (resp.http.X-Magento-Debug) { + if (resp.http.x-varnish ~ " ") { + set resp.http.X-Magento-Cache-Debug = "HIT"; + set resp.http.Grace = req.http.grace; + } else { + set resp.http.X-Magento-Cache-Debug = "MISS"; + } + } else { + unset resp.http.Age; + } + + # Not letting browser to cache non-static files. + if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") { + set resp.http.Pragma = "no-cache"; + set resp.http.Expires = "-1"; + set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0"; + } + + unset resp.http.X-Magento-Debug; + unset resp.http.X-Magento-Tags; + unset resp.http.X-Powered-By; + unset resp.http.Server; + unset resp.http.X-Varnish; + unset resp.http.Via; + unset resp.http.Link; +} + +sub vcl_hit { + if (obj.ttl >= 0s) { + # Hit within TTL period + return (deliver); + } + if (std.healthy(req.backend_hint)) { + if (obj.ttl + 300s > 0s) { + # Hit after TTL expiration, but within grace period + set req.http.grace = "normal (healthy server)"; + return (deliver); + } else { + # Hit after TTL and grace expiration + return (restart); + } + } else { + # server is not healthy, retrieve from cache + set req.http.grace = "unlimited (unhealthy server)"; + return (deliver); + } +} diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.0.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.0.js index 1bffaab9..05a4e807 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.0.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.0.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.1.js index aa4306fc..c563cf1a 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.1.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.2-p2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.2-p2.js index 5b012840..d8ad1015 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.2-p2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.2-p2.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.2.js index 21290728..a98325e8 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.2.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.3-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.3-p1.js index 42fce77a..b76414b3 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.3-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.3-p1.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.2', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.3.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.3.js index 7136bc49..7f23503a 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.3.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.3.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.2', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.4-p2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.4-p2.js index cd03abdf..1c6e2d16 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.4-p2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.4-p2.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.2', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.4.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.4.js index 948e424d..4108d44b 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.4.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.4.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.2', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p1.js index 50d78aab..0012d3a3 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p1.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.3', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p2.js index 0a40f4eb..9b915a9f 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.5-p2.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.3', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.5.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.5.js index b1b5dc3e..f32a3731 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.5.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.5.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.3', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.6-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.6-p1.js index 6d3c58a7..e3754e74 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.6-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.6-p1.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.4', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.6.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.6.js index 74797ad1..8818c7e9 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.6.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.6.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.4', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p1.js index 64fdf6c6..866b9ded 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p1.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p2.js index 8df8bf65..b0e88b11 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p2.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p3.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p3.js index 565f2d3e..1ef676fd 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p3.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7-p3.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7.js b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7.js index bf6fbe68..4daa0cc4 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.3.7.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.3.7.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.0-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.0-p1.js index e0d7f2b1..087b95ac 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.0-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.0-p1.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.0.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.0.js index 4bd4a2dc..58dee611 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.0.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.0.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.1-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.1-p1.js index 1ff1aed8..53f40299 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.1-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.1-p1.js @@ -18,6 +18,10 @@ module.exports = ({ templateDir } = {}) => ({ libsodium, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -39,6 +43,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.2', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.1.js index d6fcb719..e8e14857 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.1.js @@ -16,6 +16,10 @@ module.exports = ({ templateDir } = {}) => ({ SimpleXML: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -37,6 +41,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '1' + }, + varnish: { + enabled: true, + version: '6.2', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p1.js index 962ab52f..aa09931e 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p1.js @@ -20,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -41,6 +45,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.4', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p2.js index 479ac105..5e5d5c1a 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.2-p2.js @@ -20,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -41,6 +45,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.4', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.2.js index b55b9c10..cc303486 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.2.js @@ -19,6 +19,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -40,6 +44,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.4', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p1.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p1.js index 0cae9f16..4775238a 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p1.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p1.js @@ -20,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -41,6 +45,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p2.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p2.js index 71460d7f..cdd8ba7b 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p2.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.3-p2.js @@ -20,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -41,6 +45,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.3.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.3.js index 9cc7af23..bbf9bc59 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.3.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.3.js @@ -20,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.2' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -41,6 +45,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '6.5', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/config/versions/magento-2.4.4.js b/build-packages/magento-scripts/lib/config/versions/magento-2.4.4.js index 75722586..eef2a224 100644 --- a/build-packages/magento-scripts/lib/config/versions/magento-2.4.4.js +++ b/build-packages/magento-scripts/lib/config/versions/magento-2.4.4.js @@ -20,6 +20,10 @@ module.exports = ({ templateDir } = {}) => ({ fileinfo: {}, xdebug: { version: '3.1.4' + }, + apcu: {}, + opcache: { + extensionName: 'Zend OPcache' } } }, @@ -41,6 +45,11 @@ module.exports = ({ templateDir } = {}) => ({ }, composer: { version: '2' + }, + varnish: { + enabled: true, + version: '7.0', + configTemplate: path.join(templateDir || '', 'varnish.template.vcl') } }, magento: defaultMagentoConfig, diff --git a/build-packages/magento-scripts/lib/tasks/cli/create-bashrc-config.js b/build-packages/magento-scripts/lib/tasks/cli/create-bashrc-config.js index 5b0a140a..6b8deff8 100644 --- a/build-packages/magento-scripts/lib/tasks/cli/create-bashrc-config.js +++ b/build-packages/magento-scripts/lib/tasks/cli/create-bashrc-config.js @@ -6,14 +6,17 @@ const setConfigFile = require('../../util/set-config'); */ const createBashrcConfigFile = () => ({ title: 'Setting Bashrc config', - task: async ({ config: { php, baseConfig } }) => { + task: async (ctx) => { + const { config: { php, baseConfig, overridenConfiguration } } = ctx; + const varnishEnabled = overridenConfiguration.configuration.varnish.enabled; try { await setConfigFile({ configPathname: path.join(baseConfig.cacheDir, '.magentorc'), template: path.join(baseConfig.templateDir, 'magentorc.template'), overwrite: true, templateArgs: { - php + php, + varnishEnabled } }); } catch (e) { diff --git a/build-packages/magento-scripts/lib/tasks/docker/containers.js b/build-packages/magento-scripts/lib/tasks/docker/containers.js index bf627323..46b82e9d 100644 --- a/build-packages/magento-scripts/lib/tasks/docker/containers.js +++ b/build-packages/magento-scripts/lib/tasks/docker/containers.js @@ -14,6 +14,7 @@ const { execAsyncSpawn } = require('../../util/exec-async-command'); * @param {string} [options.command] Container command * @param {Record<"cmd" | "interval" | "retries" | "start-period" | "timeout", string>} [options.healthCheck] Container heathcheck properties * @param {string[]} [options.securityOptions] Security options [docs](https://docs.docker.com/engine/reference/commandline/run/#optional-security-options---security-opt) + * @param {string[]} [options.tmpfs] */ const run = (options) => { const { @@ -28,7 +29,8 @@ const run = (options) => { entrypoint, command = '', healthCheck, - securityOptions = [] + securityOptions = [], + tmpfs = [] } = options; const restartArg = restart && `--restart ${ restart }`; @@ -41,6 +43,7 @@ const run = (options) => { const entrypointArg = entrypoint && `--entrypoint "${entrypoint}"`; const healthCheckArg = healthCheck && Object.entries(healthCheck).map(([key, value]) => `--health-${key} '${value}'`).join(' '); const securityArg = securityOptions.length > 0 && securityOptions.map((opt) => `--security-opt ${opt}`).join(' '); + const tmpfsArg = tmpfs.length > 0 && tmpfs.map((t) => `--tmpfs ${t}`).join(' '); const dockerCommand = [ 'docker', @@ -56,6 +59,7 @@ const run = (options) => { entrypointArg, healthCheckArg, securityArg, + tmpfsArg, image, command ].filter(Boolean).join(' '); @@ -107,7 +111,7 @@ const pullContainers = () => ({ const startContainers = () => ({ title: 'Starting containers', task: async ({ ports, config: { docker } }, task) => { - const containerList = await execAsyncSpawn('docker container ls'); + const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n'); const missingContainers = Object.values(docker.getContainers(ports)).filter( ({ name }) => !containerList.includes(name) @@ -133,19 +137,17 @@ const startContainers = () => ({ */ const stopContainers = () => ({ title: 'Stopping Docker containers', - task: async ({ ports, config: { docker } }, task) => { - const containerList = await execAsyncSpawn('docker container ls -a'); + task: async ({ config: { baseConfig: { prefix } } }, task) => { + const containerList = (await execAsyncSpawn('docker container ls --all --format="{{.Names}}"')).split('\n'); - const runningContainers = Object.values(docker.getContainers(ports)).filter( - ({ name }) => containerList.includes(name) - ); + const runningContainers = containerList.filter((containerName) => containerName.startsWith(prefix)); if (runningContainers.length === 0) { task.skip(); return; } - await stop(runningContainers.map(({ name }) => name)); + await stop(runningContainers); } }); diff --git a/build-packages/magento-scripts/lib/tasks/docker/volumes.js b/build-packages/magento-scripts/lib/tasks/docker/volumes.js index df40242f..c7d69559 100644 --- a/build-packages/magento-scripts/lib/tasks/docker/volumes.js +++ b/build-packages/magento-scripts/lib/tasks/docker/volumes.js @@ -20,10 +20,10 @@ const create = ({ const createVolumes = () => ({ title: 'Creating volumes', task: async ({ config: { docker } }, task) => { - const volumeList = (await execAsyncSpawn('docker volume ls -q')).split('\n'); + const volumeList = (await execAsyncSpawn('docker volume ls --format "{{.Name}}"')).split('\n'); const missingVolumes = Object.values(docker.volumes).filter( - ({ name }) => !volumeList.some((volume) => volume === name) + ({ name }) => !volumeList.includes(name) ); if (missingVolumes.length === 0) { @@ -41,10 +41,10 @@ const createVolumes = () => ({ const removeVolumes = () => ({ title: 'Removing volumes', task: async ({ config: { docker } }, task) => { - const volumeList = (await execAsyncSpawn('docker volume ls -q')).split('\n'); + const volumeList = (await execAsyncSpawn('docker volume ls --format "{{.Name}}"')).split('\n'); const deployedVolumes = Object.values(docker.volumes).filter( - ({ name }) => volumeList.some((volume) => volume === name) + ({ name }) => volumeList.includes(name) ); if (deployedVolumes.length === 0) { diff --git a/build-packages/magento-scripts/lib/tasks/file-system/create-varnish-config.js b/build-packages/magento-scripts/lib/tasks/file-system/create-varnish-config.js new file mode 100644 index 00000000..b36bba72 --- /dev/null +++ b/build-packages/magento-scripts/lib/tasks/file-system/create-varnish-config.js @@ -0,0 +1,51 @@ +const os = require('os'); +const path = require('path'); +const setConfigFile = require('../../util/set-config'); + +/** + * @type {() => import('listr2').ListrTask} + */ +const createVarnishConfig = () => ({ + title: 'Setting Varnish config', + skip: (ctx) => !ctx.config.overridenConfiguration.configuration.varnish.enabled, + task: async (ctx) => { + const { + ports, + config: { + overridenConfiguration, + baseConfig: { + cacheDir + } + }, + isWsl + } = ctx; + + const { + configuration: { + varnish + } + } = overridenConfiguration; + + const isLinux = os.platform() === 'linux'; + + try { + await setConfigFile({ + configPathname: path.join( + cacheDir, + 'varnish', + 'default.vcl' + ), + template: varnish.configTemplate, + overwrite: true, + templateArgs: { + hostMachine: (isLinux && !isWsl) ? '127.0.0.1' : 'host.docker.internal', + hostPort: (isLinux && !isWsl) ? ports.app : 80 + } + }); + } catch (e) { + throw new Error(`Unexpected error accrued during varnish config creation\n\n${e}`); + } + } +}); + +module.exports = createVarnishConfig; diff --git a/build-packages/magento-scripts/lib/tasks/file-system/index.js b/build-packages/magento-scripts/lib/tasks/file-system/index.js index 6717d4ba..b5df39e4 100644 --- a/build-packages/magento-scripts/lib/tasks/file-system/index.js +++ b/build-packages/magento-scripts/lib/tasks/file-system/index.js @@ -2,6 +2,7 @@ const createNginxConfig = require('./create-nginx-config'); const createPhpConfig = require('./create-php-config'); const createPhpFpmConfig = require('./create-php-fpm-config'); const createPhpStormConfig = require('./create-php-storm-config'); +const createVarnishConfig = require('./create-varnish-config'); const createVSCodeConfig = require('./create-vscode-config'); /** @@ -14,7 +15,8 @@ const prepareFileSystem = () => ({ createPhpFpmConfig(), createPhpConfig(), createPhpStormConfig(), - createVSCodeConfig() + createVSCodeConfig(), + createVarnishConfig() ], { concurrent: true }) diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/adjust-magento-configuration.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/adjust-magento-configuration.js deleted file mode 100644 index c9cf8aa3..00000000 --- a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +++ /dev/null @@ -1,27 +0,0 @@ -const { isTableExists } = require('../../../util/database'); - -/** - * @type {() => import('listr2').ListrTask} - */ -const adjustMagentoConfiguration = () => ({ - title: 'Adjusting Magento Database Configuration', - skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)), - task: async (ctx) => { - const { mysqlConnection } = ctx; - - // delete varnish configuration if exists - await mysqlConnection.query(` - DELETE FROM core_config_data WHERE path LIKE '%varnish%'; - `); - - // update cache policy to not use varnish - // 0 - magento cache, 2 - varnish cache - await mysqlConnection.query(` - UPDATE core_config_data - SET value = ? - WHERE path = ?; - `, ['0', 'system/full_page_cache/caching_application']); - } -}); - -module.exports = adjustMagentoConfiguration; diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/configure-elasticsearch.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/configure-elasticsearch.js index 47084b13..0a3d77fd 100644 --- a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/configure-elasticsearch.js +++ b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/configure-elasticsearch.js @@ -4,7 +4,7 @@ const { updateTableValues, isTableExists } = require('../../../util/database'); * @type {() => import('listr2').ListrTask} */ module.exports = () => ({ - title: 'Configuring elasticsearch', + title: 'Configuring Elasticsearch', skip: async (ctx) => !(await isTableExists('magento', 'core_config_data', ctx)), task: async ({ ports, mysqlConnection }, task) => { await updateTableValues('core_config_data', [ diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-2fa.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-2fa.js index c3298fd9..2629e520 100644 --- a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-2fa.js +++ b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-2fa.js @@ -1,23 +1,15 @@ +const configPhpToJson = require('../../../util/config-php-json'); const runMagentoCommand = require('../../../util/run-magento'); /** * @type {() => import('listr2').ListrTask} */ module.exports = () => ({ - title: 'Disabling 2fa for admin.', + title: 'Disabling 2fa for admin', task: async ({ magentoVersion }, task) => { - const { result } = await runMagentoCommand('module:status Magento_TwoFactorAuth', { - magentoVersion, - throwNonZeroCode: false - }); + const { modules } = await configPhpToJson(process.cwd(), { magentoVersion }); - if (result.includes('Module is disabled')) { - task.skip(); - return; - } - - // Disable 2FA due admin login issue - if (result.includes('Module is enabled')) { + if (modules.Magento_TwoFactorAuth !== 0) { await runMagentoCommand('module:disable Magento_TwoFactorAuth', { magentoVersion }); diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-full-page-cache.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-full-page-cache.js new file mode 100644 index 00000000..de6870fe --- /dev/null +++ b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-full-page-cache.js @@ -0,0 +1,20 @@ +const envPhpToJson = require('../../../util/env-php-json'); +const magentoTask = require('../../../util/magento-task'); + +/** + * @type {() => import('listr2').ListrTask} + */ +const disableFullPageCache = () => ({ + title: 'Disabling full_page cache in Magento', + task: async ({ magentoVersion }, task) => { + const { cache_types } = await envPhpToJson(process.cwd(), { magentoVersion }); + + if (cache_types.full_page !== 0) { + return task.newListr(magentoTask('cache:disable full_page')); + } + + task.skip(); + } +}); + +module.exports = disableFullPageCache; diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-page-cache.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-page-cache.js deleted file mode 100644 index dd2e6d51..00000000 --- a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/disable-page-cache.js +++ /dev/null @@ -1,11 +0,0 @@ -const magentoTask = require('../../../util/magento-task'); - -/** - * @type {() => import('listr2').ListrTask} - */ -const disablePageCache = () => ({ - title: 'Disabling full_page cache in Magento', - task: (ctx, task) => task.newListr(magentoTask('cache:disable full_page')) -}); - -module.exports = disablePageCache; diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js index c6b9d2e0..50472cee 100644 --- a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +++ b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js @@ -5,22 +5,20 @@ const { updateTableValues } = require('../../../util/database'); */ const increaseAdminSessionLifetime = () => ({ title: 'Increase admin session lifetime to 1 month', - task: async (ctx, task) => { - const { mysqlConnection } = ctx; - await updateTableValues('core_config_data', [ - { - path: 'admin/security/session_lifetime', - value: '2800000' - }, - { - path: 'admin/security/password_lifetime', - value: null - } - ], { - mysqlConnection, - task - }); - } + task: async ({ mysqlConnection }, task) => updateTableValues('core_config_data', [ + { + path: 'admin/security/session_lifetime', + value: '2800000' + }, + { + path: 'admin/security/password_lifetime', + value: null + } + ], { + mysqlConnection, + task + }) + }); module.exports = increaseAdminSessionLifetime; diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/migrate-database.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/migrate-database.js index 9c25e619..c311900d 100644 --- a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/migrate-database.js +++ b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/migrate-database.js @@ -1,10 +1,10 @@ const magentoTask = require('../../../util/magento-task'); const runMagentoCommand = require('../../../util/run-magento'); -const adjustMagentoConfiguration = require('./adjust-magento-configuration'); const configureElasticsearch = require('./configure-elasticsearch'); const installMagento = require('./install-magento'); const upgradeMagento = require('./upgrade-magento'); const setupPersistedQuery = require('../../theme/setup-persisted-query'); +const varnishConfigSetup = require('./varnish-config'); /** * @type {({ onlyInstallMagento: boolean }) => import('listr2').ListrTask} @@ -35,11 +35,15 @@ const migrateDatabase = (options = {}) => ({ setupPersistedQuery(), upgradeMagento(), magentoTask('cache:enable'), + varnishConfigSetup(), configureElasticsearch() ], { concurrent: false, exitOnError: true, - ctx + ctx, + rendererOptions: { + collapse: false + } }); } const { code } = await runMagentoCommand('setup:db:status', { @@ -52,11 +56,15 @@ const migrateDatabase = (options = {}) => ({ // no setup is needed, but still to be sure configure ES return task.newListr([ setupPersistedQuery(), + varnishConfigSetup(), configureElasticsearch() ], { concurrent: false, exitOnError: true, - ctx + ctx, + rendererOptions: { + collapse: false + } }); } case 1: { @@ -71,23 +79,30 @@ const migrateDatabase = (options = {}) => ({ setupPersistedQuery(), upgradeMagento(), magentoTask('cache:enable'), + varnishConfigSetup(), configureElasticsearch() ], { concurrent: false, exitOnError: true, - ctx + ctx, + rendererOptions: { + collapse: false + } }); } case 2: { return task.newListr([ setupPersistedQuery(), - adjustMagentoConfiguration(), + varnishConfigSetup(), configureElasticsearch(), upgradeMagento() ], { concurrent: false, exitOnError: true, - ctx + ctx, + rendererOptions: { + collapse: false + } }); } default: { diff --git a/build-packages/magento-scripts/lib/tasks/magento/setup-magento/varnish-config.js b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/varnish-config.js new file mode 100644 index 00000000..6a2a5980 --- /dev/null +++ b/build-packages/magento-scripts/lib/tasks/magento/setup-magento/varnish-config.js @@ -0,0 +1,63 @@ +const { updateTableValues } = require('../../../util/database'); + +/** + * @type {() => import('listr2').ListrTask} + */ +const varnishConfigSetup = () => ({ + title: 'Varnish setup', + task: async (ctx, task) => { + const { + config: { + overridenConfiguration: { + configuration: { + varnish: { + enabled: varnishEnabled + } + } + } + }, + mysqlConnection, + ports + } = ctx; + + if (varnishEnabled) { + await updateTableValues('core_config_data', [ + { + path: 'system/full_page_cache/varnish/backend_host', + value: 'localhost' + }, + { + path: 'system/full_page_cache/varnish/backend_port', + value: ports.varnish + }, + { + path: 'system/full_page_cache/varnish/access_list', + value: 'localhost' + }, + { + path: 'system/full_page_cache/caching_application', + value: '2' + } + ], { mysqlConnection, task }); + } else { + // delete varnish configuration if exists + await mysqlConnection.query(` + DELETE FROM core_config_data WHERE path LIKE '%varnish%'; + `); + + // update cache policy to not use varnish + // 0 - magento cache, 2 - varnish cache + await updateTableValues('core_config_data', [ + { + path: 'system/full_page_cache/caching_application', + value: '0' + } + ], { mysqlConnection, task }); + } + }, + options: { + bottomBar: 10 + } +}); + +module.exports = varnishConfigSetup; diff --git a/build-packages/magento-scripts/lib/tasks/mysql/fix-db.js b/build-packages/magento-scripts/lib/tasks/mysql/fix-db.js index 11daad4c..fa8a6d06 100644 --- a/build-packages/magento-scripts/lib/tasks/mysql/fix-db.js +++ b/build-packages/magento-scripts/lib/tasks/mysql/fix-db.js @@ -1,8 +1,8 @@ -const adjustMagentoConfiguration = require('../magento/setup-magento/adjust-magento-configuration'); const configureElasticsearch = require('../magento/setup-magento/configure-elasticsearch'); const deleteAdminUsers = require('../magento/setup-magento/delete-admin-users'); const deleteCustomers = require('../magento/setup-magento/delete-customers'); const deleteOrders = require('../magento/setup-magento/delete-orders'); +const varnishConfigSetup = require('../magento/setup-magento/varnish-config'); /** * @type {() => import('listr2').ListrTask} @@ -24,7 +24,7 @@ const disableForeignKeyCheck = () => ({ const fixDB = () => ({ title: 'Fixing database', task: async (ctx, task) => task.newListr([ - adjustMagentoConfiguration(), + varnishConfigSetup(), configureElasticsearch(), { title: 'Deleting customers data', diff --git a/build-packages/magento-scripts/lib/tasks/php/index.js b/build-packages/magento-scripts/lib/tasks/php/index.js index dc46125d..4d7f45d1 100644 --- a/build-packages/magento-scripts/lib/tasks/php/index.js +++ b/build-packages/magento-scripts/lib/tasks/php/index.js @@ -17,7 +17,7 @@ const installPhp = () => ({ const phpBinExists = await pathExists(php.binPath); if (phpBinExists && !recompilePhp) { - task.title = `Using PHP version ${php.version}`; + task.title = `Using PHP version ${php.version} in project`; return; } diff --git a/build-packages/magento-scripts/lib/tasks/php/update-env-php.js b/build-packages/magento-scripts/lib/tasks/php/update-env-php.js index 8e5f0140..84cfee49 100644 --- a/build-packages/magento-scripts/lib/tasks/php/update-env-php.js +++ b/build-packages/magento-scripts/lib/tasks/php/update-env-php.js @@ -14,8 +14,23 @@ const updateEnvPHP = () => ({ return; } + const useVarinsh = ctx.config.overridenConfiguration.configuration.varnish.enabled ? '1' : ''; + const varnishHost = '127.0.0.1'; + const varnishPort = ctx.ports.varnish; + const previousVarnishPort = ctx.cachedPorts + ? ctx.cachedPorts.varnish + : ctx.cachedPorts; + return task.newListr( - phpTask(`-f ${ path.join(__dirname, 'update-env.php') }`, { noTitle: true }) + phpTask(`-f ${ path.join(__dirname, 'update-env.php') }`, { + noTitle: true, + env: { + USE_VARNISH: useVarinsh, + VARNISH_PORT: `${ varnishPort }`, + VARNISH_HOST: varnishHost, + PREVIOUS_VARNISH_PORT: `${ previousVarnishPort }` + } + }) ); } }); diff --git a/build-packages/magento-scripts/lib/tasks/php/update-env.php b/build-packages/magento-scripts/lib/tasks/php/update-env.php index 45ebf51e..ba21ec2f 100644 --- a/build-packages/magento-scripts/lib/tasks/php/update-env.php +++ b/build-packages/magento-scripts/lib/tasks/php/update-env.php @@ -1,13 +1,17 @@ \s$/"], [NULL, ']$1', ' => ['], $array); + $array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [null, ']$1', ' => ['], $array); $export = join(PHP_EOL, array_filter(["["] + $array)); - if ((bool)$return) return $export; else echo $export; + if ((bool)$return) { + return $export; + } else { + echo $export; + } } function joinpaths(): string @@ -15,13 +19,16 @@ function joinpaths(): string $paths = array(); foreach (func_get_args() as $arg) { - if ($arg !== '') { $paths[] = $arg; } + if ($arg !== '') { + $paths[] = $arg; + } } - return preg_replace('#/+#','/',join('/', $paths)); + return preg_replace('#/+#', '/', join('/', $paths)); } -class EnvUpdater { +class EnvUpdater +{ /** * @var array @@ -33,7 +40,8 @@ class EnvUpdater { */ private $portConfig; - public function loadConfig() { + public function loadConfig() + { $this->config = require './app/etc/env.php'; } @@ -53,7 +61,8 @@ public function getPortConfig(): mixed return $this->portConfig; } - public function loadPortConfig() { + public function loadPortConfig() + { $portConfigContent = file_get_contents('./node_modules/.create-magento-app-cache/port-config.json'); if ($portConfigContent === false) { throw new Error('Port config file does not exists in cache directory'); @@ -67,7 +76,8 @@ public function loadPortConfig() { $this->portConfig = $portConfigJsonData; } - public function modifyConfig() { + public function modifyConfig() + { // update mysql config if (isset($this->config['db']['connection']['default'])) { $conn = &$this->config['db']['connection']['default']; @@ -122,16 +132,48 @@ public function modifyConfig() { } } } + + $httpCacheHosts = &$this->config['http_cache_hosts']; + $httpCacheHosts = []; + + if (getenv('USE_VARNISH') == '1') { + $varnishHost = getenv('VARNISH_HOST'); + $varnishPort = getenv('VARNISH_PORT'); + $previousVarnishPort = getenv('PREVIOUS_VARNISH_PORT'); + $varnishConfig = [ + 'host' => $varnishHost, + 'port' => $varnishPort + ]; + + if (isset($httpCacheHosts)) { + $varnishHostExists = false; + foreach ($httpCacheHosts as $host) { + if ($host['host'] == $varnishHost && $host['port'] == $previousVarnishPort) { + $host['port'] = $varnishPort; + $varnishHostExists = true; + break; + } + } + + if (!$varnishHostExists) { + $httpCacheHosts = [$varnishConfig]; + } + } else { + $this->config['http_cache_hosts'] = [$varnishConfig]; + } + } } - public function saveConfig(string $filePath){ + public function saveConfig(string $filePath) + { file_put_contents( $filePath, 'config, true).';' . PHP_EOL ); } - public function update(){ + public function update() + { $this->loadConfig(); $this->loadPortConfig(); $this->modifyConfig(); diff --git a/build-packages/magento-scripts/lib/tasks/requirements/index.js b/build-packages/magento-scripts/lib/tasks/requirements/index.js index 94d5cec6..8323cba2 100644 --- a/build-packages/magento-scripts/lib/tasks/requirements/index.js +++ b/build-packages/magento-scripts/lib/tasks/requirements/index.js @@ -13,17 +13,17 @@ const checkRequirements = () => ({ task: (ctx, task) => task.newListr([ // checking if user is on supported platform checkPlatform(), + // check the Docker installation + checkDocker(), + // check for Node.js version + checkNodeVersion(), // check the PHPBrew installation checkPHPbrew(), // check installed PHP version checkPHPVersion(), - // check the Docker installation - checkDocker(), // check for COMPOSER_AUTH or auth.json // localAuthJson(), - checkComposer(), - // check for Node.js version - checkNodeVersion() + checkComposer() ], { concurrent: false, exitOnError: true, diff --git a/build-packages/magento-scripts/lib/tasks/requirements/php-version.js b/build-packages/magento-scripts/lib/tasks/requirements/php-version.js index 0ca8d559..e408374b 100644 --- a/build-packages/magento-scripts/lib/tasks/requirements/php-version.js +++ b/build-packages/magento-scripts/lib/tasks/requirements/php-version.js @@ -99,7 +99,7 @@ const checkPHPVersion = () => ({ task: async (ctx, task) => { const phpVersionResponse = await execAsyncSpawn('php --version'); - const phpVersionResponseResult = phpVersionResponse.match(/PHP\s(\d\.\d\.\d)/i); + const phpVersionResponseResult = phpVersionResponse.match(/PHP\s(\d+\.\d+\.\d+)/i); if (phpVersionResponseResult && phpVersionResponseResult.length > 0) { const phpVersion = phpVersionResponseResult[1]; @@ -123,6 +123,8 @@ To fix that we will build special PHP version that will be used by PHPBrew, plea ); } } + + task.title = `Using PHP version ${phpVersion} in system`; } } }); diff --git a/build-packages/magento-scripts/lib/tasks/status/index.js b/build-packages/magento-scripts/lib/tasks/status/index.js index a6ead6c3..59684b22 100644 --- a/build-packages/magento-scripts/lib/tasks/status/index.js +++ b/build-packages/magento-scripts/lib/tasks/status/index.js @@ -91,7 +91,7 @@ const prettyStatus = async (ctx) => { .addLine(`Image: ${logger.style.file(container.image)}`) .addLine(`Network: ${logger.style.link(container.network)}`); - if (container.ports.length > 0) { + if (container.ports && container.ports.length > 0) { block.addLine('Port forwarding:'); container.ports.forEach((port) => { const { host, hostPort, containerPort } = parsePort(port); diff --git a/build-packages/magento-scripts/lib/tasks/theme/link-theme.js b/build-packages/magento-scripts/lib/tasks/theme/link-theme.js index 5be351f6..ff6a6513 100644 --- a/build-packages/magento-scripts/lib/tasks/theme/link-theme.js +++ b/build-packages/magento-scripts/lib/tasks/theme/link-theme.js @@ -1,6 +1,6 @@ const symlinkTheme = require('./symlink-theme'); const installTheme = require('./install-theme'); -const disablePageCache = require('../magento/setup-magento/disable-page-cache'); +const disableFullPageCache = require('../magento/setup-magento/disable-full-page-cache'); const disablePageBuilder = require('../magento/setup-magento/disable-page-builder'); const buildTheme = require('./build-theme'); const upgradeMagento = require('../magento/setup-magento/upgrade-magento'); @@ -53,7 +53,7 @@ const linkTheme = () => ({ updateEnvPHP(), setupPersistedQuery(), upgradeMagento(), - disablePageCache(), + disableFullPageCache(), ...(isPageBuilderInstalled && Number(isPagebuilderEnabled) ? [disablePageBuilder()] : []), buildTheme(theme) ]); diff --git a/build-packages/magento-scripts/lib/tasks/theme/setup-persisted-query.js b/build-packages/magento-scripts/lib/tasks/theme/setup-persisted-query.js index 1b2df2fe..8fb81d81 100644 --- a/build-packages/magento-scripts/lib/tasks/theme/setup-persisted-query.js +++ b/build-packages/magento-scripts/lib/tasks/theme/setup-persisted-query.js @@ -8,7 +8,7 @@ const runMagentoCommand = require('../../util/run-magento'); * @type {() => import('listr2').ListrTask} */ const persistedQuerySetup = () => ({ - title: 'Setting up redis configuration for persisted queries', + title: 'Setting up Redis configuration for persisted queries', task: async (ctx, task) => { const { ports, magentoVersion, verbose = false } = ctx; const composerLockData = await getJsonfileData(path.join(process.cwd(), 'composer.lock')); @@ -29,8 +29,8 @@ const persistedQuerySetup = () => ({ if ( persistedQueryConfig && persistedQueryConfig.redis - && persistedQueryConfig.redis.port === ports.redis - && persistedQueryConfig.redis.localhost === 'localhost' + && persistedQueryConfig.redis.port === `${ ports.redis }` + && persistedQueryConfig.redis.host === 'localhost' ) { task.skip(); return; diff --git a/build-packages/magento-scripts/lib/tasks/theme/setup-themes.js b/build-packages/magento-scripts/lib/tasks/theme/setup-themes.js index 306124c5..c9e0e2f1 100644 --- a/build-packages/magento-scripts/lib/tasks/theme/setup-themes.js +++ b/build-packages/magento-scripts/lib/tasks/theme/setup-themes.js @@ -5,7 +5,7 @@ const symlinkTheme = require('./symlink-theme'); const installTheme = require('./install-theme'); const setupPersistedQuery = require('./setup-persisted-query'); const upgradeMagento = require('../magento/setup-magento/upgrade-magento'); -const disablePageCache = require('../magento/setup-magento/disable-page-cache'); +const disableFullPageCache = require('../magento/setup-magento/disable-full-page-cache'); const buildTheme = require('./build-theme'); /** @@ -80,7 +80,7 @@ const setupThemes = () => ({ ]) })).concat([ upgradeMagento(), - disablePageCache(), + disableFullPageCache(), setupPersistedQuery() ]) ); diff --git a/build-packages/magento-scripts/lib/util/config-file-validator.js b/build-packages/magento-scripts/lib/util/config-file-validator.js index 6d1e472b..b25627a3 100644 --- a/build-packages/magento-scripts/lib/util/config-file-validator.js +++ b/build-packages/magento-scripts/lib/util/config-file-validator.js @@ -72,6 +72,15 @@ const nginxConfigurationSchema = Joi.object({ configTemplate: Joi.string().optional().custom(fileExistsValidator) }); +/** + * @type {Joi.ObjectSchema} + */ +const varnishConfigurationSchema = Joi.object({ + enabled: Joi.boolean().optional(), + version: Joi.string().optional(), + configTemplate: Joi.string().optional().custom(fileExistsValidator) +}); + /** * @type {Joi.ObjectSchema} */ @@ -101,7 +110,8 @@ const configurationSchema = Joi.object({ mysql: serviceConfigurationSchema.optional(), elasticsearch: serviceConfigurationSchema.optional(), redis: serviceConfigurationSchema.optional(), - composer: composerConfigurationSchema.optional() + composer: composerConfigurationSchema.optional(), + varnish: varnishConfigurationSchema.optional() }); /** diff --git a/build-packages/magento-scripts/lib/util/config-php-json.js b/build-packages/magento-scripts/lib/util/config-php-json.js new file mode 100644 index 00000000..9e5797e9 --- /dev/null +++ b/build-packages/magento-scripts/lib/util/config-php-json.js @@ -0,0 +1,19 @@ +const path = require('path'); +const runPhpCode = require('./run-php'); + +const configPhpToJson = async (projectPath = process.cwd(), { magentoVersion }) => { + const { code, result } = await runPhpCode(`-r "echo json_encode(require '${path.join(projectPath, 'app', 'etc', 'config.php')}');"`, { + magentoVersion + }); + + if (code !== 0) { + throw new Error(result); + } + try { + return JSON.parse(result); + } catch (e) { + throw new Error(`Ooops! Something went wrong when trying to parse app/etc/config.php file!\n\n${e}\n\nFile result: ${result}`); + } +}; + +module.exports = configPhpToJson; diff --git a/build-packages/magento-scripts/lib/util/php-task.js b/build-packages/magento-scripts/lib/util/php-task.js index 3be9b530..03fac34b 100644 --- a/build-packages/magento-scripts/lib/util/php-task.js +++ b/build-packages/magento-scripts/lib/util/php-task.js @@ -1,7 +1,10 @@ const runPhpCode = require('./run-php'); /** - * @type {(command: string, options: { noTitle: boolean }) => import('listr2').ListrTask} + * @type {( + * command: string, + * options: { noTitle: boolean, env: Record } + * ) => import('listr2').ListrTask} */ const phpTask = (command, options = {}) => ({ title: !options.noTitle ? `Running command 'php ${command}` : undefined, @@ -10,7 +13,8 @@ const phpTask = (command, options = {}) => ({ task.output = t; }, throwNonZeroCode: true, - magentoVersion + magentoVersion, + env: options.env }) }); diff --git a/build-packages/magento-scripts/lib/util/run-php.js b/build-packages/magento-scripts/lib/util/run-php.js index e11ab954..ab6d79e0 100644 --- a/build-packages/magento-scripts/lib/util/run-php.js +++ b/build-packages/magento-scripts/lib/util/run-php.js @@ -10,6 +10,7 @@ const { getConfigFromMagentoVersion, defaultConfiguration } = require('../config * @param {() => {}} options.callback * @param {Boolean} options.throwNonZeroCode Throw if command return non 0 code. * @param {String} options.magentoVersion Magento version for config + * @param {Record} options.env Environment variables */ const runPhpCode = async (command, options = {}) => { const { @@ -17,7 +18,12 @@ const runPhpCode = async (command, options = {}) => { magentoVersion = defaultConfiguration.magentoVersion } = options; const { php } = await getConfigFromMagentoVersion(magentoVersion); - const { code, result } = await execAsyncSpawn(`${php.binPath} -c ${php.iniPath} ${command}`, { + let spawnCommand = `${php.binPath} -c ${php.iniPath} ${command}`; + if (options.env && Object.keys(options.env).length > 0) { + const env = Object.entries(options.env).map(([key, value]) => `${key}=${value}`).join(' '); + spawnCommand = `${env} ${spawnCommand}`; + } + const { code, result } = await execAsyncSpawn(spawnCommand, { ...options, withCode: true }); diff --git a/build-packages/magento-scripts/typings/context.d.ts b/build-packages/magento-scripts/typings/context.d.ts index 2f7fd0fe..7db1b4e4 100644 --- a/build-packages/magento-scripts/typings/context.d.ts +++ b/build-packages/magento-scripts/typings/context.d.ts @@ -12,6 +12,7 @@ export interface ListrContext { mysql: number redis: number elasticsearch: number + varnish: number } arch: 'arm64' | 'x64' isArm: boolean diff --git a/build-packages/magento-scripts/typings/index.d.ts b/build-packages/magento-scripts/typings/index.d.ts index 74cbd5fc..97b8128d 100644 --- a/build-packages/magento-scripts/typings/index.d.ts +++ b/build-packages/magento-scripts/typings/index.d.ts @@ -21,6 +21,20 @@ export interface NginxConfiguration extends ServiceWithVersion { configTemplate: string } +export interface VarnishConfiguration extends ServiceWithVersion { + /** + * Enable or disable Varnish in the project + */ + enabled: boolean + + /** + * Configuration file location + * + * @example ./my-varnish-config.vcl + */ + configTemplate: string +} + export interface PHPExtension extends Record { version?: string /** @@ -175,6 +189,11 @@ export interface CMAConfiguration { * Composer configuration */ composer: ServiceWithVersion + + /** + * Varnish configuration + */ + varnish: VarnishConfiguration } /** * Magento configuration diff --git a/sample-packages/magento-2.4.3-p1/composer.json b/sample-packages/magento-2.4.3-p1/composer.json index 63739c4b..835a13f1 100644 --- a/sample-packages/magento-2.4.3-p1/composer.json +++ b/sample-packages/magento-2.4.3-p1/composer.json @@ -24,6 +24,7 @@ "magento/composer-dependency-version-audit-plugin": "~0.1", "magento/composer-root-update-plugin": "~1.1", "magento/product-community-edition": "2.4.3-p1", + "scandipwa/sample-data": "^1.1", "scandipwa/scandipwa": "^0.0.1" }, "autoload": { @@ -96,4 +97,4 @@ ] } } -} \ No newline at end of file +} diff --git a/sample-packages/magento-2.4.3-p1/composer.lock b/sample-packages/magento-2.4.3-p1/composer.lock index 0feca09b..0e5a7fe4 100644 --- a/sample-packages/magento-2.4.3-p1/composer.lock +++ b/sample-packages/magento-2.4.3-p1/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e0084d53f060d5757100d263802db975", + "content-hash": "bac68cacfbd0b5ba45ce6220fd0fcb0e", "packages": [ { "name": "2tvenom/cborencode", @@ -20510,6 +20510,40 @@ }, "time": "2020-11-19T14:00:34+00:00" }, + { + "name": "scandipwa/sample-data", + "version": "1.1.7", + "source": { + "type": "git", + "url": "https://github.com/scandipwa/sample-data.git", + "reference": "adbb1f89788e68eb11f8f9c9537779734dccb08c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/scandipwa/sample-data/zipball/adbb1f89788e68eb11f8f9c9537779734dccb08c", + "reference": "adbb1f89788e68eb11f8f9c9537779734dccb08c", + "shasum": "" + }, + "require": { + "magento/magento2-base": "^2.3.2" + }, + "type": "magento2-module", + "autoload": { + "files": [ + "src/registration.php" + ], + "psr-4": { + "ScandiPWA\\SampleData\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "Sample data for ScandiPWA", + "support": { + "email": "info@scandiweb.com", + "source": "https://github.com/scandipwa/sample-data/tree/1.1.7" + }, + "time": "2021-09-29T15:25:43+00:00" + }, { "name": "scandipwa/scandipwa", "version": "0.0.1", @@ -29578,5 +29612,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/sample-packages/magento-2.4.3/cma.js b/sample-packages/magento-2.4.3/cma.js index b2f2bfa0..f0388624 100644 --- a/sample-packages/magento-2.4.3/cma.js +++ b/sample-packages/magento-2.4.3/cma.js @@ -10,5 +10,9 @@ module.exports = { mode: 'developer', edition: 'community' }, - configuration: {} + configuration: { + varnish: { + enabled: false + } + } }; diff --git a/sample-packages/magento-2.4.3/composer.json b/sample-packages/magento-2.4.3/composer.json index d378c759..261b389c 100644 --- a/sample-packages/magento-2.4.3/composer.json +++ b/sample-packages/magento-2.4.3/composer.json @@ -23,6 +23,7 @@ "magento/composer-dependency-version-audit-plugin": "~0.1", "magento/composer-root-update-plugin": "~1.1", "magento/product-community-edition": "2.4.3", + "scandipwa/sample-data": "^1.1", "scandipwa/scandipwa": "^0.0.1" }, "autoload": { diff --git a/sample-packages/magento-2.4.3/composer.lock b/sample-packages/magento-2.4.3/composer.lock index 907a7539..f208b8a5 100644 --- a/sample-packages/magento-2.4.3/composer.lock +++ b/sample-packages/magento-2.4.3/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ca84b0eb6d6d2c61a2b161fcb4b34050", + "content-hash": "36fbe8e8c0362c2c8973518e73d0026b", "packages": [ { "name": "2tvenom/cborencode", @@ -19881,6 +19881,40 @@ }, "time": "2020-11-19T14:00:34+00:00" }, + { + "name": "scandipwa/sample-data", + "version": "1.1.7", + "source": { + "type": "git", + "url": "https://github.com/scandipwa/sample-data.git", + "reference": "adbb1f89788e68eb11f8f9c9537779734dccb08c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/scandipwa/sample-data/zipball/adbb1f89788e68eb11f8f9c9537779734dccb08c", + "reference": "adbb1f89788e68eb11f8f9c9537779734dccb08c", + "shasum": "" + }, + "require": { + "magento/magento2-base": "^2.3.2" + }, + "type": "magento2-module", + "autoload": { + "files": [ + "src/registration.php" + ], + "psr-4": { + "ScandiPWA\\SampleData\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "Sample data for ScandiPWA", + "support": { + "email": "info@scandiweb.com", + "source": "https://github.com/scandipwa/sample-data/tree/1.1.7" + }, + "time": "2021-09-29T15:25:43+00:00" + }, { "name": "scandipwa/scandipwa", "version": "0.0.1", @@ -28967,5 +29001,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" }