Skip to content

fix: preserve configured repository order during build, lock, and resolution - #2578

Open
trukhinyuri wants to merge 1 commit into
chainguard-dev:mainfrom
trukhinyuri:fix/preserve-repository-order-2559
Open

trukhinyuri wants to merge 1 commit into
chainguard-dev:mainfrom
trukhinyuri:fix/preserve-repository-order-2559

Conversation

@trukhinyuri

Copy link
Copy Markdown

Summary

When multiple repositories provide the same package name and version, APK resolves the first matching repository in /etc/apk/repositories. Previously:

  1. apk.SetRepositories deduplicated via map iteration + slices.Sort, overwriting user-configured repository order with alphabetical sorting.
  2. pkg/build/apk.go and pkg/build/lock.go called uniqify (which also sorts alphabetically) on ic.Contents.Repositories and ic.Contents.BuildRepositories.

This change preserves the first-seen declaration order while deduplicating repositories across SetRepositories, build, and lock, and breaks ties in ResolveWorld / ResolvePackage by repository order when version, pin preference, and provider priority are equal.

Fixes #2559

Verification

  • Added regression tests in pkg/apk/apk/repo_test.go and pkg/build/build_test.go.
  • Ran go test -race -v ./pkg/apk/apk ./pkg/build.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Repository precedence incorrectly changes resolution between differently named virtual providers.

2 open findings
What changed in this PR

Preserves configured repository order during image builds, locking, and package resolution.

Changes:

  • Deduplicates repositories without sorting.
  • Adds repository-order resolution tie-breaking.
  • Adds repository-order regression tests.
File Description
pkg/​build/​apk.go Preserves repository order during builds.
pkg/​build/​lock.go Preserves order in locked configurations.
pkg/​build/​build_test.go Tests build and lock ordering.
pkg/​apk/​apk/​repo.go Tracks repository indexes for resolution.
pkg/​apk/​apk/​repo_test.go Tests resolution tie-breaking.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/apk/apk/repo.go Resolved
Comment thread pkg/build/build_test.go Resolved
@trukhinyuri
trukhinyuri force-pushed the fix/preserve-repository-order-2559 branch 2 times, most recently from 63d629d to fc90ab4 Compare October 14, 2026 08:56
@trukhinyuri
trukhinyuri force-pushed the fix/preserve-repository-order-2559 branch from fc90ab4 to 84a50e8 Compare November 30, 2026 02:44
@trukhinyuri

Copy link
Copy Markdown
Author

Rebased onto latest main and resolved the conflict in pkg/build/apk.go with #2520 by keeping runtime repository key separation while deduplicating runtimeRepos, regularRuntimeRepos, and runtimeOnlyRepos in configured order. go test -race ./pkg/apk/apk/... ./pkg/build/... passes.

…s by repo index

Preserve configured repository order across ImageConfiguration locking, extra-repository merging, and package resolution, and break equal-version ties for identical package names by repository order while preserving package-name tie-breaking across distinct virtual providers.

Fixes chainguard-dev#2559

Signed-off-by: Yuri (IURII) Trukhin <yuri@trukhin.com>
@trukhinyuri
trukhinyuri force-pushed the fix/preserve-repository-order-2559 branch from 84a50e8 to c5df509 Compare November 30, 2026 03:50
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.

Repository order is lost, so identical name+version packages always resolve from the alphabetically first repository

2 participants