pusher-http-php icon indicating copy to clipboard operation
pusher-http-php copied to clipboard

Pusher being run at Laravel package:discover resulting in Argument Error

Open williwlwilliwll opened this issue 2 years ago • 7 comments

In my Dockerfile I have a step that installs Composer packages. After the installs are complete an artisan package:discover automatically executes and this errors out because Pusher can't find environment variables that it needs.

Why does Pusher actually get run by the package:discover command? Could I prefix the step in my Dockerfile with some 'temporary' env variables to get the build to succeed e.g. PUSHER_APP_KEY=foo PUSHER_APP_SECRET=bar composer install? Would this present any problems when I later to come set the actual values that I want when running the image as a container?

Cheers!

composer.json

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

Terminal Output

#21 28.30 
#21 28.30    TypeError 
#21 28.30 
#21 28.30   Pusher\Pusher::__construct(): Argument #1 ($auth_key) must be of type string, null given, called in /var/www/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php on line 295
#21 28.30 
#21 28.30   at vendor/pusher/pusher-php-server/src/Pusher.php:63
#21 28.31      59▕      * @param ClientInterface|null $client [optional] - a Guzzle client to use for all HTTP requests
#21 28.31      60▕      *
#21 28.31      61▕      * @throws PusherException Throws exception if any required dependencies are missing
#21 28.31      62▕      */
#21 28.31   ➜  63▕     public function __construct(string $auth_key, string $secret, string $app_id, array $options = [], ClientInterface $client = null)
#21 28.31      64▕     {
#21 28.31      65▕         $this->check_compatibility();
#21 28.31      66▕ 
#21 28.31      67▕         if (!is_null($client)) {

williwlwilliwll avatar Jun 14 '23 17:06 williwlwilliwll

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

stale[bot] avatar Sep 16 '23 22:09 stale[bot]

Please keep this issue open, I think it is a valid question

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you.

williwlwilliwll avatar Sep 18 '23 08:09 williwlwilliwll

I've just encountered the same problem. Seems a straightforward question, strange not to get an answer.

watkit avatar Nov 19 '23 06:11 watkit

@watkit

I have added the following code to my Dockerfile:

RUN export PUSHER_APP_ID="123abc" \
    && export PUSHER_APP_KEY="abc123" \
    && export PUSHER_APP_SECRET="1a2b3c" \
    && curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && composer install \
    && composer clear-cache

This circumvents the problem but it would still be nice to have a response from the project owners about why this is necessary at all.

williwlwilliwll avatar Nov 20 '23 09:11 williwlwilliwll

Ah, good workaround, thanks for sharing! I ended up figuring out a way to maintain a .env file in prod and setting environment variables from there, in a similar vein to your Dockerfile idea, but would be handy for pusher (or laravel for my case) to have a supported way to manage this.

watkit avatar Nov 26 '23 04:11 watkit

I got same problem here, can't install project because of it

Guilhemfuel avatar Dec 03 '23 11:12 Guilhemfuel

I believe this is a result of the integration of Pusher (specifically this library) into the Laravel framework. package:discover registers service providers, and this process may be looking for the values identified in https://github.com/pusher/pusher-http-php/issues/373#issuecomment-1818581459.

You can prevent a library from being discovered with the below:

"extra": {
    "laravel": {
        "dont-discover": [
            "pusher/pusher-php-server"
        ]
    }
}

benw-pusher avatar Mar 26 '24 16:03 benw-pusher