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

linter: lint rule for using the legacy key/value format with whitespace #4923

Merged
merged 1 commit into from
May 30, 2024

Conversation

jsternberg
Copy link
Collaborator

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.

@jsternberg jsternberg force-pushed the lint-legacy-key-value-env branch 4 times, most recently from 18a8384 to 6be16d1 Compare May 14, 2024 18:02
@tonistiigi tonistiigi requested a review from thaJeztah May 14, 2024 18:46
Comment on lines +634 to +636
FROM scratch
ENV key value
LABEL key value
Copy link
Member

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

Copy link
Member

@thaJeztah thaJeztah left a 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 🤔)

@tonistiigi tonistiigi added this to the v0.14.0 milestone May 28, 2024
@@ -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]{
Copy link
Member

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"

Copy link
Collaborator Author

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.

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 <[email protected]>
@tonistiigi tonistiigi merged commit 71f730f into moby:master May 30, 2024
75 checks passed
@jsternberg jsternberg deleted the lint-legacy-key-value-env branch May 30, 2024 20:03
techknowlogick pushed a commit to go-gitea/gitea that referenced this pull request Jun 21, 2024
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
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Jun 21, 2024
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
techknowlogick pushed a commit to go-gitea/gitea that referenced this pull request Jun 24, 2024
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 <[email protected]>
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Jun 25, 2024
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
luzfcb added a commit to cookiecutter/cookiecutter-django that referenced this pull request Jul 18, 2024
luzfcb added a commit to cookiecutter/cookiecutter-django that referenced this pull request Jul 18, 2024
luzfcb added a commit to cookiecutter/cookiecutter-django that referenced this pull request Jul 19, 2024
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