itsgoingd / clockwork

Clockwork - php dev tools in your browser - server-side component
https://underground.works/clockwork
MIT License
5.69k stars 321 forks source link

Connecting to SQL during package discover #577

Closed screw closed 3 weeks ago

screw commented 2 years ago

My app build fails with clockwork during composer install because clockwork tries to access the SQL connection. But the SQL connection is another docker container which is not present during the build.

clockwork.php includes:

'storage' => env('CLOCKWORK_STORAGE', 'sql'),

In my Dockerfile I have:

composer install --no-interaction --classmap-authoritative

which then triggers:

"post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ],

which results in:

 Generating optimized autoload files
#14 52.09 > Illuminate\Foundation\ComposerScripts::postAutoloadDump
#14 52.16 > @php artisan package:discover --ansi
#14 52.83 
#14 52.89 In Exception.php line 18:
#14 52.89                                                                                
#14 52.89   SQLSTATE[08006] [7] could not translate host name "<sql-hostname>" to ad  
#14 52.89   dress: Name does not resolve                                                 
#14 52.89                                                                                
#14 52.89 
#14 52.92 In PDOConnection.php line 40:
#14 52.92                                                                                
#14 52.92   SQLSTATE[08006] [7] could not translate host name "<sql-hostname>" to ad  
#14 52.92   dress: Name does not resolve                                                 
#14 52.92                                                                                
#14 52.92 
#14 52.96 Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Any idea how I can prevent clockwork from trying to access the storage during package discovery?

itsgoingd commented 2 years ago

Hey, how did you identify this as a Clockwork issue? Do you have a full exception trace? The error only mentions PDOConnection.php, which doesn't seem to be a file included in Laravel.

screw commented 2 years ago

Well when I disable package discovery for clockwork, or remove clockwork altogether I don't get any error. Also when I configure clockwork to use files as the storage, the build succeeds.

That's why I thought it is related to clockwork.

itsgoingd commented 2 years ago

So I've been looking into this and I don't think we can do anything to improve the situation here.

Currently we are constructing the storage instance when the Laravel service provider is registered, which causes the database connection to be made. We could do it a little bit later when the service provider is booted, but this does not change anything, since running artisan commands both registers and boots all service providers.

In fact I would consider this a misconfiguration on your part as you are setting Clockwork to use SQL database without having the database available. I would suggest overriding the CLOCKWORK_STORAGE for your CI process to not use database or even fully disabling Clockwork using CLOCKWORK_ENABLE=false.