Skip to content

Capture additional metadata in the parse phase #5889

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

Open
reteps opened this issue Apr 5, 2025 · 2 comments
Open

Capture additional metadata in the parse phase #5889

reteps opened this issue Apr 5, 2025 · 2 comments

Comments

@reteps
Copy link

reteps commented Apr 5, 2025

(area/dockerfile, enhancement)

I am trying to build a dockerfile formatter. The current dockerfile parser discards comment nodes from the AST instead of adding them, making a round-trip from AST back to source very tricky. I am hoping to improve the parser so this can be captured.

Would this project accept a PR tracking this additional metadata? This would mean the addition of a comment node, and tests to go with it.

@tonistiigi
Copy link
Member

The current dockerfile parser discards comment nodes from the AST instead of adding them,

It doesn't actually. There is a PrevComment https://github.com/moby/buildkit/blob/v0.20.2/frontend/dockerfile/parser/parser.go#L41 allowing to capture the comment associated with the instruction.

This is used for capturing descriptions for FROM and ARG command and should be used in the future to ignore specific checks for individual commands docker/buildx#3059

I think changes in AST are not generally a big issue but these features need to remain functional (and possible in the future).

@reteps
Copy link
Author

reteps commented Apr 8, 2025

Sorry, I should be more clear. The PrevComment field does not include all comments in the Dockerfile:

  • Comments within steps e.g.
RUN echo "hello" \
    # this is a comment
    && echo "world"
  • Multiline comments (only captures the previous line comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants