Permanently fix Docker cache ownership during Deployer cleanup
This commit is contained in:
+42
@@ -470,3 +470,45 @@ after('deploy:failed', 'deploy:unlock');
|
||||
// Rollback changes the symlink, so refresh PHP-FPM too.
|
||||
after('rollback', 'absdev:php:restart');
|
||||
after('rollback', 'absdev:health');
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Repair Laravel cache ownership before release cleanup
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel writes cache files as www-data (UID 33).
|
||||
| Deployer deletes release directories as mag.
|
||||
| Keep mag as the directory owner and www-data as the group.
|
||||
|
|
||||
*/
|
||||
desc('Repair cache permissions across Deployer releases');
|
||||
|
||||
task('absdev:cache:repair', function (): void {
|
||||
$script = <<<'SH'
|
||||
set -eu
|
||||
|
||||
for release in /var/www/deploy/releases/[0-9]*; do
|
||||
cache="$release/bootstrap/cache"
|
||||
|
||||
[ -d "$cache" ] || continue
|
||||
|
||||
owner=$(stat -c %u "$release")
|
||||
|
||||
chown -R "$owner":33 "$cache"
|
||||
chmod -R u+rwX,g+rwX "$cache"
|
||||
find "$cache" -type d -exec chmod g+s {} +
|
||||
|
||||
echo "Repaired: $cache"
|
||||
done
|
||||
SH;
|
||||
|
||||
run(
|
||||
absdevCompose()
|
||||
. ' exec -T -u root php sh -c '
|
||||
. escapeshellarg($script)
|
||||
);
|
||||
});
|
||||
|
||||
before('deploy:cleanup', 'absdev:cache:repair');
|
||||
after('absdev:laravel:prepare', 'absdev:cache:repair');
|
||||
|
||||
Reference in New Issue
Block a user