knuckleswtf / scribe

Generate API documentation for humans from your Laravel codebase.✍
https://scribe.knuckles.wtf/laravel/
MIT License
1.58k stars 280 forks source link

scribe:generate command does not work on Laravel Vapor... due to no local filesystem? #768

Open MartijnDB opened 6 months ago

MartijnDB commented 6 months ago

Scribe version

4.26.0

PHP version

8.2

Framework

Laravel

Framework version

10.34.2

Scribe config

base_url => "https://example.com"
type => "laravel"
laravel.add_routes => false
laravel.docs_url => "/"
try_it_out.base_url => "https://aaa.com"
auth.enabled => true
auth.default => true
auth.name => "Authorization"
last_updated => ""

What happened?

When deploying to vapor the error below occurs. I've tried Attaching Storage https://docs.vapor.build/resources/storage.html#attaching-storage And temporary storage https://docs.vapor.build/resources/storage.html#temporary-storage

This is the code where it is failing. Because (as I see it) it will always select a local filesystem, where vapor does not have/support one: https://github.com/knuckleswtf/scribe/blob/a720537cb6c03e8900d3ef800bdf3f27599e856e/src/Tools/Utils.php#L194

Exception:

Unable to delete file located at: /var/task/.scribe/endpoints/00.yaml.

  at vendor/league/flysystem/src/UnableToDeleteFile.php:24
     20▕     private $reason;
     21▕ 
     22▕     public static function atLocation(string $location, string $reason = '', Throwable $previous = null): UnableToDeleteFile
     23▕     {
  ➜  24▕         $e = new static(rtrim("Unable to delete file located at: {$location}. {$reason}"), 0, $previous);
     25▕         $e->location = $location;
     26▕         $e->reason = $reason;
     27▕ 
     28▕         return $e;

      +19 vendor frames 

  20  artisan:41
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

Docs

shalvah commented 6 months ago

Thanks for the investigation! How would you suggest we resolve this (ideally without adding a configuration item)? That place is only called to delete custom endpoint files, just before writing the new ones to disk, in order to avoid deleting the whole directory. Is there a way to detect the attached storage/a Flysystem adapter?

warespace-sebastian-richter commented 2 months ago

We ran into the same issue. Deployment with vapor fails because lamda is read only on file system. Only storages on vapor are explained here: https://docs.vapor.build/resources/storage.html

frital commented 2 months ago

As i trigger vapor in a Gitlab pipeline, i just created a job before, where i run the scribe generation, and then make the upload (with a artisan command) to a s3 bucket. Obviously, then i adjust the routes for the openapi.yaml file, to read it from the bucket. Working perfect, and i could also install scribe with "--dev" (i'm always trying to reduce the size of my application). Maybe this inspires/helps you.