deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Task artisan:storage:link -> symlink(): No such file or directory

Open vladles opened this issue 2 years ago • 3 comments

  • Deployer version: ^7.0
  • Deployment OS: Ubuntu 20.04
desc('Deploy the application');
task('deploy', [
    'deploy:info',
    'deploy:setup',
    'deploy:lock',
    'deploy:release',
    'rsync',
    'deploy:shared',
    'deploy:writable',
    'deploy:vendors',
    'artisan:storage:link', // |
    'artisan:config:cache', // |
    'artisan:route:cache',  // |
    'artisan:view:cache',   // | Laravel Specific packages
    'artisan:event:cache',  // |
    'deploy:publish',
]);

I fetched a Exception on artisan:storage:link task. I assume it's because we do shared/writable tasks which make ./current/storage as symlink on ./shared/storage folder. (shared_files and shared_dir set from recipes/laravel.php file, I don't change them) In this case I see just one resolve way.- make the custom link.

Something like this:

task('artisan:storage:custom-link', function(){
    $sharedPath = "{{deploy_path}}/shared";
    run("{{bin/symlink}} $sharedPath/storage/app/public {{release_path}}/public/storage");
});

What do you think? If this is a real problem, maybe add a solution to this problem to the documentation?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

vladles avatar Sep 07 '22 08:09 vladles

How do I implement this to .yaml file? I am using the default snippet from docs. All sample snippets are in php format. It would be great to have both sample snippets in php and yaml.

Update: Okay, I tried something like the following but I don't think it would work at the moment since workflows are run using the default branch and I am working on dev branch:

tasks:
  build:
    - run: "{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage"

lnfel avatar Sep 20 '22 14:09 lnfel

How do I implement this to .yaml file? I am using the default snippet from docs. All sample snippets are in php format. It would be great to have both sample snippets in php and yaml.

Update: Okay, I tried something like the following but I don't think it would work at the moment since workflows are run using the default branch and I am working on dev branch:

tasks:
  build:
    - run: "{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage"

Hello, Sorry for the delay, Did you get it? The example you gave seems to work.

vladles avatar Sep 27 '22 06:09 vladles

Hello, Sorry for the delay, Did you get it? The example you gave seems to work.

Figured out I was using chown on writable_mode which messes up ownership of shared_dirs. For context I was expecting to have username as owner and www-data as group permissions. With writable_mode set to chown, Deployer changes both owner and group to www-data which causes permission error when artisan:storage:link task is run.

I ended up using chmod as writable mode:

# deploy.yaml

config:
  writable_mode: chmod

This allows artisan commands such as artisan:storage:link to run successfully without relying on additional task. Considering that artisan:storage:link also runs the same command.

https://github.com/deployphp/deployer/blob/6d759ef372af18c2a8ec48d4bf5282aee0133b64/recipe/deploy/shared.php#L58

Above code is also similar to the one we have on build task:

tasks:
  build:
    - run: "{{bin/symlink}} {{deploy_path}}/shared/storage/app/public {{release_path}}/public/storage"

Also writable_chmod_mode defaults to 0755 which is working for artisan commands but if we try and visit the website, we will again be welcomed by another permission error similar to the one I have when trying to run artisan:storage:link with writable_mode set to chown:

The stream or file "releases/36/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied.

Setting writable_chmod_mode to 775 fixes this issue and allows www-data group to write to logs/laravel.log.

lnfel avatar Sep 28 '22 07:09 lnfel