diff --git a/composer.json b/composer.json index ccf5d749b..72fc95d7c 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "symfony/polyfill-php80": "^1.22", "symfony/polyfill-php81": "^1.26", "symfony/process": "^5", + "symfony/var-exporter": "^5.4", "symfony/yaml": "^5" }, "require-dev": { @@ -58,8 +59,7 @@ "phpunit/php-code-coverage": "^9.2", "phpunit/phpunit": "^9.3", "slevomat/coding-standard": "^7.0", - "squizlabs/php_codesniffer": "^3.5", - "symfony/var-exporter": "^5.4" + "squizlabs/php_codesniffer": "^3.5" }, "config": { "sort-packages": true, diff --git a/composer.lock b/composer.lock index 1a78969ad..9b5119343 100644 --- a/composer.lock +++ b/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": "a8fcdbe293cf508305b9865ac9821da4", + "content-hash": "63ecf006452d42fbe25f8b5b856876b3", "packages": [ { "name": "evenement/evenement", @@ -2049,6 +2049,79 @@ ], "time": "2022-01-02T09:53:40+00:00" }, + { + "name": "symfony/var-exporter", + "version": "v5.4.21", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-exporter.git", + "reference": "be74908a6942fdd331554b3cec27ff41b45ccad4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/be74908a6942fdd331554b3cec27ff41b45ccad4", + "reference": "be74908a6942fdd331554b3cec27ff41b45ccad4", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-php80": "^1.16" + }, + "require-dev": { + "symfony/var-dumper": "^4.4.9|^5.0.9|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\VarExporter\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Allows exporting any serializable PHP data structure to plain PHP code", + "homepage": "https://symfony.com", + "keywords": [ + "clone", + "construct", + "export", + "hydrate", + "instantiate", + "serialize" + ], + "support": { + "source": "https://github.com/symfony/var-exporter/tree/v5.4.21" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-02-21T19:46:44+00:00" + }, { "name": "symfony/yaml", "version": "v5.4.3", @@ -4775,79 +4848,6 @@ }, "time": "2021-12-12T21:44:58+00:00" }, - { - "name": "symfony/var-exporter", - "version": "v5.4.21", - "source": { - "type": "git", - "url": "https://github.com/symfony/var-exporter.git", - "reference": "be74908a6942fdd331554b3cec27ff41b45ccad4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/be74908a6942fdd331554b3cec27ff41b45ccad4", - "reference": "be74908a6942fdd331554b3cec27ff41b45ccad4", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" - }, - "require-dev": { - "symfony/var-dumper": "^4.4.9|^5.0.9|^6.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\VarExporter\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Allows exporting any serializable PHP data structure to plain PHP code", - "homepage": "https://symfony.com", - "keywords": [ - "clone", - "construct", - "export", - "hydrate", - "instantiate", - "serialize" - ], - "support": { - "source": "https://github.com/symfony/var-exporter/tree/v5.4.21" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-02-21T19:46:44+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.1", diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index 2c9493a2c..e73a8dd95 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -352,18 +352,8 @@ true ``` -### use_redis_cache_id -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L150) - -deploy with auto updating cache index_prefix - -```php title="Default value" -false -``` - - ### artifact_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L336) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L333) The file the artifact is saved to @@ -373,7 +363,7 @@ The file the artifact is saved to ### artifact_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L339) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L336) The directory the artifact is saved in @@ -383,7 +373,7 @@ The directory the artifact is saved in ### artifact_excludes_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L343) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L340) Points to a file with a list of files to exclude from packaging. The format is as with the `tar --exclude-from=[file]` option @@ -394,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#L346) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L343) If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory @@ -404,7 +394,7 @@ false ### repository -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L349) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L346) Overrides [repository](/docs/recipe/common.md#repository) from `recipe/common.php`. @@ -416,7 +406,7 @@ null ### artifact_path -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L352) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L349) The relative path to the artifact file. If the directory does not exist, it will be created @@ -429,7 +419,7 @@ return get('artifact_dir') . '/' . get('artifact_file'); ### bin/tar -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L360) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L357) The location of the tar command. On MacOS you should have installed gtar, as it supports the required settings :::info Autogenerated @@ -440,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#L432) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L429) 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#L434) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L431) Array of shared directories that will be added to the default shared_dirs without overriding @@ -457,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#L160) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L157) Compiles magento di. @@ -469,7 +459,7 @@ e.g. ### magento:deploy:assets -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L186) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L183) Deploys assets. @@ -496,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#L202) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L199) Deploys assets for backend only. @@ -504,7 +494,7 @@ Deploys assets for backend only. ### magento:deploy:assets:frontend -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L207) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L204) Deploys assets for frontend only. @@ -512,7 +502,7 @@ Deploys assets for frontend only. ### magento:sync:content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L255) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L252) Syncs content version. @@ -520,7 +510,7 @@ Syncs content version. ### magento:maintenance:enable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L265) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L262) Enables maintenance mode. @@ -528,7 +518,7 @@ Enables maintenance mode. ### magento:maintenance:disable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L271) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L268) Disables maintenance mode. @@ -536,7 +526,7 @@ Disables maintenance mode. ### magento:maintenance:enable-if-needed -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L277) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L274) Set maintenance mode if needed. @@ -544,7 +534,7 @@ Set maintenance mode if needed. ### magento:config:import -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L284) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L281) Config Import. @@ -552,7 +542,7 @@ Config Import. ### magento:upgrade:db -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L293) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L290) Upgrades magento database. @@ -560,7 +550,7 @@ Upgrades magento database. ### magento:cache:flush -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L302) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L299) Flushes Magento Cache. @@ -568,7 +558,7 @@ Flushes Magento Cache. ### deploy:magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L307) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L304) Magento2 deployment operations. @@ -585,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#L317) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L314) Magento2 build operations. @@ -598,7 +588,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L323) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L320) Deploys your project. @@ -614,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#L371) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L368) Packages all relevant files in an artifact. @@ -622,7 +612,7 @@ Packages all relevant files in an artifact. ### artifact:upload -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L381) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L378) Uploads artifact in release folder for extraction. @@ -630,7 +620,7 @@ Uploads artifact in release folder for extraction. ### artifact:extract -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L386) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L383) Extracts artifact in release path. @@ -638,7 +628,7 @@ Extracts artifact in release path. ### build:remove-generated -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L392) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L389) Clears generated files prior to building. @@ -646,7 +636,7 @@ Clears generated files prior to building. ### build:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L397) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L394) Prepare local artifact build. @@ -654,7 +644,7 @@ Prepare local artifact build. ### artifact:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L422) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L419) Builds an artifact. @@ -671,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#L438) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L435) Adds additional files and dirs to the list of shared files and dirs. @@ -679,17 +669,21 @@ 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#L449) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L450) Update cache id_prefix. Update cache id_prefix on deploy so that you are compiling against a fresh cache Reference Issue: https://github.com/davidalger/capistrano-magento2/issues/151 -use set('use_redis_cache_id') in your deployer script to enable +use add the following to your deployer scripts: +```php +after('deploy:shared', 'magento:set_cache_prefix'); +after('deploy:magento', 'magento:cleanup_cache_prefix'); +``` ### magento:cleanup_cache_prefix -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L482) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L490) Cleanup cache id_prefix env files. @@ -697,7 +691,7 @@ After successful deployment, move the tmp_env.php file to env.php ready for next ### artifact:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L496) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L500) Prepares an artifact on the target server. @@ -717,7 +711,7 @@ This task is group task which contains next tasks: ### artifact:finish -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L509) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L513) Executes the tasks after artifact is released. @@ -732,7 +726,7 @@ This task is group task which contains next tasks: ### artifact:deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L518) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L521) Actually releases the artifact deployment. diff --git a/recipe/magento2.php b/recipe/magento2.php index 2b0f2ece4..7dbe5e0b3 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -146,9 +146,6 @@ // Deploy without setting maintenance mode if possible set('enable_zerodowntime', true); -//deploy with auto updating cache index_prefix -set('use_redis_cache_id', false); - // Tasks // To work correctly with artifact deployment, it is necessary to set the MAGE_MODE correctly in `app/etc/config.php` @@ -443,7 +440,11 @@ function magentoDeployAssetsSplit(string $area) /** * Update cache id_prefix on deploy so that you are compiling against a fresh cache * Reference Issue: https://github.com/davidalger/capistrano-magento2/issues/151 - * use set('use_redis_cache_id') in your deployer script to enable + * use add the following to your deployer scripts: + * ```php + * after('deploy:shared', 'magento:set_cache_prefix'); + * after('deploy:magento', 'magento:cleanup_cache_prefix'); + * ``` **/ desc('Update cache id_prefix'); task('magento:set_cache_prefix', function () { @@ -454,6 +455,17 @@ function magentoDeployAssetsSplit(string $area) //set prefix to `alias_releasename_` $prefixUpdate = get('alias') . '_' . get('release_name') . '_'; + //check for preload keys and update + if (isset($envConfigArray['cache']['frontend']['default']['backend_options']['preload_keys'])) { + $oldPrefix = $envConfigArray['cache']['frontend']['default']['id_prefix']; + $preloadKeys = $envConfigArray['cache']['frontend']['default']['backend_options']['preload_keys']; + $newPreloadKeys = []; + foreach ($preloadKeys as $preloadKey) { + $newPreloadKeys[] = str_replace($oldPrefix, $prefixUpdate, $preloadKey); + } + $envConfigArray['cache']['frontend']['default']['backend_options']['preload_keys'] = $newPreloadKeys; + } + //update id_prefix to include release name $envConfigArray['cache']['frontend']['default']['id_prefix'] = $prefixUpdate; $envConfigArray['cache']['frontend']['page_cache']['id_prefix'] = $prefixUpdate; @@ -470,10 +482,6 @@ function magentoDeployAssetsSplit(string $area) //link the env to the tmp version run('{{bin/symlink}} {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); }); -//get current env config -if (get('use_redis_cache_id')) { - after('deploy:shared', 'magento:set_cache_prefix'); -} /** * After successful deployment, move the tmp_env.php file to env.php ready for next deployment @@ -486,10 +494,6 @@ function magentoDeployAssetsSplit(string $area) // Symlink shared dir to release dir run('{{bin/symlink}} {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); }); -//get current env config -if (get('use_redis_cache_id')) { - after('deploy:magento', 'magento:cleanup_cache_prefix'); -} desc('Prepares an artifact on the target server');