From 71dbbe4c1f8b908626354527c1da9ac1c0dd35f2 Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Fri, 20 Nov 2026 10:11:16 +0000 Subject: [PATCH] Permanently fix Docker cache ownership during Deployer cleanup --- deploy.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/deploy.php b/deploy.php index eda6162..e40339a 100644 --- a/deploy.php +++ b/deploy.php @@ -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');