diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index edfa0becc..bb8702a87 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -289,8 +289,18 @@ true ``` +### use_redis_cache_id +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L103) + +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#L265) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L268) The file the artifact is saved to @@ -300,7 +310,7 @@ The file the artifact is saved to ### artifact_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L268) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L271) The directory the artifact is saved in @@ -310,7 +320,7 @@ The directory the artifact is saved in ### artifact_excludes_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L272) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L275) Points to a file with a list of files to exclude from packaging. The format is as with the `tar --exclude-from=[file]` option @@ -321,7 +331,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#L275) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L278) If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory @@ -331,7 +341,7 @@ false ### repository -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L278) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L281) Overrides [repository](/docs/recipe/common.md#repository) from `recipe/common.php`. @@ -343,7 +353,7 @@ null ### artifact_path -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L281) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L284) The relative path to the artifact file. If the directory does not exist, it will be created @@ -356,7 +366,7 @@ return get('artifact_dir') . '/' . get('artifact_file'); ### bin/tar -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L289) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L292) The location of the tar command. On MacOS you should have installed gtar, as it supports the required settings :::info Autogenerated @@ -367,14 +377,14 @@ The value of this configuration is autogenerated on access. ### additional_shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L361) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L364) 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#L363) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L366) Array of shared directories that will be added to the default shared_dirs without overriding @@ -384,7 +394,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#L110) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L113) Compiles magento di. @@ -396,7 +406,7 @@ e.g. ### magento:deploy:assets -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L136) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L139) Deploys assets. @@ -423,7 +433,7 @@ in `app/etc/config.php`, e.g.: ### magento:sync:content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L149) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L152) Syncs content version. @@ -431,7 +441,7 @@ Syncs content version. ### magento:maintenance:enable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L159) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L162) Enables maintenance mode. @@ -439,7 +449,7 @@ Enables maintenance mode. ### magento:maintenance:disable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L165) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L168) Disables maintenance mode. @@ -447,7 +457,7 @@ Disables maintenance mode. ### magento:config:import -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L171) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L174) Config Import. @@ -455,7 +465,7 @@ Config Import. ### magento:upgrade:db -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L206) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L209) Upgrades magento database. @@ -463,7 +473,7 @@ Upgrades magento database. ### magento:cache:flush -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L233) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L236) Flushes Magento Cache. @@ -471,7 +481,7 @@ Flushes Magento Cache. ### deploy:magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L238) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L241) Magento2 deployment operations. @@ -486,7 +496,7 @@ This task is group task which contains next tasks: ### magento:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L246) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L249) Magento2 build operations. @@ -499,7 +509,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L252) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L255) Deploys your project. @@ -515,7 +525,7 @@ This task is group task which contains next tasks: ### artifact:package -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L300) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L303) Packages all relevant files in an artifact. @@ -523,7 +533,7 @@ Packages all relevant files in an artifact. ### artifact:upload -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L310) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L313) Uploads artifact in release folder for extraction. @@ -531,7 +541,7 @@ Uploads artifact in release folder for extraction. ### artifact:extract -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L315) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L318) Extracts artifact in release path. @@ -539,7 +549,7 @@ Extracts artifact in release path. ### build:remove-generated -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L321) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L324) Clears generated files prior to building. @@ -547,7 +557,7 @@ Clears generated files prior to building. ### build:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L326) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L329) Prepare local artifact build. @@ -555,7 +565,7 @@ Prepare local artifact build. ### artifact:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L351) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L354) Builds an artifact. @@ -572,7 +582,7 @@ This task is group task which contains next tasks: ### deploy:additional-shared -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L367) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L370) Adds additional files and dirs to the list of shared files and dirs. @@ -580,16 +590,17 @@ 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#L377) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L381) Update cache id_prefix. -Update cache ip_prefix on deploy so that you are compiling against a fresh cache +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 ### magento:cleanup_cache_prefix -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L404) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L409) Cleanup cache id_prefix env files. @@ -597,7 +608,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#L415) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L422) Prepares an artifact on the target server. @@ -617,7 +628,7 @@ This task is group task which contains next tasks: ### artifact:finish -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L428) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L435) Executes the tasks after artifact is released. @@ -632,7 +643,7 @@ This task is group task which contains next tasks: ### artifact:deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L436) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L443) Actually releases the artifact deployment. diff --git a/recipe/magento2.php b/recipe/magento2.php index fa1489df7..a658ccc1f 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -99,6 +99,9 @@ // 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` @@ -372,27 +375,30 @@ /** * 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 **/ desc('Update cache id_prefix'); task('magento:set_cache_prefix', function () { //get current env config - $envConfigString = run('cat {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); - $envConfig = eval('?>'.$envConfigString); - //set prefix to `alias_releasename_` - $prefixUpdate = get('alias') . '_' . get('release_name') . '_'; - - //update id_prefix to include release name - $envConfig['cache']['frontend']['default']['id_prefix'] = $prefixUpdate; - $envConfig['cache']['frontend']['page_cache']['id_prefix'] = $prefixUpdate; - //Generate configuration array as string - $envConfigStr = ' {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH); - //delete the symlink for env.php - run('rm {{release_or_current_path}}/' . ENV_CONFIG_FILE_PATH); - //link the env to the tmp version - run('{{bin/symlink}} {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); + if (get('use_redis_cache_id')) { + $envConfigString = run('cat {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); + $envConfig = eval('?>' . $envConfigString); + //set prefix to `alias_releasename_` + $prefixUpdate = get('alias') . '_' . get('release_name') . '_'; + + //update id_prefix to include release name + $envConfig['cache']['frontend']['default']['id_prefix'] = $prefixUpdate; + $envConfig['cache']['frontend']['page_cache']['id_prefix'] = $prefixUpdate; + //Generate configuration array as string + $envConfigStr = ' {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH); + //delete the symlink for env.php + run('rm {{release_or_current_path}}/' . ENV_CONFIG_FILE_PATH); + //link the env to the tmp version + run('{{bin/symlink}} {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); + } }); after('deploy:shared', 'magento:set_cache_prefix'); @@ -401,11 +407,13 @@ */ desc('Cleanup cache id_prefix env files'); task('magento:cleanup_cache_prefix', function () { - run('rm {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); - run('rm {{release_or_current_path}}/' . ENV_CONFIG_FILE_PATH); - run('mv {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); - // Symlink shared dir to release dir - run('{{bin/symlink}} {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); + if (get('use_redis_cache_id')) { + run('rm {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); + run('rm {{release_or_current_path}}/' . ENV_CONFIG_FILE_PATH); + run('mv {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH); + // Symlink shared dir to release dir + run('{{bin/symlink}} {{deploy_path}}/shared/' . ENV_CONFIG_FILE_PATH . ' {{release_path}}/' . ENV_CONFIG_FILE_PATH); + } }); after('deploy:magento', 'magento:cleanup_cache_prefix');