Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve magento performance, add varnish to setup #97

Merged
merged 19 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6306469
add varnish to setup
ejnshtein May 3, 2022
e91f724
adjust docker config, add some formatting to paths, change mysql to m…
ejnshtein May 3, 2022
de5743f
change docker containers and docker volumes data retrieval from cli t…
ejnshtein May 3, 2022
03aadb3
fix status command failing if no ports is set it docker container set…
ejnshtein May 3, 2022
fbbd06c
add varnish setup to more migrade-db tasks, fix import issue for mysq…
ejnshtein May 5, 2022
c0fd791
update update-env-php logic
ejnshtein May 5, 2022
124d9a0
resolve issue with setup-pq running on every start even if no setup i…
ejnshtein May 5, 2022
be35bf8
update disable-2fa and disable fill_page cache tasks logic plus misc …
ejnshtein May 5, 2022
241b3a8
update stop containers logic to stop all containers of the projects
ejnshtein May 5, 2022
8091309
if varnish is disable, remove http_cache_hosts from env.php while upd…
ejnshtein May 6, 2022
a4dcfe1
stage changes in requirement tasks and setup pq
ejnshtein May 6, 2022
c04abe1
temporarely enable php apcu extension for improving performance
ejnshtein May 6, 2022
ee9ec27
add sample data for sample magento 2.4.3
ejnshtein May 6, 2022
f3cfb74
cs format update-env.php
ejnshtein May 6, 2022
c8861ad
enable opcache in php.ini, enable php apcu and opcache extensions in …
ejnshtein May 10, 2022
c1e21bf
add sample-data for sample magento 2.4.3-p1
ejnshtein May 10, 2022
0c8a9ed
add /var/lib/varnish to tmpfs argument in docker container
ejnshtein May 11, 2022
bf380a4
update cli command output, add new aliases and alias to clean varnish…
ejnshtein May 11, 2022
f498cd5
reorder cli command output a bit
ejnshtein May 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion build-packages/magento-scripts/lib/commands/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
});
};
3 changes: 2 additions & 1 deletion build-packages/magento-scripts/lib/commands/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Available containers:
- mysql
- nginx
- redis
- elasticsearch`);
- elasticsearch
- varnish (if enabled)`);
},
async (argv) => {
const containers = (await docker).getContainers();
Expand Down
54 changes: 45 additions & 9 deletions build-packages/magento-scripts/lib/config/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = async ({ configuration, ssl, host }, config) => {
redis,
mysql,
elasticsearch,
mariadb
mariadb,
varnish
} = configuration;

const {
Expand Down Expand Up @@ -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) {
/**
Expand All @@ -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'
}
};
Expand All @@ -69,18 +69,28 @@ 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 = {}) => {
const dockerConfig = {
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'
Expand Down Expand Up @@ -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'
},
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
};

Expand Down
3 changes: 2 additions & 1 deletion build-packages/magento-scripts/lib/config/get-port-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const getAvailablePorts = () => ({
});

/**
* @type {import('listr2').ListrTask<import('../../typings/context').ListrContext>}
* @type {() => import('listr2').ListrTask<import('../../typings/context').ListrContext>}
*/
const getCachedPorts = () => ({
title: 'Getting cached ports',
Expand All @@ -65,6 +65,7 @@ const getCachedPorts = () => ({
'utf-8'
)
);
ctx.cachedPorts = { ...ports };
} else {
ports = { ...defaultPorts };
}
Expand Down
1 change: 1 addition & 0 deletions build-packages/magento-scripts/lib/config/port-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -2038,3 +2038,5 @@ xdebug.mode=off
<% } %>

<% } %>

apc.enabled=1
Loading