Skip to content

Commit

Permalink
ensure the storage directories laravel expects are created in the sha…
Browse files Browse the repository at this point in the history
…red storage
  • Loading branch information
joelpittet committed Nov 3, 2021
1 parent 6c08422 commit 8e119e9
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions recipes/laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
// Overwrite deploy task.
require_once __DIR__ . '/base.php';

// Override shared directories.
set('shared_dirs', [
'bootstrap/cache',
'storage',
]);

// Build the vendor directory locally.
desc('Run artisan commands');
task('deploy:artisan', function () {
invoke('artisan:storage:link');
invoke('artisan:optimize:clear');
Expand All @@ -18,9 +25,38 @@
invoke('artisan:event:cache');
});

/**
* Create storage directories.
*/
desc('Make initial storage directories.');
task('deploy:create_storage_dirs', function () {
$writable_dirs = [
'bootstrap/cache',
'storage/app',
'storage/app/public',
'storage/framework',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
];

$sharedPath = "{{deploy_path}}/shared";
foreach ($writable_dirs as $dir) {
// Check if shared dir does not exist.
if (!test("[ -d $sharedPath/$dir ]")) {
// Create shared dir if it does not exist.
run("umask 0002; mkdir -p $sharedPath/$dir");
}
}

})->once();
// Before deploy:shared since deploy:symlink is a local task call too and we
// only want this on remote servers.
after('deploy:shared', 'deploy:create_storage_dirs');

// Additional deploy steps for Laravel.
// Before deploy:symlink since there is a local task call too.
before('deploy:symlink', 'deploy:artisan');
after('deploy:create_storage_dirs', 'deploy:artisan');

/**
* Helper tasks overrides from laravel-deployer.
Expand Down

0 comments on commit 8e119e9

Please sign in to comment.