From 1ca856ed58ab2585d4a545a791e22d2321651031 Mon Sep 17 00:00:00 2001 From: Thomas De Marez Date: Wed, 22 May 2024 09:58:11 +0200 Subject: [PATCH 1/3] let the Craft deploy fail when a command fails --- recipe/craftcms.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/recipe/craftcms.php b/recipe/craftcms.php index 96c5e7596..2fce4eda8 100644 --- a/recipe/craftcms.php +++ b/recipe/craftcms.php @@ -27,9 +27,11 @@ * Run a craft command. * * Supported options: + * - 'showOutput': Show the output of the command if given. * * @param string $command The craft command (with cli options if any). * @param array $options The options that define the behaviour of the command. + * * @return callable A function that can be used as a task. */ function craft($command, $options = []) @@ -39,14 +41,10 @@ function craft($command, $options = []) throw new \Exception('Your .env file is empty! Cannot proceed.'); } - try { - $output = run("cd {{release_path}} && {{bin/php}} craft $command"); + $output = run("{{bin/php}} {{release_path}}/craft $command"); - if (in_array('showOutput', $options)) { - writeln("$output"); - } - } catch (\Throwable $e) { - writeln("{$e->getMessage()}"); + if (in_array('showOutput', $options)) { + writeln("$output"); } }; } From 453f692b03f80d4651ca75e9c7643b3b05c192a9 Mon Sep 17 00:00:00 2001 From: Thomas De Marez Date: Wed, 22 May 2024 11:26:32 +0200 Subject: [PATCH 2/3] add craft cache, setup and garbage collection commands --- recipe/craftcms.php | 86 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/recipe/craftcms.php b/recipe/craftcms.php index 2fce4eda8..4a6530e8c 100644 --- a/recipe/craftcms.php +++ b/recipe/craftcms.php @@ -22,12 +22,12 @@ 'web/cpresources', ]); - /** * Run a craft command. * * Supported options: * - 'showOutput': Show the output of the command if given. + * - 'interactive': Don't append the --interactive=0 flag to the command. * * @param string $command The craft command (with cli options if any). * @param array $options The options that define the behaviour of the command. @@ -41,6 +41,11 @@ function craft($command, $options = []) throw new \Exception('Your .env file is empty! Cannot proceed.'); } + // By default we don't want any command to be interactive + if(! in_array('interactive', $options)) { + $command .= ' --interactive=0'; + } + $output = run("{{bin/php}} {{release_path}}/craft $command"); if (in_array('showOutput', $options)) { @@ -49,22 +54,83 @@ function craft($command, $options = []) }; } -desc('Execute craft migrate/all'); -task('craft:migrate/all', craft('migrate/all --interactive=0'))->once(); +/* + * Migrations + */ + +desc('Runs all pending Craft, plugin, and content migrations'); +task('craft:migrate/all', craft('migrate/all')); + +desc('Upgrades Craft by applying new migrations'); +task('craft:migrate/up', craft('migrate/up')); + +/* + * Generate keys + */ + +desc('Generates a new application ID and saves it in the `.env` file'); +task('craft:setup/app-id', craft('setup/app-id')); + +desc('Generates a new security key and saves it in the `.env` file'); +task('craft:setup/security-key', craft('setup/security-key')); + +/* + * Project config + */ + +desc('Applies project config file changes.'); +task('craft:project-config/apply', craft('project-config/apply')); + +/* + * Caches + */ + +desc('Flushes all caches registered in the system'); +task('craft:cache/flush-all', craft('cache/flush-all')); + +desc('Clear all caches'); +task('craft:clear-caches/all', craft('clear-caches/all')); + +desc('Clear all Asset caches'); +task('craft:clear-caches/asset', craft('clear-caches/asset')); + +desc('Clear all Asset indexing data'); +task('craft:clear-caches/asset-indexing-data', craft('clear-caches/asset-indexing-data')); -desc('Execute craft project-config/apply'); -task('craft:project-config/apply', craft('project-config/apply --interactive=0'))->once(); +desc('Clear all compiled classes'); +task('craft:clear-caches/compiled-classes', craft('clear-caches/compiled-classes')); -desc('Execute craft clear-caches/all'); -task('craft:clear-caches/all', craft('clear-caches/all --interactive=0'))->once(); +desc('Clear all compiled templates'); +task('craft:clear-caches/compiled-templates', craft('clear-caches/compiled-templates')); -desc('deploy'); +desc('Clear all control panel resources'); +task('craft:clear-caches/cp-resources', craft('clear-caches/cp-resources')); + +desc('Clear all data caches'); +task('craft:clear-caches/data', craft('clear-caches/data')); + +desc('Clear all temp files'); +task('craft:clear-caches/temp-files', craft('clear-caches/temp-files')); + +/* + * Garbage collection + */ + +desc('Runs garbage collection'); +task('craft:gc', craft('gc --delete-all-trashed=1 --silent-exit-on-exception=1', ['showOutput'])); + +/* + * Main deploy + */ + +desc('Deploys Craft CMS'); task('deploy', [ 'deploy:prepare', 'deploy:vendors', - 'craft:clear-caches/all', + 'craft:clear-caches/compiled-classes', 'craft:migrate/all', 'craft:project-config/apply', + 'craft:gc', + 'craft:clear-caches/all', 'deploy:publish', ]); - From 0468cbc5c7a068c6508491848a520b4dc585787f Mon Sep 17 00:00:00 2001 From: Thomas De Marez Date: Wed, 22 May 2024 14:36:48 +0200 Subject: [PATCH 3/3] generate docs --- docs/recipe/craftcms.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/recipe/craftcms.md b/docs/recipe/craftcms.md index 9ba91c749..5142b9dfe 100644 --- a/docs/recipe/craftcms.md +++ b/docs/recipe/craftcms.md @@ -99,10 +99,18 @@ Overrides [writable_dirs](/docs/recipe/deploy/writable.md#writable_dirs) from `r ## Tasks +### craft:gc +[Source](https://github.com/deployphp/deployer/blob/master/recipe/craftcms.php#L120) + +Runs garbage collection. + + + + ### deploy -[Source](https://github.com/deployphp/deployer/blob/master/recipe/craftcms.php#L64) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/craftcms.php#L127) -deploy. +Deploys Craft CMS.