Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #373: Run custom command in fpm images without running web server #413

Conversation

cappuc
Copy link
Contributor

@cappuc cappuc commented Aug 14, 2024

Hi, I've the same problem as describe in #373 and I think I found a good solution to fix this problem:

  • use docker-php-serversideup-entrypoint as entrypoint like other images instead of /init from s6
  • don't run the entrypoint.d scripts as s6 service because they are run inside docker-php-serversideup-entrypoint
  • set /init as default docker CMD

I removed the docker-php-serversideup-s6-init since it's not needed anymore

@jaydrogers
Copy link
Member

Thanks for putting some effort to solve this problem.

I have a few things to update in the documentation (I have learned a lot since I wrote it), but one way of solving this is by setting --entrypoint='' on a docker run command or entrypoint: '' on a Docker Compose service. This works great for things like running a queue that doesn't need FPM or NGINX started.

The /init stuff is required by S6 Overlay.

The changes you're proposing might have a big domino effect in other areas if I understand everything correctly.

Do you have a lot of experience with S6 Overlay? I have a bit of experience with it, but there are others who are beyond experts at it 😃

@cappuc
Copy link
Contributor Author

cappuc commented Aug 15, 2024

With this changes we don't need to override the entrypoint with --entrypoint='' anymore and we can simply override the command like we can do with non fpm images.
If we override the docker entrypoint, entrypoint.d scripts are not executed.

I've already used s6 in other projects but I'm not an expert so maybe I'm missing something.
With the tests I did with this changes, it seems to work by moving /init to the command.

Running the image without custom command:

  1. execute entrypoint.d scripts
  2. execute /init wich starts nginx + fpm

Running the image with a custom command:

  1. execute entrypoint.d scripts
  2. execute the custom command without starting nginx and fpm

@jaydrogers
Copy link
Member

That's cool to know. The only thing I am really hesitant on is the docs explicitly say you should set the entrypoint. I've worked on some issues with the founder of S6 and have been called out to "do exactly as I say", which makes sense from an OSS maintainer's perspective.

I'm just really worried about unintentional side effects if we start using S6 the way it's not intended to be used.

https://github.com/just-containers/s6-overlay?tab=readme-ov-file#usage

Screenshot 2024-08-15 at 08 43 30@2x

Thoughts?

@cappuc
Copy link
Contributor Author

cappuc commented Aug 16, 2024

I don't know if there are side effects but I've already used s6 this way in one of my docker images for laravel and it worked.
In this way we can simply override the command (for example to run horizon or the scheduler) and s6 will not start so nginx and php fpm are not booted.

I found this issue just-containers/s6-overlay#587 on s6 and he suggest to call /init conditionally when you want to start s6 services. (I think the code in the last comment is not required because the CMD is passed as argument to the entrypoint so we can set /init as CMD and simply run the argument command)

@jaydrogers
Copy link
Member

I am just adding a note that I haven't forgotten about this -- I've just been slammed with other things.

I really like where this is going. I am hoping to get a direction on this in the next few days to a week. I will keep you posted 👍

@jaydrogers jaydrogers changed the base branch from main to 373-nginx-boots-up-and-starts-accepting-connections-when-running-a-non-default-command September 26, 2024 16:22
…n-running-a-non-default-command' into fix-fpm-custom-command
@jaydrogers jaydrogers merged commit 882c37e into serversideup:373-nginx-boots-up-and-starts-accepting-connections-when-running-a-non-default-command Sep 26, 2024
1 check passed
@jaydrogers
Copy link
Member

I really like what you proposed here! I am moving this into my PR for further testing #437

Thanks a ton for bringing this up. I think it will be a great DX improvement 👍

jaydrogers added a commit that referenced this pull request Sep 26, 2024
…ehavior (#437)

* Add custom registry support to build command

* Attempted fix for just-containers/s6-overlay#586

* Preprended `fpm` to debug logs

* Revert change back to SIGQUIT for best performance with graceful shutdowns with FPM

* fix fpm with custom command (#413)

Co-authored-by: Jay Rogers <[email protected]>

* Removed undefined PHP_VARIATION warnings

* Added support for running custom commands

* Improved debug notice

* Added deprecation notice

* Revert "Removed undefined PHP_VARIATION warnings"

This reverts commit fbfcc9d.

* Remove undefined variable warnings

---------

Co-authored-by: Fabio Capucci <[email protected]>
jaydrogers added a commit that referenced this pull request Oct 3, 2024
…ehavior (#437)

* Add custom registry support to build command

* Attempted fix for just-containers/s6-overlay#586

* Preprended `fpm` to debug logs

* Revert change back to SIGQUIT for best performance with graceful shutdowns with FPM

* fix fpm with custom command (#413)

Co-authored-by: Jay Rogers <[email protected]>

* Removed undefined PHP_VARIATION warnings

* Added support for running custom commands

* Improved debug notice

* Added deprecation notice

* Revert "Removed undefined PHP_VARIATION warnings"

This reverts commit fbfcc9d.

* Remove undefined variable warnings

---------

Co-authored-by: Fabio Capucci <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants