DL3061: Check for instruction order#763
Merged
lorenzo merged 1 commit intohadolint:masterfrom Feb 25, 2022
Merged
Conversation
Not all dockerfiles are valid just because all instructions in the dockerfile are individually valid. For example, a `RUN` instruction may not preceed the first `FROM` instruction and so on. The new rule DL3061 checks that the order of the instructions is not completely bogus. That means the Dockefile must begin with a comment, an `ARG` or a `FROM` instruction. - Add new rule DL3061 to check for instruction order - Add tests for rule DL3061 - Fix regression tests wrt. rule DL3061 fixes: hadolint#737
|
Hi @lorenzo this rule is too restrictive, it needs to allow for comments. We need the first comment to remain in place because it is a pragma. Without it the docker image build itself will fail. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not all dockerfiles are valid just because all instructions in the
dockerfile are individually valid. For example, a
RUNinstruction maynot precede the first
FROMinstruction and so on. The new rule DL3061checks that the order of the instructions is not completely bogus. That
means the Dockefile must begin with a comment, an
ARGor aFROMinstruction.
fixes: #737
How to verify it
The new rule should alert in case the beginning of a dockerfile messes up instruction order such that a build can not succeed, e.g.:
But should of course not alert in case a Dockerfile is valid and can be build:
Thanks to @ye for suggesting this rule.