gomod: exclude go module proxy zip cache from generated source deps - #1197
Open
cpuguy83 wants to merge 1 commit into
Open
gomod: exclude go module proxy zip cache from generated source deps#1197cpuguy83 wants to merge 1 commit into
cpuguy83 wants to merge 1 commit into
Conversation
go mod download extracts each module's contents directly under $GOMODCACHE/<module>@<version> in addition to keeping a zip copy under $GOMODCACHE/cache/download/**/@v/*.zip. That zip is redundant once the module is extracted, and duplicating it in generated RPM/DEB source packages needlessly bloats them. GomodDeps now always excludes the zip cache via the existing SourceFilter mechanism, merging it with (and after) any downstream build-time source filter config so a configured filter can't accidentally negate the exclusion via a leading "!" pattern. Adds unit tests exercising the LLB directly plus an integration test that runs a real build through the debug/gomods target to confirm the zip is excluded while the extracted module and its .mod/.info metadata remain, including under a negating downstream filter. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Excludes redundant Go module proxy ZIP archives from generated dependency sources while preserving extracted modules and metadata.
Changes:
- Adds a mandatory, negation-resistant ZIP cache exclusion.
- Adds unit and integration regression coverage.
- Promotes
patternmatcherfor direct test use.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
generator_gomod.go |
Applies the mandatory ZIP exclusion. |
generator_gomod_test.go |
Tests filtering and pattern ordering. |
test/source_test.go |
Verifies real generated filesystem output. |
go.mod |
Promotes the pattern matcher dependency. |
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
What this PR does / why we need it:
go mod downloadextracts each module's contents directly under$GOMODCACHE/<module>@<version>in addition to keeping a redundant zip copy under$GOMODCACHE/cache/download/**/@v/*.zip.GomodDepswas packaging both into generated RPM/DEB source packages, needlessly bloating them with a duplicate copy of every module's sources.GomodDepsnow always excludes that zip cache using the existingSourceFiltermechanism, merging the mandatory exclude with (and after) any downstream build-time source filter config. The exclude is appended last rather than first because exclude patterns are matched in order with.dockerignore-style!negation support: putting it last ensures a downstream-configured filter can't accidentally (or intentionally) re-include the zip cache via a leading!pattern.The extracted module sources and the small
.mod/.info/.ziphashcache metadata files are left untouched; only the bulky.ziparchives are dropped. Other generators (cargohome, pip, nodemodules) are unaffected.Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when the PR gets merged):Fixes #
Special notes for your reviewer:
generator_gomod_test.go) that inspect the generated LLB directly, including a regression test proving a downstream"!cache/download/**/*.zip"filter can't re-include the excluded zip.test/source_test.go) that runs a real build through thedebug/gomodstarget and checks the actual output filesystem, covering both the default-exclude case and the negation-resistance case end-to-end.go.mod:github.com/moby/patternmatcherpromoted from indirect to direct (used by the new negation regression unit test to validate real pattern-matching semantics).