From 3580716bb10e07535dc3a20f8de1154e72a315ed Mon Sep 17 00:00:00 2001 From: Tom Scott-Malden Date: Fri, 26 Apr 2024 14:30:26 +0100 Subject: [PATCH] DD#0000: feat: Update cache prefix to use stage if availble for multi server deploys --- docs/recipe/magento2.md | 112 ++++++++++++++++++++-------------------- recipe/magento2.php | 13 +++-- 2 files changed, 64 insertions(+), 61 deletions(-) diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index 33fedf7a5..0b8c3dc49 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -33,7 +33,7 @@ The [deploy](#deploy) task of **Magento 2** consists of: * [deploy:setup](/docs/recipe/deploy/setup.md#deploysetup) – Prepares host for deploy * [deploy:lock](/docs/recipe/deploy/lock.md#deploylock) – Locks deploy * [deploy:release](/docs/recipe/deploy/release.md#deployrelease) – Prepares release - * [deploy:update_code](/docs/recipe/shopware.md#deployupdate_code) – + * [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 * [deploy:writable](/docs/recipe/deploy/writable.md#deploywritable) – Makes writable dirs * [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) – Installs vendors @@ -115,7 +115,7 @@ The magento2 recipe is based on the [common](/docs/recipe/common.md) recipe. ## Configuration ### static_content_locales -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L26) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L27) By default setup:static-content:deploy uses `en_US`. To change that, simply put `set('static_content_locales', 'en_US de_DE');` @@ -127,7 +127,7 @@ in you deployer script. ### magento_themes -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L43) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L44) You can also set the themes to run against. By default it'll deploy all themes - `add('magento_themes', ['Magento/luma', 'Magento/backend']);` @@ -151,14 +151,14 @@ set('magento_themes', [ ### static_deploy_options -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L48) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L49) Static content deployment options, e.g. '--no-parent' ### split_static_deployment -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L51) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L52) Deploy frontend and adminhtml together as default @@ -168,7 +168,7 @@ false ### static_content_locales_backend -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L54) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L55) Use the default languages for the backend as default @@ -178,7 +178,7 @@ Use the default languages for the backend as default ### magento_themes_backend -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L58) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L59) backend themes to deploy. Only used if split_static_deployment=true This setting supports the same options/structure as [magento_themes](/docs/recipe/magento2.md#magento_themes) @@ -189,7 +189,7 @@ This setting supports the same options/structure as [magento_themes](/docs/recip ### static_content_jobs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L64) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L65) Also set the number of conccurent jobs to run. The default is 1 Update using: `set('static_content_jobs', '1');` @@ -200,7 +200,7 @@ Update using: `set('static_content_jobs', '1');` ### content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L66) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L67) @@ -210,7 +210,7 @@ return time(); ### magento_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L71) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L72) Magento directory relative to repository root. Use "." (default) if it is not located in a subdirectory @@ -220,7 +220,7 @@ Magento directory relative to repository root. Use "." (default) if it is not lo ### shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L74) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L75) Overrides [shared_files](/docs/recipe/deploy/shared.md#shared_files) from `recipe/deploy/shared.php`. @@ -235,7 +235,7 @@ Overrides [shared_files](/docs/recipe/deploy/shared.md#shared_files) from `recip ### shared_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L78) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L79) Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/deploy/shared.php`. @@ -261,7 +261,7 @@ Overrides [shared_dirs](/docs/recipe/deploy/shared.md#shared_dirs) from `recipe/ ### writable_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L93) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L94) Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `recipe/deploy/writable.php`. @@ -279,7 +279,7 @@ Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `r ### clear_paths -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L100) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L101) Overrides [clear_paths](/docs/recipe/deploy/clear_paths.md#clear_paths) from `recipe/deploy/clear_paths.php`. @@ -298,7 +298,7 @@ Overrides [clear_paths](/docs/recipe/deploy/clear_paths.md#clear_paths) from `re ### bin/magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L109) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L110) @@ -308,7 +308,7 @@ Overrides [clear_paths](/docs/recipe/deploy/clear_paths.md#clear_paths) from `re ### magento_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L111) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L112) @@ -321,7 +321,7 @@ return $matches[0] ?? '2.0'; ### config_import_needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L118) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L119) :::info Autogenerated @@ -332,7 +332,7 @@ The value of this configuration is autogenerated on access. ### database_upgrade_needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L132) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L133) :::info Autogenerated @@ -343,7 +343,7 @@ The value of this configuration is autogenerated on access. ### enable_zerodowntime -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L157) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L158) Deploy without setting maintenance mode if possible @@ -353,7 +353,7 @@ true ### artifact_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L345) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L346) The file the artifact is saved to @@ -363,7 +363,7 @@ The file the artifact is saved to ### artifact_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L348) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L349) The directory the artifact is saved in @@ -373,7 +373,7 @@ The directory the artifact is saved in ### artifact_excludes_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L352) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L353) Points to a file with a list of files to exclude from packaging. The format is as with the `tar --exclude-from=[file]` option @@ -384,7 +384,7 @@ The format is as with the `tar --exclude-from=[file]` option ### build_from_repo -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L355) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L356) If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory @@ -394,7 +394,7 @@ false ### repository -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L358) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L359) Overrides [repository](/docs/recipe/common.md#repository) from `recipe/common.php`. @@ -406,7 +406,7 @@ null ### artifact_path -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L361) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L362) The relative path to the artifact file. If the directory does not exist, it will be created @@ -419,7 +419,7 @@ return get('artifact_dir') . '/' . get('artifact_file'); ### bin/tar -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L369) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L370) The location of the tar command. On MacOS you should have installed gtar, as it supports the required settings :::info Autogenerated @@ -430,14 +430,14 @@ The value of this configuration is autogenerated on access. ### additional_shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L441) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L442) Array of shared files that will be added to the default shared_files without overriding ### additional_shared_dirs -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L443) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L444) Array of shared directories that will be added to the default shared_dirs without overriding @@ -447,7 +447,7 @@ Array of shared directories that will be added to the default shared_dirs withou ## Tasks ### magento:compile -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L167) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L168) Compiles magento di. @@ -459,7 +459,7 @@ e.g. ### magento:deploy:assets -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L193) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L194) Deploys assets. @@ -486,7 +486,7 @@ in `app/etc/config.php`, e.g.: ### magento:deploy:assets:adminhtml -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L210) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L211) Deploys assets for backend only. @@ -494,7 +494,7 @@ Deploys assets for backend only. ### magento:deploy:assets:frontend -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L215) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L216) Deploys assets for frontend only. @@ -502,7 +502,7 @@ Deploys assets for frontend only. ### magento:sync:content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L263) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L264) Syncs content version. @@ -510,7 +510,7 @@ Syncs content version. ### magento:maintenance:enable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L273) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L274) Enables maintenance mode. @@ -518,7 +518,7 @@ Enables maintenance mode. ### magento:maintenance:disable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L279) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L280) Disables maintenance mode. @@ -526,7 +526,7 @@ Disables maintenance mode. ### magento:maintenance:enable-if-needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L285) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L286) Set maintenance mode if needed. @@ -534,7 +534,7 @@ Set maintenance mode if needed. ### magento:config:import -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L292) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L293) Config Import. @@ -542,7 +542,7 @@ Config Import. ### magento:upgrade:db -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L301) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L302) Upgrades magento database. @@ -550,7 +550,7 @@ Upgrades magento database. ### magento:cache:flush -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L311) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L312) Flushes Magento Cache. @@ -558,7 +558,7 @@ Flushes Magento Cache. ### deploy:magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L316) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L317) Magento2 deployment operations. @@ -575,7 +575,7 @@ This task is group task which contains next tasks: ### magento:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L326) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L327) Magento2 build operations. @@ -588,7 +588,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L332) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L333) Deploys your project. @@ -604,7 +604,7 @@ This task is group task which contains next tasks: ### artifact:package -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L380) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L381) Packages all relevant files in an artifact. @@ -612,7 +612,7 @@ Packages all relevant files in an artifact. ### artifact:upload -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L390) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L391) Uploads artifact in release folder for extraction. @@ -620,7 +620,7 @@ Uploads artifact in release folder for extraction. ### artifact:extract -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L395) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L396) Extracts artifact in release path. @@ -628,7 +628,7 @@ Extracts artifact in release path. ### build:remove-generated -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L401) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L402) Clears generated files prior to building. @@ -636,7 +636,7 @@ Clears generated files prior to building. ### build:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L406) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L407) Prepare local artifact build. @@ -644,7 +644,7 @@ Prepare local artifact build. ### artifact:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L431) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L432) Builds an artifact. @@ -661,7 +661,7 @@ This task is group task which contains next tasks: ### deploy:additional-shared -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L447) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L448) Adds additional files and dirs to the list of shared files and dirs. @@ -669,7 +669,7 @@ Adds additional files and dirs to the list of shared files and dirs. ### magento:set_cache_prefix -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L462) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L463) Update cache id_prefix. @@ -683,7 +683,7 @@ after('deploy:magento', 'magento:cleanup_cache_prefix'); ### magento:cleanup_cache_prefix -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L502) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L505) Cleanup cache id_prefix env files. @@ -691,7 +691,7 @@ After successful deployment, move the tmp_env.php file to env.php ready for next ### magento:cron:stop -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L518) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L521) Remove cron from crontab and kill running cron jobs. @@ -703,7 +703,7 @@ To use this feature, add the following to your deployer scripts: ### magento:cron:install -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L534) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L537) Install cron in crontab. @@ -715,7 +715,7 @@ To use this feature, add the following to your deployer scripts: ### artifact:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L540) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L543) Prepares an artifact on the target server. @@ -735,7 +735,7 @@ This task is group task which contains next tasks: ### artifact:finish -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L553) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L556) Executes the tasks after artifact is released. @@ -750,7 +750,7 @@ This task is group task which contains next tasks: ### artifact:deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L562) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L565) Actually releases the artifact deployment. diff --git a/recipe/magento2.php b/recipe/magento2.php index 45a89bbc8..59cfd864b 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -1,4 +1,5 @@ 0 ) { + if (count(get('magento_themes')) > 0) { $themes = array_is_list(get('magento_themes')) ? get('magento_themes') : array_keys(get('magento_themes')); foreach ($themes as $theme) { $themesToCompile .= ' -t ' . $theme; @@ -377,7 +378,7 @@ function magentoDeployAssetsSplit(string $area) // tasks section desc('Packages all relevant files in an artifact.'); -task('artifact:package', function() { +task('artifact:package', function () { if (!test('[ -f {{artifact_excludes_file}} ]')) { throw new GracefulShutdownException( "No artifact excludes file provided, provide one at artifacts/excludes or change location" @@ -398,12 +399,12 @@ function magentoDeployAssetsSplit(string $area) }); desc('Clears generated files prior to building.'); -task('build:remove-generated', function() { +task('build:remove-generated', function () { run('rm -rf generated/*'); }); desc('Prepare local artifact build'); -task('build:prepare', function() { +task('build:prepare', function () { if (!currentHost()->get('local')) { throw new GracefulShutdownException('Artifact can only be built locally, you provided a non local host'); } @@ -464,8 +465,10 @@ function magentoDeployAssetsSplit(string $area) $tmpConfigFile = tempnam(sys_get_temp_dir(), 'deployer_config'); download('{{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH, $tmpConfigFile); $envConfigArray = include($tmpConfigFile); + //check if stage is used for multi server deploy, otherwise use alias + $prefixId = get('stage') ?? get('alias'); //set prefix to `alias_releasename_` - $prefixUpdate = get('alias') . '_' . get('release_name') . '_'; + $prefixUpdate = $prefixId . '_' . get('release_name') . '_'; //check for preload keys and update if (isset($envConfigArray['cache']['frontend']['default']['backend_options']['preload_keys'])) {