diff --git a/docs/recipe/magento2.md b/docs/recipe/magento2.md index 829a27e75..09a1d024d 100644 --- a/docs/recipe/magento2.md +++ b/docs/recipe/magento2.md @@ -52,6 +52,61 @@ The [deploy](#deploy) task of **Magento 2** consists of: * [deploy:success](/docs/recipe/common.md#deploysuccess) – +In addition the **Magento 2** recipe contains an artifact deployment. +This is a two step process where you first execute + +```php +bin/dep artifact:build [options] [localhost] +``` + +to build an artifact, which then is deployed on a server with + +```php +bin/dep artifact:deploy [host] +``` + +The `localhost` to build the artifact on has to be declared local, so either add +```php +localhost() + ->set('local', true); +``` +to your deploy.php or +```yaml +hosts: + localhost: + local: true +``` +to your deploy yaml. + +The [artifact:build](#artifact:build) command of **Magento 2** consists of: * [build:prepare](/docs/recipe/magento2.md#buildprepare) – Prepare local artifact build +* [build:remove-generated](/docs/recipe/magento2.md#buildremove-generated) – Clears generated files prior to building. +* [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) – Installs vendors +* [magento:compile](/docs/recipe/magento2.md#magentocompile) – Compiles magento di +* [magento:deploy:assets](/docs/recipe/magento2.md#magentodeployassets) – Deploys assets +* [artifact:package](/docs/recipe/magento2.md#artifactpackage) – Packages all relevant files in an artifact. + + + The [artifact:deploy](#artifact:deploy) command of **Magento 2** consists of: +* [artifact:prepare](/docs/recipe/magento2.md#artifactprepare) – Prepares an artifact on the target server + * [deploy:info](/docs/recipe/deploy/info.md#deployinfo) – Displays info about deployment + * [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 + * [artifact:upload](/docs/recipe/magento2.md#artifactupload) – Uploads artifact in release folder for extraction. + * [artifact:extract](/docs/recipe/magento2.md#artifactextract) – Extracts artifact in release path. + * [deploy:additional-shared](/docs/recipe/magento2.md#deployadditional-shared) – Adds additional files and dirs to the list of shared files and dirs + * [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 +* [magento:upgrade:db](/docs/recipe/magento2.md#magentoupgradedb) – Upgrades magento database +* [magento:config:import](/docs/recipe/magento2.md#magentoconfigimport) – Config Import +* [deploy:symlink](/docs/recipe/deploy/symlink.md#deploysymlink) – Creates symlink to release +* [artifact:finish](/docs/recipe/magento2.md#artifactfinish) – Executes the tasks after artifact is released + * [magento:cache:flush](/docs/recipe/magento2.md#magentocacheflush) – Flushes Magento Cache + * [cachetool:clear:opcache](/docs/contrib/cachetool.md#cachetoolclearopcache) – Clears OPcode cache + * [deploy:cleanup](/docs/recipe/deploy/cleanup.md#deploycleanup) – Cleanup old releases + * [deploy:unlock](/docs/recipe/deploy/lock.md#deployunlock) – Unlocks deploy + + The magento2 recipe is based on the [common](/docs/recipe/common.md) recipe. ## Configuration @@ -235,10 +290,9 @@ true ### artifact_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L236) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L263) -artifact deployment section -settings section +The file the artifact is saved to ```php title="Default value" 'artifact.tar.gz' @@ -246,9 +300,9 @@ settings section ### artifact_dir -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L237) - +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L266) +The directory the artifact is saved in ```php title="Default value" 'artifacts' @@ -256,9 +310,10 @@ settings section ### artifact_excludes_file -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L238) - +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L270) +Points to a file with a list of files to exclude from packaging. +The format is as with the `tar --exclude-from=[file]` option ```php title="Default value" 'artifacts/excludes' @@ -266,7 +321,7 @@ settings section ### build_from_repo -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L240) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L273) If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory @@ -276,7 +331,7 @@ false ### repository -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L242) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L276) Overrides [repository](/docs/recipe/common.md#repository) from `recipe/common.php`. @@ -288,9 +343,9 @@ null ### artifact_path -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L244) - +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L279) +The relative path to the artifact file. If the directory does not exist, it will be created ```php title="Default value" if (!testLocally('[ -d {{artifact_dir}} ]')) { @@ -301,9 +356,9 @@ return get('artifact_dir') . '/' . get('artifact_file'); ### bin/tar -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L251) - +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L287) +The location of the tar command. On MacOS you should have installed gtar, as it supports the required settings :::info Autogenerated The value of this configuration is autogenerated on access. ::: @@ -312,14 +367,14 @@ The value of this configuration is autogenerated on access. ### additional_shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L325) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L359) 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#L327) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L361) Array of shared directories that will be added to the default shared_dirs without overriding @@ -329,23 +384,46 @@ 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#L102) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L108) Compiles magento di. -Tasks +To work correctly with artifact deployment, it is necessary to set the MAGE_MODE correctly in `app/etc/config.php` +e.g. +```php +'MAGE_MODE' => 'production' +``` ### magento:deploy:assets -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L108) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L134) Deploys assets. - +To work correctly with artifact deployment it is necessary to set `system/dev/js` , `system/dev/css` and `system/dev/template` +in `app/etc/config.php`, e.g.: +```php +'system' => [ + 'default' => [ + 'dev' => [ + 'js' => [ + 'merge_files' => '1', + 'minify_files' => '1' + ], + 'css' => [ + 'merge_files' => '1', + 'minify_files' => '1' + ], + 'template' => [ + 'minify_html' => '1' + ] + ] + ] +``` ### magento:sync:content_version -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L121) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L147) Syncs content version. @@ -353,7 +431,7 @@ Syncs content version. ### magento:maintenance:enable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L131) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L157) Enables maintenance mode. @@ -361,7 +439,7 @@ Enables maintenance mode. ### magento:maintenance:disable -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L137) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L163) Disables maintenance mode. @@ -369,7 +447,7 @@ Disables maintenance mode. ### magento:config:import -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L143) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L169) Config Import. @@ -377,7 +455,7 @@ Config Import. ### magento:upgrade:db -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L178) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L204) Upgrades magento database. @@ -385,7 +463,7 @@ Upgrades magento database. ### magento:cache:flush -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L205) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L231) Flushes Magento Cache. @@ -393,7 +471,7 @@ Flushes Magento Cache. ### deploy:magento -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L210) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L236) Magento2 deployment operations. @@ -408,7 +486,7 @@ This task is group task which contains next tasks: ### magento:build -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L218) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L244) Magento2 build operations. @@ -421,7 +499,7 @@ This task is group task which contains next tasks: ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L224) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L250) Deploys your project. @@ -437,15 +515,15 @@ This task is group task which contains next tasks: ### artifact:package -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L261) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L298) Packages all relevant files in an artifact. -tasks section + ### artifact:upload -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L271) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L308) Uploads artifact in release folder for extraction. @@ -453,7 +531,7 @@ Uploads artifact in release folder for extraction. ### artifact:extract -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L276) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L313) Extracts artifact in release path. @@ -461,7 +539,7 @@ Extracts artifact in release path. ### build:remove-generated -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L282) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L319) Clears generated files prior to building. @@ -469,18 +547,86 @@ Clears generated files prior to building. ### build:prepare -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L287) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L324) Prepare local artifact build. +### artifact:build +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L349) + +Builds an artifact. + + + + +This task is group task which contains next tasks: +* [build:prepare](/docs/recipe/magento2.md#buildprepare) +* [build:remove-generated](/docs/recipe/magento2.md#buildremove-generated) +* [deploy:vendors](/docs/recipe/deploy/vendors.md#deployvendors) +* [magento:compile](/docs/recipe/magento2.md#magentocompile) +* [magento:deploy:assets](/docs/recipe/magento2.md#magentodeployassets) +* [artifact:package](/docs/recipe/magento2.md#artifactpackage) + + ### deploy:additional-shared -[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L331) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L365) Adds additional files and dirs to the list of shared files and dirs. +### artifact:prepare +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L372) + +Prepares an artifact on the target server. + + + + +This task is group task which contains next tasks: +* [deploy:info](/docs/recipe/deploy/info.md#deployinfo) +* [deploy:setup](/docs/recipe/deploy/setup.md#deploysetup) +* [deploy:lock](/docs/recipe/deploy/lock.md#deploylock) +* [deploy:release](/docs/recipe/deploy/release.md#deployrelease) +* [artifact:upload](/docs/recipe/magento2.md#artifactupload) +* [artifact:extract](/docs/recipe/magento2.md#artifactextract) +* [deploy:additional-shared](/docs/recipe/magento2.md#deployadditional-shared) +* [deploy:shared](/docs/recipe/deploy/shared.md#deployshared) +* [deploy:writable](/docs/recipe/deploy/writable.md#deploywritable) + + +### artifact:finish +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L385) + +Executes the tasks after artifact is released. + + + + +This task is group task which contains next tasks: +* [magento:cache:flush](/docs/recipe/magento2.md#magentocacheflush) +* [cachetool:clear:opcache](/docs/contrib/cachetool.md#cachetoolclearopcache) +* [deploy:cleanup](/docs/recipe/deploy/cleanup.md#deploycleanup) +* [deploy:unlock](/docs/recipe/deploy/lock.md#deployunlock) + + +### artifact:deploy +[Source](https://github.com/deployphp/deployer/blob/master/recipe/magento2.php#L393) + +Actually releases the artifact deployment. + + + + +This task is group task which contains next tasks: +* [artifact:prepare](/docs/recipe/magento2.md#artifactprepare) +* [magento:upgrade:db](/docs/recipe/magento2.md#magentoupgradedb) +* [magento:config:import](/docs/recipe/magento2.md#magentoconfigimport) +* [deploy:symlink](/docs/recipe/deploy/symlink.md#deploysymlink) +* [artifact:finish](/docs/recipe/magento2.md#artifactfinish) + + diff --git a/recipe/magento2.php b/recipe/magento2.php index 056fd7cda..bbb8ffa7c 100644 --- a/recipe/magento2.php +++ b/recipe/magento2.php @@ -98,12 +98,38 @@ set('enable_zerodowntime', true); // Tasks + +// To work correctly with artifact deployment, it is necessary to set the MAGE_MODE correctly in `app/etc/config.php` +// e.g. +// ```php +// 'MAGE_MODE' => 'production' +// ``` desc('Compiles magento di'); task('magento:compile', function () { run("{{bin/php}} {{bin/magento}} setup:di:compile"); run('cd {{release_or_current_path}}/{{magento_dir}} && {{bin/composer}} dump-autoload -o'); }); +// To work correctly with artifact deployment it is necessary to set `system/dev/js` , `system/dev/css` and `system/dev/template` +// in `app/etc/config.php`, e.g.: +// ```php +// 'system' => [ +// 'default' => [ +// 'dev' => [ +// 'js' => [ +// 'merge_files' => '1', +// 'minify_files' => '1' +// ], +// 'css' => [ +// 'merge_files' => '1', +// 'minify_files' => '1' +// ], +// 'template' => [ +// 'minify_html' => '1' +// ] +// ] +// ] +// ``` desc('Deploys assets'); task('magento:deploy:assets', function () { @@ -231,16 +257,25 @@ after('deploy:failed', 'magento:maintenance:disable'); -// artifact deployment section -// settings section +// Artifact deployment section + +// The file the artifact is saved to set('artifact_file', 'artifact.tar.gz'); + +// The directory the artifact is saved in set('artifact_dir', 'artifacts'); + +// Points to a file with a list of files to exclude from packaging. +// The format is as with the `tar --exclude-from=[file]` option set('artifact_excludes_file', 'artifacts/excludes'); + // If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory set('build_from_repo', false); + // Set this value if "build_from_repo" is set to true. The target to deploy must also be set with "--branch", "--tag" or "--revision" set('repository', null); +// The relative path to the artifact file. If the directory does not exist, it will be created set('artifact_path', function () { if (!testLocally('[ -d {{artifact_dir}} ]')) { runLocally('mkdir -p {{artifact_dir}}'); @@ -248,6 +283,7 @@ return get('artifact_dir') . '/' . get('artifact_file'); }); +// The location of the tar command. On MacOS you should have installed gtar, as it supports the required settings set('bin/tar', function () { if (commandExist('gtar')) { return which('gtar'); @@ -257,6 +293,7 @@ }); // tasks section + desc('Packages all relevant files in an artifact.'); task('artifact:package', function() { if (!test('[ -f {{artifact_excludes_file}} ]')) { @@ -309,17 +346,14 @@ }); desc('Builds an artifact.'); -task( - 'artifact:build', - [ +task('artifact:build', [ 'build:prepare', 'build:remove-generated', 'deploy:vendors', 'magento:compile', 'magento:deploy:assets', 'artifact:package', - ] -); +]); // Array of shared files that will be added to the default shared_files without overriding set('additional_shared_files', []); @@ -335,9 +369,7 @@ desc('Prepares an artifact on the target server'); -task( - 'artifact:prepare', - [ +task('artifact:prepare', [ 'deploy:info', 'deploy:setup', 'deploy:lock', @@ -347,30 +379,23 @@ 'deploy:additional-shared', 'deploy:shared', 'deploy:writable', - ] -); +]); desc('Executes the tasks after artifact is released'); -task( - 'artifact:finish', - [ +task('artifact:finish', [ 'magento:cache:flush', 'cachetool:clear:opcache', 'deploy:cleanup', 'deploy:unlock', - ] -); +]); desc('Actually releases the artifact deployment'); -task( - 'artifact:deploy', - [ +task('artifact:deploy', [ 'artifact:prepare', 'magento:upgrade:db', 'magento:config:import', 'deploy:symlink', - 'artifact:finish' - ] -); + 'artifact:finish', +]); fail('artifact:deploy', 'deploy:failed'); diff --git a/src/Documentation/DocGen.php b/src/Documentation/DocGen.php index b12059454..9712c1116 100644 --- a/src/Documentation/DocGen.php +++ b/src/Documentation/DocGen.php @@ -108,7 +108,7 @@ public function gen(string $destination): ?string } return $output; }; - $findTask = function (string $name) use ($recipe): ?DocTask { + $findTask = function (string $name, bool $searchOtherRecipes = true) use ($recipe): ?DocTask { if (array_key_exists($name, $recipe->tasks)) { return $recipe->tasks[$name]; } @@ -119,9 +119,11 @@ public function gen(string $destination): ?string } } } - foreach ($this->recipes as $r) { - if (array_key_exists($name, $r->tasks)) { - return $r->tasks[$name]; + if ($searchOtherRecipes) { + foreach ($this->recipes as $r) { + if (array_key_exists($name, $r->tasks)) { + return $r->tasks[$name]; + } } } return null; @@ -165,24 +167,65 @@ public function gen(string $destination): ?string MARKDOWN; + $map = function (DocTask $task, $ident = '') use (&$map, $findTask, &$intro): void { + foreach ($task->group as $taskName) { + $t = $findTask($taskName); + if ($t !== null) { + $intro .= "$ident* {$t->mdLink()} – $t->desc\n"; + if ($t->group !== null) { + $map($t, $ident . ' '); + } + } + } + }; $deployTask = $findTask('deploy'); if ($deployTask !== null) { $intro .= "The [deploy](#deploy) task of **$brandName** consists of:\n"; - $map = function (DocTask $task, $ident = '') use (&$map, $findTask, &$intro): void { - foreach ($task->group as $taskName) { - $t = $findTask($taskName); - if ($t !== null) { - $intro .= "$ident* {$t->mdLink()} – $t->desc\n"; - if ($t->group !== null) { - $map($t, $ident . ' '); - } - } - } - }; $map($deployTask); } $intro .= "\n\n"; + + $artifactBuildTask = $findTask('artifact:build', false); + $artifactDeployTask = $findTask('artifact:deploy', false); + if ($artifactDeployTask !== null && $artifactBuildTask !== null) { + $intro .= "In addition the **$brandName** recipe contains an artifact deployment.\n"; + $intro .= <<set('local', true); +``` +to your deploy.php or +```yaml +hosts: + localhost: + local: true +``` +to your deploy yaml. + +The [artifact:build](#artifact:build) command of **$brandName** consists of: +MD; + $map($artifactBuildTask); + + $intro .= "\n\n The [artifact:deploy](#artifact:deploy) command of **$brandName** consists of:\n"; + + $map($artifactDeployTask); + + $intro .= "\n\n"; + } } if (count($recipe->require) > 0) { if (is_framework_recipe($recipe)) {