Skip to content

Commit 10c1442

Browse files
committed
Add shared_dirs_populate option to populate shared dirs from release
1 parent 7bdc3f7 commit 10c1442

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

docs/recipe/deploy/shared.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,20 @@ set('shared_dirs', ['storage']);
2323

2424

2525

26+
### shared_dirs_populate
27+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L18)
28+
29+
When true, populate existing shared dirs with any new files/dirs present in the release.
30+
Useful when new subdirectories are added to the repo over time and should be propagated to shared.
31+
Existing files in shared are never overwritten.
32+
33+
```php title="Default value"
34+
false
35+
```
36+
37+
2638
### shared_files
27-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L20)
39+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L25)
2840

2941
List of files what will be shared between releases.
3042
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']);
3850
## Tasks
3951

4052
### deploy\:shared {#deploy-shared}
41-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L23)
53+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/shared.php#L28)
4254

4355
Creates symlinks for shared files and dirs.
4456

recipe/deploy/shared.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
// ```
1313
set('shared_dirs', []);
1414

15+
// When true, populate existing shared dirs with any new files/dirs present in the release.
16+
// Useful when new subdirectories are added to the repo over time and should be propagated to shared.
17+
// Existing files in shared are never overwritten.
18+
set('shared_dirs_populate', false);
19+
1520
// List of files what will be shared between releases.
1621
// Each release will have symlink to those files stored in {{deploy_path}}/shared dir.
1722
// ```php
@@ -46,6 +51,9 @@
4651
if (test("[ -d $(echo {{release_path}}/$dir) ]")) {
4752
run("cp -r$copyVerbosity {{release_path}}/$dir $sharedPath/" . dirname($dir));
4853
}
54+
} elseif (get('shared_dirs_populate') && test("[ -d $(echo {{release_path}}/$dir) ]")) {
55+
// Populate shared dir with new files/dirs from release without overwriting existing content.
56+
run("cp -r$copyVerbosity --no-dereference --no-clobber {{release_path}}/$dir/. $sharedPath/$dir/");
4957
}
5058

5159
// Remove from source.

0 commit comments

Comments
 (0)