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: add rule to catch multiple conflicting instructions used in the same stage #4913

Merged

Conversation

jsternberg
Copy link
Collaborator

This linter rule catches when ENTRYPOINT, CMD, and HEALTHCHECK are used
multiple times in the same stage. This is because the last usage of each
of these overrides the other usages which makes it so the earlier usage
is ignored and unnecessary.

@jsternberg jsternberg force-pushed the lint-multiple-instructions-disallowed branch 2 times, most recently from fecc7ad to 7dbab0c Compare May 13, 2024 16:12
@jsternberg jsternberg marked this pull request as ready for review May 13, 2024 20:54
@jsternberg jsternberg force-pushed the lint-multiple-instructions-disallowed branch 2 times, most recently from 3dd18c6 to 7dbab0c Compare May 13, 2024 21:09
@@ -904,6 +903,10 @@ type dispatchState struct {
// workdirSet is set to true if a workdir has been set
// within the current dockerfile.
workdirSet bool

Copy link
Member

Choose a reason for hiding this comment

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

possible follow-up: workdirSet to healthcheck seem like fields with similar usage. I think they could be all combined into one struct that is included here.

IsSet bool
}

func (v *parserLocation) Set(loc []parser.Range) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like * instructionTracker) MarkUsed(loc []parser.Range) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems like a better name to me. Done.

…he same stage

This linter rule catches when ENTRYPOINT, CMD, and HEALTHCHECK are used
multiple times in the same stage. This is because the last usage of each
of these overrides the other usages which makes it so the earlier usage
is ignored and unnecessary.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@jsternberg jsternberg force-pushed the lint-multiple-instructions-disallowed branch from 7dbab0c to 89ce746 Compare May 13, 2024 21:20
@tonistiigi tonistiigi merged commit 6acf12f into moby:master May 13, 2024
69 checks passed
@jsternberg jsternberg deleted the lint-multiple-instructions-disallowed branch May 14, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants