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

frontend: command casing rule check after parsing the ast #5243

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

daghack
Copy link
Collaborator

@daghack daghack commented Aug 12, 2024

addresses @tonistiigi comments in #5240

Currently we're checking the AST for command violations, but typically it is more convenient and correct for these checks to happen at the instruction level. This updates the consistent command casing check to occur after the AST is parsed out into instructions.

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

We need test for this as well that covers #5240

@daghack
Copy link
Collaborator Author

daghack commented Aug 15, 2024

We need test for this as well that covers #5240

Added!

tonistiigi
tonistiigi previously approved these changes Aug 19, 2024
Dockerfile: dockerfile,
BuildErrLocation: 4,
StreamBuildErr: "failed to solve: dockerfile parse error on line 4: ENV requires at least one argument",
UnmarshalBuildErr: "dockerfile parse error on line 4: ENV requires at least one argument",
Copy link
Member

Choose a reason for hiding this comment

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

fyi @jedevc

Copy link
Member

@jedevc jedevc Aug 19, 2024

Choose a reason for hiding this comment

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

SGTM, but if this is a common typo, potentially there should be a more dedicated lint message.

@tonistiigi tonistiigi dismissed their stale review August 19, 2024 07:03

Confused about dash in the example

@daghack daghack force-pushed the heredoc-case-consistent branch 2 times, most recently from 0b1dbfe to 64d84e6 Compare August 19, 2024 15:56
Comment on lines 551 to 554
FROM scratch
RUN -<<'EOT'
env
EOT
Copy link
Member

Choose a reason for hiding this comment

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

Confused about dash in the example

This was a mistake on my hand in the linked ticket, and the - shouldn't have been there (I blindly wrote it out of habit); see #5240 (comment)

So in this case, there's 3 "commands";

  • RUN -<<'EOT' - which will produce an error
  • env - which (at least before this PR) produces both a warning (lowercase) and an error
  • EOT - invalid instruction, but it looks like we bail out before reaching that

i.e., this currently (before this PR) produces;

docker build -<<'EOF'
FROM alpine
RUN -<<'EOT'
env
EOT
EOF

[+] Building 0.1s (1/1) FINISHED                                                                                        docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                    0.0s
 => => transferring dockerfile: 70B                                                                                                     0.0s
 => WARN: ConsistentInstructionCasing: Command 'env' should match the case of the command majority (uppercase) (line 3)                 0.0s

 1 warning found (use docker --debug to expand):
 - ConsistentInstructionCasing: Command 'env' should match the case of the command majority (uppercase) (line 3)
Dockerfile:3
--------------------
   1 |     FROM alpine
   2 |     RUN -<<'EOT'
   3 | >>> env
   4 |     EOT
   5 |
--------------------
ERROR: failed to solve: dockerfile parse error on line 3: ENV requires at least one argument

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/q4mv7723jfvmni1dvj3ptkji2

As the Dockerfile is invalid, to some extent, I'd expect this to;

  • skip printing all linting warnings; they're not relevant if the dockerfile is invalid
  • if possible, detect (all?) invalid syntax issues (i.e. both env as invalid and EOT being an invalid command)
  • ☝️ 🤔 that could become noisy though, because the heredoc may contain many lines, all of which would now be considered an "invalid dockerfile instruction"
  • 👉 so, yes, perhaps still fail early, but if possible, have a useful "did you mean X?" for the invalid here-doc 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I was pretty much just replicating the original failure mode in the tests. That being said, is a fix so that we don't get erroneous rule checks from the contents of the heredoc, and doesn't need to reproduce the dockerfile error in the integration test (which I think the point @tonistiigi was making).

@daghack daghack force-pushed the heredoc-case-consistent branch 3 times, most recently from 1423095 to 128deb2 Compare August 20, 2024 16:47
Signed-off-by: Talon Bowler <talon.bowler@docker.com>
@daghack
Copy link
Collaborator Author

daghack commented Aug 21, 2024

@tonistiigi Updated the test to not be based on the heredoc typo. :)

@thompson-shaun
Copy link
Collaborator

Do we still want to merge this based on the discussions in #5240? @daghack

@daghack
Copy link
Collaborator Author

daghack commented Aug 29, 2024

Do we still want to merge this based on the discussions in #5240? @daghack

I'm inclined, because I generally think removing checks from the AST stage is a net benefit, even if it's not a fix for the issue where it came up. I'll happily defer to @tonistiigi, though.

@tonistiigi tonistiigi merged commit 94d3dae into moby:master Sep 3, 2024
91 checks passed
@daghack daghack deleted the heredoc-case-consistent branch September 4, 2024 06:50
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