Repository navigation
Fix ADD --exclude having no effect on archive contents with --unpack - #7422
Open
ToniAdreal wants to merge 1 commit into
Open
ToniAdreal wants to merge 1 commit into
ToniAdreal wants to merge 1 commit into
Conversation
When AttemptUnpackDockerCompatibility is set, docopy hands the archive to unpack(), which extracts every entry via chrootarchive.Untar and never sees the FileActionCopy ExcludePatterns: the copy path that honors them is skipped entirely. Thread the patterns into unpack() and filter the tar stream with the same patternmatcher the regular copy path uses, matching entries against their paths inside the archive (so go/doc/** filters go/doc/...). go-archive's own unpack filter is a plain prefix test and cannot express globs like go/doc/**, so the filtering happens in buildkit before the stream reaches UntarUncompressed. Adds regression tests covering glob excludes, a bare directory pattern, the no-exclude path, and non-archive sources. Fixes moby#7376 Signed-off-by: ToniAdreal <184365500+ToniAdreal@users.noreply.github.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 #7376
Problem
ADD --excludepatterns are silently ignored when the added archive is unpacked (--unpack). The same patterns work on the plain-copy path, so a Dockerfile likeADD --exclude='go/doc/**' --unpack archive.tar.gz /deststill extracts the excluded entries.Root cause
When
AttemptUnpackDockerCompatibilityis set,docopyhands the archive tounpack(), which extracts every entry viachrootarchive.Untarand never sees theFileActionCopyExcludePatterns: the copy path that honors them is skipped entirely. The vendored go-archive unpack filter is a plain prefix test and cannot express globs likego/doc/**, so passing the patterns through to it would not work either.Fix
Thread the patterns into
unpack()and filter the tar stream in buildkit with the samepatternmatcherthe regular copy path uses, matching entries against their paths inside the archive (sogo/doc/**filtersgo/doc/...). A barego/docpattern does not over-match siblings likego/docker/...because matching goes through the glob matcher, not a prefix test.Verification
gofmtclean,go vet ./solver/llbsolver/file/cleango test ./solver/llbsolver/file/passes (5 new tests inunpack_test.go: glob exclude, bare directory, no-exclude passthrough, non-archive passthrough, and a direct filterTar test)go test ./frontend/dockerfile/dockerfile2llb/passese4d319dafter rebase; DCO signedNote
@sainimal1ba-hue picked this up on Nov 7 and planned a failing test first. No PR has landed in the week since, so I put this up to keep the issue moving. Happy to hand it over or rework it if you are still on it.