Skip to content

refactor: move the config-hash helpers to internal/confighash - #14405

Merged
ndeloof merged 1 commit into
docker:mainfrom
ndeloof:internal-confighash
Oct 29, 2026
Merged

ndeloof merged 1 commit into
docker:mainfrom
ndeloof:internal-confighash

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Moves the ServiceHash, NetworkHash and VolumeHash helpers out of the exported API of pkg/compose into a new internal/confighash package, without changing a single computed hash.

Context

These helpers compute the config-hash labels that Compose stamps on the containers, networks and volumes it creates, and compares on the next run to decide whether a resource must be recreated. They only serve Compose's own change detection, yet they are exported from pkg/compose and therefore part of the public surface of the /v5 module. This is one of the items of the "Public surface" section of #14396.

What the PR brings

  • The three helpers (and their key-order pinning logic and tests) now live in internal/confighash. Callers in pkg/compose and cmd/compose only get a qualified call, nothing else changes there.
  • The hashes are byte-for-byte identical. They are persisted in labels of existing resources, so any change would recreate everyone's services on the next up. The golden-values test that already pinned known hashes moves with the code and passes unchanged, and compose config --hash '*' run on a sample project with the binary built from main and from this branch prints the same output.
  • The code had a single dependency on its former package, the unexported sortedKeys helper. Rather than exporting it or sharing it, the helper's one use is replaced by slices.Sorted(maps.Keys(...)), which orders string keys identically; sortedKeys stays untouched in reconcile.go for its other callers.
  • This removes exported symbols from the /v5 module: compose.ServiceHash, compose.NetworkHash and compose.VolumeHash. That is the intent of the epic item.
  • Deliberately out of scope: Plan, Operation, ObservedState and Graph, which will leave the exported API with the plan-engine extraction, to avoid churn in the files where other PRs are open.

Why this is the right next brick

It is a pure move with no dependency on the rest of pkg/compose, so it shrinks the public surface with no behavioral risk and no conflict with the in-flight reconcile work: the diff in those files is limited to the call sites.

Part of #14396

🤖 Generated with Claude Code

ServiceHash, NetworkHash and VolumeHash only serve Compose's own change
detection (the config-hash labels stamped on containers, networks and
volumes); they have no business being part of the exported API of
pkg/compose. Move them, with their tests, to internal/confighash.

The hashes are byte-for-byte unchanged (the golden values test moves with
the code, and `compose config --hash` prints the same output before and
after). The only dependency on the package they came from, a sorted-keys
helper, is replaced by slices.Sorted(maps.Keys(...)).

This removes exported symbols from the /v5 module: compose.ServiceHash,
compose.NetworkHash and compose.VolumeHash.

Part of docker#14396

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested review from a team as code owners October 28, 2026 06:55

@docker-agent docker-agent 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.

Assessment: 🟢 APPROVE

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ndeloof
ndeloof merged commit fc55a94 into docker:main Oct 29, 2026
63 of 64 checks passed
@ndeloof
ndeloof deleted the internal-confighash branch October 29, 2026 07:20
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.

3 participants