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

feat: activate the watch mode in dev #717

Closed
wants to merge 1 commit into from
Closed

Conversation

94noni
Copy link
Contributor

@94noni 94noni commented Jan 9, 2025

hey

the blog post https://dunglas.dev/2024/11/frankenphp-1-3-massive-performance-improvements-watcher-mode-dedicated-prometheus-metrics-and-more/
the paragraph "File Watchers" talks about this feature watch

Questions:

  1. is it good here? no overhead for prod
  2. otherwise, how to differentiate a worker.Caddyfile from dev or prod ?
    • creating a ENV FRANKENPHP_CONFIG="import dev.worker.Caddyfile" inside the frankenphp_dev
  3. actually what is the best way with current image/container to see live file changes of symfony app?
    • with running docker compose up --watch after docker compose build --no-cache --pull ?

thank you,

@maxhelias maxhelias requested a review from dunglas January 15, 2025 08:41
@dunglas
Copy link
Owner

dunglas commented Jan 16, 2025

The watch mode should only be enabled en dev. It should be useless in prod.

@94noni
Copy link
Contributor Author

94noni commented Jan 17, 2025

yes that was my first idea, will see to change it thx

@94noni 94noni changed the title feat: activate the watch mode feat: activate the watch mode in dev Jan 17, 2025
@94noni
Copy link
Contributor Author

94noni commented Jan 17, 2025

@dunglas @maxhelias i am really unsure of the way to achieve this
does this works? or perhaps something like so ?

worker {
    file ./public/index.php
    env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
    {$WATCH_MODE} # where WATCH_MODE can be defined as "watch" or not defined
}

@@ -63,6 +64,7 @@ RUN set -eux; \
;

COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
COPY --link frankenphp/dev.worker.Caddyfile /etc/caddy/dev.worker.Caddyfile

CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frankenphp is already running in watch mode for dev, if you add the worker for dev (which I think should be in your own Dockerfile, not the one in this repo) it shouldn't run in watch mode here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @deluxetom thx for commenting
I am very new to both caddy and frankenphp
What you mean is that the actual code already watch new code for exemple a php class inside src or a js file inside asset folder ?
Does this PR is useless then ?

thx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think its useless but I think what you're trying to do it out of scope of this repository.
Worker mode isn't meant to be used for development, and watch mode isn't supposed to be used on prod.

What you might want to do is to fork this repository and change the Dockerfile for your own application. This is what I ended up doing on my end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deluxetom is right: the Dockerfile in the symfony-docker project already manages the watch and worker modes.

The Dockerfile builds the project with 3 targets:

  1. The first one, the frankenphp_base build target, is a common target for development and production image. It contains all dependencies which are common to both type of environement
  2. The second one is frankenphp_dev which takes the base one, adds the debugger and add the --watch argument to the frankenphp command
  3. The third one is frankenphp_prod which is independent from the dev one (so the --watch argument is not used) and which downloads dependencies and enables the worker mode through the line ENV FRANKENPHP_CONFIG="import worker.Caddyfile" (this environment variable is read by the main Caddyfile; the worker.Caddyfile enables the worker mode)

It is well designed by default, but it can be forked and adapted as you prefer as @deluxetom said

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oki thx both of you with all your comments
of course after using this repo as base I've tweaked some file and perhaps missed something regarding such watch logic as when testing as I had to rebuild to have y code available
will double check this specifically

in the meantime lets close here if it wont bring value as it should be already the case

thx again !

@94noni 94noni closed this Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants