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

Watch: Support Path Pattern Matching #12544

Closed
davidgfitzgerald opened this issue Feb 10, 2025 · 4 comments · Fixed by #12584
Closed

Watch: Support Path Pattern Matching #12544

davidgfitzgerald opened this issue Feb 10, 2025 · 4 comments · Fixed by #12584
Labels
area/watch Related with watch feature kind/feature

Comments

@davidgfitzgerald
Copy link

davidgfitzgerald commented Feb 10, 2025

Request

It would be nice if the watch path attribute behaved like the ignore attribute. For example, path could accept wildcards such as *.

At the very least it would help to have some more detail in the API documentation adding that (at least for the time being) pattern matching does not work on path.

Reference: https://docs.docker.com/reference/compose-file/develop/

Example

I would like the convenience of being able to do this:

services:
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "5173:5173"
    develop:
        watch:
        - action: rebuild
          path: frontend/*.json
        - action: rebuild
          path: frontend/*.js

instead of the verbose (yet explicit):

services:
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "5173:5173"
    develop:
        watch:
        - action: rebuild
          path: frontend/jsconfig.json
        - action: rebuild
          path: frontend/package-lock.json
        - action: rebuild
          path: frontend/package.json
        - action: rebuild
          path: frontend/eslint.config.js
        - action: rebuild
          path: frontend/svelte.config.js
        - action: rebuild
          path: frontend/tailwind.config.js
        - action: rebuild
          path: frontend/vite.config.js

Nice To Have

Bonus points for allowing multiple path entries in a single rebuild action:

services:
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "5173:5173"
    develop:
        watch:
        - action: rebuild
          path: frontend/*.json frontend/*.js

Currently, passing a space separated list is silently interpreted as a single path. So, the below example (misleadingly) does not match frontend/package.json nor frontend/vite.config.js

        - action: rebuild
          path: frontend/package.json frontend/vite.config.js
@jhrotko
Copy link
Contributor

jhrotko commented Feb 14, 2025

I would propose to introduce a new keyword paths for rebuild and restart actions, since the path has a 1 to 1 relation to target for sync++ actions.
Under this assumption, the new keyword paths you could also have the pattern matching safely as it would support multiple files (as the pattern matching might resolve to more than one file). As for path, we should be careful for the pattern matching; perhaps returning an error explaining the matched files if it resolves to multiple files.

Or we can change path to be either a string or a list in the json schema and during validation make sure the above assumptions. However, I think usability becomes more complicated as there are different conditions for different actions

@davidgfitzgerald
Copy link
Author

@jhrotko paths sounds reasonable, at the slight expense of the user having to understand that both path and paths exist. Which is not obscene by any stretch of the imagination, just slightly more mental overhead for the user.

I guess it's a tradeoff between making the API as smooth as possible for the user and an implementation that actually achieves the desired behaviour. I am guess that extending the behaviour of path has complications on the implementation I am unaware of.

@jhrotko
Copy link
Contributor

jhrotko commented Feb 16, 2025

I created a POC in these branches (feature-wild-star-watch-path):

in these branches the implementation is under the path which can now receive a string or a list of strings and also validates the * pattern matching.

If you want to try, clone my fork/branch and run make build.

in your compose.yml you can write something along the lines

...
develop:
  watch:
    - path: SOME/PATH/*.txt
      action: rebuild
    - path: 
        - FILE1
        - FILE2
      action: restart

you can run with the specific compose build (from the make build) by running

PATH/TO/JHROTKO/FORK/compose/bin/build/docker-compose up --watch

@ndeloof
Copy link
Contributor

ndeloof commented Feb 25, 2025

On #12584 I proposed to keep using a single path as base to monitor filesystem for changes, and introduce a dedicated include attribute so one can declare patterns to restrict which actual file changes should be considered by action:

    develop:
        watch:
        - action: rebuild
          path: frontend
          include:
            - *.json
            - *.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/watch Related with watch feature kind/feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants