Repository navigation
utils: match .dockerignore patterns against every parent directory - #3454
Open
SparkDrago05 wants to merge 1 commit into
Open
SparkDrago05 wants to merge 1 commit into
SparkDrago05 wants to merge 1 commit into
Conversation
PatternMatcher.matches() only compared a pattern against the parent prefix with the same number of path components as the pattern. A pattern such as **/cache never matched the parent directory of cache/drop.txt, so files inside an excluded directory were sent in the build context whenever an exception pattern made the walker descend into that directory. Check every parent prefix instead, as moby/patternmatcher's MatchesOrParentMatches does. Both BuildKit and the classic builder exclude these files. Fixes docker#3449 Signed-off-by: SparkDrago05 <huzaifa.farooq05@gmail.com>
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.
Fixes #3449
Problem
PatternMatcher.matches()only compared a pattern against the parent prefix with the same number of components as the pattern. A pattern like**/cachehas two components, so forcache/drop.txt(one parent component) the parent check never ran. When an exception such as!cache/keep.txtmade the walker descend intocache/, every file in it was kept.Fix
Check the pattern against every parent prefix, the same as
MatchesOrParentMatchesin moby/patternmatcher. The Docker CLI and BuildKit use that matcher.Verification
Same context and
.dockerignore(**/cache,!cache/keep.txt) on Docker 29.8.1:cache/keep.txtDOCKER_BUILDKIT=0)cache/keep.txtcache/drop.txt,cache/keep.txtcache/keep.txttest_double_wildcard_dir_with_file_exceptionfails before the change and passes after it. It also covers a nested file (cache/sub/drop.txt).tests/unitpasses. The one exception istest_set_auth_headers_with_dict_and_no_auth_configs, which also fails onmainbecause of local Docker credentials.ruff==0.1.8is clean.#3448 is a separate case. There, docker-py matches the classic builder but not BuildKit. I left it out of this PR and posted details on that issue.