serversideup / docker-php

🐳 Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!
https://serversideup.net/open-source/docker-php/
GNU General Public License v3.0
1.75k stars 118 forks source link

Extra space appended to schedule:work - ERROR Command "schedule:work " is not defined. #434

Closed emilebourquin closed 4 weeks ago

emilebourquin commented 1 month ago

Steps To Reproduce

Using this 99-scheduled.sh entrypoint script:

#!/bin/sh
php artisan schedule:work

and this Dockerfile:

FROM serversideup/php:8.3-cli
USER root
RUN install-php-extensions gd
USER www-data
COPY --chmod=755 ./entrypoint.d/99-scheduled.sh /etc/entrypoint.d/99-scheduled.sh
COPY --chown=www-data:www-data ./src /var/www/html

I get this error immediately on startup:

ERROR  Command "schedule:work " is not defined. Did you mean one of these?  

⇂ queue:work  
⇂ schedule:clear-cache  
⇂ schedule:interrupt  
⇂ schedule:list  
⇂ schedule:run  
⇂ schedule:test  
⇂ schedule:work

I have triple-checked that there is no space, newline, etc. after the schedule:work. I even put a basic echo "Hello" on the next line, and the extra space was still added after schedule:work

When I echo the two lines into the file, it works without issue:

FROM serversideup/php:8.3-cli
USER root
RUN install-php-extensions gd
RUN echo "#!/bin/sh" >> /etc/entrypoint.d/99-scheduled.sh \
 && echo "php artisan schedule:work" >> /etc/entrypoint.d/99-scheduled.sh
USER www-data
COPY --chown=www-data:www-data ./src /var/www/html

I realize this may not be a serversideup issue, but I'm not sure what to make of it.

Outcome

I expected the php artisan schedule:work command to work when I use the entrypoint file.

Instead, I get ERROR Command "schedule:work " is not defined.

Affected Docker Images

serversideup/php:8.3-cli

Anything else?

No response

jaydrogers commented 1 month ago

Hey @emilebourquin!

What version of Laravel are you running?

Something like this would come from laravel itself, and not from our images:

ERROR Command "schedule:work " is not defined. Did you mean one of these?

⇂ queue:work
⇂ schedule:clear-cache
⇂ schedule:interrupt
⇂ schedule:list
⇂ schedule:run
⇂ schedule:test
⇂ schedule:work
emilebourquin commented 1 month ago

Hi Jay, I'm using the latest version of Laravel, framework 11.24.0

emilebourquin commented 1 month ago

I do notice that:

php artisan queue:work

also throws the same error, but

php artisan queue:work --tries=3

does not.

jaydrogers commented 1 month ago

Sorry I read that on my mobile quickly and missed one of the most important paragraphs 😆

I wonder if it has something to do with this file:

https://github.com/serversideup/docker-php/blob/main/src/common/usr/local/bin/docker-php-serversideup-entrypoint

Let me look into this and see if I can replicate it. I am working on refactoring that script soon anyways.

⚠️ Warning of using schedule:work in an entrypoint script

I'm not 100% sure of your use case, but just a heads up that you're not getting the best benefits of Docker by running schedule:work as an entrypoint script. This basically makes the schedule:work command unmonitored by an orchestrator and it could potentially fail and you wouldn't know about it.

It's best to run a separate container and pass php artisan queue:work as a COMMAND. This will ensure Docker monitors it.

emilebourquin commented 1 month ago

Thanks Jay. Agreed on running it as a Command. I'm actually trying to get schduled task/queue containers running alongside my app on AWS Fargate, but I was getting some sort of "command not found" error when I was trying to run it as the entry Command.

I'll go back down that road, since it's the proper way to do it. Put this on the back burner, or dump it, as you see fit.

Thanks for your help and for all of your hard work on the images.

jaydrogers commented 1 month ago

You bet, thanks for bringing it to our attention!

You might have to set your command/entrypoint to be this:

php /var/www/html/artisan schedule:work

If the orchestrator doesn't respect the workdir set in the images, then you need to explicitly tell it where /var/www/html/artisan is located.

Hope this helps!

jaydrogers commented 4 weeks ago

Many things are getting improved in v3.4, specifically:

I have everything being prepared on this branch, which will eventually be promoted to "beta".

Check out the docs preview site too. I am starting to assemble the much easier approach to running these advanced Laravel services now that we don't have to worry about S6 getting in the way.

Closing this for now since I think this will be dramatically easier in the next release.

Thanks for reporting this Emile!