Skip to content

gomod: exclude go module proxy zip cache from generated source deps - #1197

Open
cpuguy83 wants to merge 1 commit into
project-dalec:mainfrom
cpuguy83:cpuguy83-vigilant-carnival
Open

gomod: exclude go module proxy zip cache from generated source deps#1197
cpuguy83 wants to merge 1 commit into
project-dalec:mainfrom
cpuguy83:cpuguy83-vigilant-carnival

Conversation

@cpuguy83

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it:

go mod download extracts each module's contents directly under $GOMODCACHE/<module>@<version> in addition to keeping a redundant zip copy under $GOMODCACHE/cache/download/**/@v/*.zip. GomodDeps was packaging both into generated RPM/DEB source packages, needlessly bloating them with a duplicate copy of every module's sources.

GomodDeps now always excludes that zip cache using the existing SourceFilter mechanism, 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/.ziphash cache metadata files are left untouched; only the bulky .zip archives 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:

  • Added unit tests (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.
  • Added an integration test (test/source_test.go) that runs a real build through the debug/gomods target 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/patternmatcher promoted from indirect to direct (used by the new negation regression unit test to validate real pattern-matching semantics).

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>
Copilot AI balanced review requested due to automatic review settings August 11, 2026 20:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 patternmatcher for 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.

@cpuguy83 cpuguy83 self-assigned this Aug 11, 2026
@cpuguy83 cpuguy83 modified the milestones: v0.22, v0.23 Aug 11, 2026
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