Skip to content

linter: add rule to catch multiple conflicting instructions used in the same stage#4913

Merged
tonistiigi merged 1 commit into
moby:masterfrom
jsternberg:lint-multiple-instructions-disallowed
May 13, 2024
Merged

linter: add rule to catch multiple conflicting instructions used in the same stage#4913
tonistiigi merged 1 commit into
moby:masterfrom
jsternberg:lint-multiple-instructions-disallowed

Conversation

@jsternberg
Copy link
Copy Markdown
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 requested review from daghack and tonistiigi May 13, 2024 20:54
@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
// workdirSet is set to true if a workdir has been set
// within the current dockerfile.
workdirSet bool

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@jsternberg jsternberg requested a review from tonistiigi May 13, 2024 21:20
@tonistiigi tonistiigi merged commit 6acf12f into moby:master May 13, 2024
@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.

2 participants