From 10c1442314b926d56332516647ab9b90ea4ab41b Mon Sep 17 00:00:00 2001 From: Adrien Peyre Date: Tue, 2 Jun 2026 15:40:38 +0200 Subject: [PATCH] Add shared_dirs_populate option to populate shared dirs from release --- docs/recipe/deploy/shared.md | 16 ++++++++++++++-- recipe/deploy/shared.php | 8 ++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/recipe/deploy/shared.md b/docs/recipe/deploy/shared.md index 90b2639d0..4fd289fa1 100644 --- a/docs/recipe/deploy/shared.md +++ b/docs/recipe/deploy/shared.md @@ -23,8 +23,20 @@ set('shared_dirs', ['storage']); +### shared_dirs_populate +[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L18) + +When true, populate existing shared dirs with any new files/dirs present in the release. +Useful when new subdirectories are added to the repo over time and should be propagated to shared. +Existing files in shared are never overwritten. + +```php title="Default value" +false +``` + + ### shared_files -[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L20) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L25) List of files what will be shared between releases. Each release will have symlink to those files stored in [deploy_path](/docs/recipe/common.md#deploy_path)/shared dir. @@ -38,7 +50,7 @@ set('shared_files', ['.env']); ## Tasks ### deploy\:shared {#deploy-shared} -[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L23) +[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L28) Creates symlinks for shared files and dirs. diff --git a/recipe/deploy/shared.php b/recipe/deploy/shared.php index a2066fe60..4750f8589 100644 --- a/recipe/deploy/shared.php +++ b/recipe/deploy/shared.php @@ -12,6 +12,11 @@ // ``` set('shared_dirs', []); +// When true, populate existing shared dirs with any new files/dirs present in the release. +// Useful when new subdirectories are added to the repo over time and should be propagated to shared. +// Existing files in shared are never overwritten. +set('shared_dirs_populate', false); + // List of files what will be shared between releases. // Each release will have symlink to those files stored in {{deploy_path}}/shared dir. // ```php @@ -46,6 +51,9 @@ if (test("[ -d $(echo {{release_path}}/$dir) ]")) { run("cp -r$copyVerbosity {{release_path}}/$dir $sharedPath/" . dirname($dir)); } + } elseif (get('shared_dirs_populate') && test("[ -d $(echo {{release_path}}/$dir) ]")) { + // Populate shared dir with new files/dirs from release without overwriting existing content. + run("cp -r$copyVerbosity --no-dereference --no-clobber {{release_path}}/$dir/. $sharedPath/$dir/"); } // Remove from source.