From 4bc92927f7ede6613e549c71575768c41b8d9be6 Mon Sep 17 00:00:00 2001 From: Tom Scott-Malden Date: Mon, 21 Nov 2022 11:57:39 +0000 Subject: [PATCH 1/2] DD#0000: feat: Created magento2 deploy code to update cacheKeyId Referece Issue: https://github.com/davidalger/capistrano-magento2/issues/151 --- docs/recipe/magento2.md | 7 +++++++ recipe/magento2.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index ff123ec8e..f1099f292 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -35,6 +35,7 @@ The [deploy](#deploy) task of **Magento 2** consists of: * [deploy:release](/docs/recipe/deploy/release.md#deployrelease) – Prepares release * [deploy:update_code](/docs/recipe/deploy/update_code.md#deployupdate_code) – Updates code * [deploy:shared](/docs/recipe/deploy/shared.md#deployshared) – Creates symlinks for shared files and dirs + * [magento:set_cache_prefix](/docs/recipe/magento2.md#magentoset_cache_prefix) * [deploy:writable](/docs/recipe/deploy/writable.md#deploywritable) – Makes writable dirs * [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) – Installs vendors * [deploy:clear_paths](/docs/recipe/deploy/clear_paths.md#deployclear_paths) – Cleanup files and/or directories @@ -216,6 +217,12 @@ true ## Tasks +### magento:set_cache_prefix +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L194) + +Copy env.php and update the cache id_prefix so that your deployment runs on a fresh cache. +Developed from this issue surfaced in capistrano: [capistrano issue](https://github.com/davidalger/capistrano-magento2/issues/151) + ### magento:compile [Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L92) diff --git a/recipe/magento2.php b/recipe/magento2.php index 84667bffb..635cf94bd 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -190,6 +190,34 @@ } }); +// Deploy without setting maintenance mode if possible +desc('Update cache id_prefix'); +task('magento:set_cache_prefix', function () { + //check and only run if env.php is a symlink + if (test('[ -L {{release_or_current_path}}/app/etc/env.php ]')) { + //get local temp file name + $tmpFilename = tempnam(sys_get_temp_dir(), 'tmp_settings_'); + //download env.php to local temp file + download("{{deploy_path}}/shared/app/etc/env.php", $tmpFilename, ['progress_bar' => false]); + $envConfig = include($tmpFilename); + $prefixUpdate = get('release_name') . '_'; + //update id_prefix to include release name + $envConfig["cache"]["frontend"]["default"]["id_prefix"] = $envConfig["cache"]["frontend"]["default"]["id_prefix"] . $prefixUpdate; + $envConfig["cache"]["frontend"]["page_cache"]["id_prefix"] = $envConfig["cache"]["frontend"]["page_cache"]["id_prefix"] . $prefixUpdate; + + //create temporary config file locally + $envConfigStr = " false]); + //delete local temp file + unlink($tmpFilename); + } +}); +after('deploy:shared', 'magento:set_cache_prefix'); + desc('Flushes Magento Cache'); task('magento:cache:flush', function () { run("{{bin/php}} {{release_or_current_path}}/bin/magento cache:flush"); From 2789436fd26d2c5423731938b4da56b6758668f7 Mon Sep 17 00:00:00 2001 From: Tom Scott-Malden Date: Mon, 21 Nov 2022 12:01:28 +0000 Subject: [PATCH 2/2] DD#0000: feat: Updated docs --- docs/recipe/magento2.md | 24 +++++++++++++----------- recipe/magento2.php | 5 ++++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index f1099f292..0c713dc5c 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -35,7 +35,6 @@ The [deploy](#deploy) task of **Magento 2** consists of: * [deploy:release](/docs/recipe/deploy/release.md#deployrelease) – Prepares release * [deploy:update_code](/docs/recipe/deploy/update_code.md#deployupdate_code) – Updates code * [deploy:shared](/docs/recipe/deploy/shared.md#deployshared) – Creates symlinks for shared files and dirs - * [magento:set_cache_prefix](/docs/recipe/magento2.md#magentoset_cache_prefix) * [deploy:writable](/docs/recipe/deploy/writable.md#deploywritable) – Makes writable dirs * [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) – Installs vendors * [deploy:clear_paths](/docs/recipe/deploy/clear_paths.md#deployclear_paths) – Cleanup files and/or directories @@ -217,12 +216,6 @@ true ## Tasks -### magento:set_cache_prefix -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L194) - -Copy env.php and update the cache id_prefix so that your deployment runs on a fresh cache. -Developed from this issue surfaced in capistrano: [capistrano issue](https://github.com/davidalger/capistrano-magento2/issues/151) - ### magento:compile [Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L92) @@ -279,8 +272,17 @@ Upgrades magento database. +### magento:set_cache_prefix +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L198) + +Update cache id_prefix. + +Update cache ip_prefix on deploy so that your are compiling against a fresh cache +Reference Issue: https://github.com/davidalger/capistrano-magento2/issues/151 + + ### magento:cache:flush -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L194) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L225) Flushes Magento Cache. @@ -288,7 +290,7 @@ Flushes Magento Cache. ### deploy:magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L199) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L230) Magento2 deployment operations. @@ -303,7 +305,7 @@ This task is group task which contains next tasks: ### magento:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L207) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L238) Magento2 build operations. @@ -316,7 +318,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L213) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L244) Deploys your project. diff --git a/recipe/magento2.php b/recipe/magento2.php index 635cf94bd..5b2687527 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -190,7 +190,10 @@ } }); -// Deploy without setting maintenance mode if possible +/** + * Update cache ip_prefix on deploy so that your are compiling against a fresh cache + * Reference Issue: https://github.com/davidalger/capistrano-magento2/issues/151 +**/ desc('Update cache id_prefix'); task('magento:set_cache_prefix', function () { //check and only run if env.php is a symlink