Skip to content

Commit

Permalink
DD#0000: feat: Added an option to enable feature
Browse files Browse the repository at this point in the history
  • Loading branch information
valguss committed Mar 10, 2023
1 parent 6341e20 commit f4ef8a1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 55 deletions.
77 changes: 44 additions & 33 deletions docs/recipe/magento2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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`.

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -423,55 +433,55 @@ 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.




### 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.




### 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.




### 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.




### 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.




### 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.




### 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.

Expand All @@ -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.

Expand All @@ -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.

Expand All @@ -515,47 +525,47 @@ 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.




### 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.




### 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.




### 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.




### 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.




### 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.

Expand All @@ -572,32 +582,33 @@ 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.




### 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.

After successful deployment, move the tmp_env.php file to env.php ready for next deployment


### 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.

Expand All @@ -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.

Expand All @@ -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.

Expand Down
52 changes: 30 additions & 22 deletions recipe/magento2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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 = '<?php return ' . var_export($envConfig, true) . ';';
// Touch tmp config
run('[ -f {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH. ' ] || touch {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH);
run('echo $"' . $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 = '<?php return ' . var_export($envConfig, true) . ';';
// Touch tmp config
run('[ -f {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH . ' ] || touch {{deploy_path}}/shared/' . TMP_ENV_CONFIG_FILE_PATH);
run('echo $"' . $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');

Expand All @@ -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');

Expand Down

0 comments on commit f4ef8a1

Please sign in to comment.