buildkit
buildkit copied to clipboard
Capture additional metadata in the parse phase
(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.
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 https://github.com/docker/buildx/issues/3059
I think changes in AST are not generally a big issue but these features need to remain functional (and possible in the future).
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)