-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
linter: lint rule for using the legacy key/value format with whitespace #4923
Conversation
18a8384
to
6be16d1
Compare
FROM scratch | ||
ENV key value | ||
LABEL key value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there were some concerns about warning about these being potentially too strict.
Wondering if we should have a "more permissive" and "more strict" rule. The most problematic ones are when multiple whitespaces are present;
ARG key one two
ENV key one two
Those look very much alike, but ARG
means 3 args are defined, but the ENV
one defines a single key
env with value one two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but left a suggestion (wondering if this one may be too noisy for some if it's by default 🤔)
@@ -105,4 +105,11 @@ var ( | |||
return fmt.Sprintf("Multiple %s instructions should not be used in the same stage because only the last one will be used", instructionName) | |||
}, | |||
} | |||
RuleLegacyKeyValueFormat = LinterRule[func(cmdName string) string]{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should provide some hint that key=value
should be used instead in the message. Most users will not know what is "legacy format"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this message to read differently so now it explicitly mentions the solution in the detailed description.
6be16d1
to
d312e96
Compare
The `ENV` and `LABEL` commands both support using either a whitespace delimited token or one delimited with the equals token. The equals token is preferred because it is more explicit and less ambiguous than using whitespace. The linter rule emits a warning when it sees the whitespace separator used. To facilitate this, the parser was modified to include the separator as a node in the tree. The associated parsing code has also been changed for 3 arguments instead of only 2 per key/value pair. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
d312e96
to
6cfa459
Compare
See https://docs.docker.com/reference/build-checks/legacy-key-value-format/. Fixes these warnings seen during the docker build: ``` 4 warnings found (use --debug to expand): - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 9) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 75) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 76) ``` Introduced in: moby/buildkit#4923
See https://docs.docker.com/reference/build-checks/legacy-key-value-format/. Fixes these warnings seen during the docker build: ``` 4 warnings found (use --debug to expand): - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 9) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 75) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 76) ``` Introduced in: moby/buildkit#4923
Backport #31450 by @silverwind See https://docs.docker.com/reference/build-checks/legacy-key-value-format/. Fixes these warnings seen during the docker build: ``` 4 warnings found (use --debug to expand): - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 9) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 75) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 76) ``` Introduced in: moby/buildkit#4923 Co-authored-by: silverwind <me@silverwind.io>
See https://docs.docker.com/reference/build-checks/legacy-key-value-format/. Fixes these warnings seen during the docker build: ``` 4 warnings found (use --debug to expand): - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 9) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 75) - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 76) ``` Introduced in: moby/buildkit#4923 (cherry picked from commit 996037fb6a61b1a7f9a0a837fd87bbeab9cad154) Conflicts: Dockerfile.rootless trivial context conflict
The old syntax for ENV and LABEL is marked as deprecated in docker buildx v0.14.0 https://docs.docker.com/reference/build-checks/legacy-key-value-format/ moby/buildkit#4923
The old syntax for ENV and LABEL is marked as deprecated in docker buildx v0.14.0 https://docs.docker.com/reference/build-checks/legacy-key-value-format/ moby/buildkit#4923
The old syntax for ENV and LABEL is marked as deprecated in docker buildx v0.14.0 https://docs.docker.com/reference/build-checks/legacy-key-value-format/ moby/buildkit#4923
The
ENV
andLABEL
commands both support using either a whitespace delimited token or one delimited with the equals token. The equals token is preferred because it is more explicit and less ambiguous than using whitespace. The linter rule emits a warning when it sees the whitespace separator used.To facilitate this, the parser was modified to include the separator as a node in the tree. The associated parsing code has also been changed for 3 arguments instead of only 2 per key/value pair.