Skip to content

Conversation

thaJeztah
Copy link
Member

add internal fork of docker/docker/registry

This adds an internal fork of github.com/docker/docker/registry, taken
at commit moby@f651a5d. Git history was not preserved in this fork,
but can be found using the URLs provided.

This fork was created to remove the dependency on the "Moby" codebase,
and because the CLI only needs a subset of its features. The original
package was written specifically for use in the daemon code, and includes
functionality that cannot be used in the CLI.

- Human readable description for the release notes

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 29.0.0 milestone Jul 24, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jul 24, 2025

This adds an internal fork of [github.com/docker/docker/registry], taken
at commit [moby@f651a5d]. Git history  was not preserved in this fork,
but can be found using the URLs provided.

This fork was created to remove the dependency on the "Moby" codebase,
and because the CLI only needs a subset of its features. The original
package was written specifically for use in the daemon code, and includes
functionality that cannot be used in the CLI.

[github.com/docker/docker/registry]: https://pkg.go.dev/github.com/docker/docker@v28.3.2+incompatible/registry
[moby@49306c6]: https://github.com/moby/moby/tree/49306c607b72c5bf0a8e426f5a9760fa5ef96ea0/registry

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Jul 24, 2025
@thaJeztah thaJeztah marked this pull request as ready for review July 24, 2025 21:17
The CLI does not have information about mirrors, and doesn't
configure them, so we can remove these parts.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
It's not matched anywhere, so we can just return a plain error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
It was only used in a single place; inline it there.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
now that we no longer need to account for mirrors, these were
identical, so just use a single one.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
It was written to be used as validate-func for command-line flags, which
we don't use it for (which for CLI-flags includes normalizing the value).

The validation itself didn't add much; it only checked the registry didn't
start or end with a hyphen (which would still fail when parsing).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The registry.ServiceConfig struct in the API types was meant for the
registry configuration on the daemon side; it has variuos fields we
don't use, defines methods for (un)marshaling JSON, and a custom version
of `net.IPNet`, also to (un)marshal JSON.

None of that is needed, so let's change it to a local type, and implement
a constructor (as we now only have "insecure registries" to care
about).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
    internal/registry/errors.go:26:43: use-any: since Go 1.18 'interface{}' can be replaced by 'any' (revive)
    func invalidParamf(format string, args ...interface{}) error {
                                              ^
    internal/registry/registry_mock_test.go:52:51: use-any: since Go 1.18 'interface{}' can be replaced by 'any' (revive)
    func writeResponse(w http.ResponseWriter, message interface{}, code int) {
                                                      ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

@Benehiko @vvoland PTAL 🤗

Copy link
Member

@Benehiko Benehiko left a comment

Choose a reason for hiding this comment

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

LGTM, i left some comments that might (?) be relevant.

Copy link
Member

Choose a reason for hiding this comment

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

We should look at refactoring this test code, it uses init() which isn't necessary and we can move the using stretchr/testify/assert instead of t.Fatalf.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I didn't look closely at the tests yet. Initially I forked without tests, but then decided to "let's just copy those as well - just in case it's covering some bits that are important"

Copy link
Member

Choose a reason for hiding this comment

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

we import assert in this file but we end up using t.Fatalf instead (perhaps theses should be require instead?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup! See above; depending on what we end up doing with this package (probably should be fully dismantled), we should either fully use assert, or fully stdlib testing - depending on what's needed.

or library packages that only need minimal functionality of an assert library, I try to use stdlib ("zero dependencies!"). But if things get too complicated with that, using an assert library is OK.

Comment on lines +68 to +71
log.G(ctx).WithFields(log.Fields{
"error": err,
"endpoint": endpoint,
}).Infof("Error logging in to endpoint, trying next endpoint")
Copy link
Member

Choose a reason for hiding this comment

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

does this logger actually do something in the CLI?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does; it (currently) falls back to using the default logger if none was set on the context (which I actually want to change in that package - or at least an easier way to set a noplogger / discardlogger);

// GetLogger retrieves the current logger from the context. If no logger is
// available, the default logger is returned.
func GetLogger(ctx context.Context) *Entry {
if logger := ctx.Value(loggerKey{}); logger != nil {
return logger.(*Entry)
}
return L.WithContext(ctx)
}

It's a bit awkward, but log.G is a variable, so allows anyone to swap it for anything. I thought that was a design-mistake, so at some point changed it, but turned out that BuildKit found that loophole and is abusing it;

// G is a shorthand for [GetLogger].
//
// We may want to define this locally to a package to get package tagged log
// messages.
var G = GetLogger

@thaJeztah
Copy link
Member Author

I'll bring this one in, but more cleaning up may follow; also to get rid of some of the types that are used, and (currently) must remain related to Docker Content Trust code expecting it, but I'd love to get rid of those where possible, and simplify for it to be "just enough for what we need".

docker manifest is the other part that uses a bunch of this code (for pulling/pushing manifests); love to replace some of that, because it also forces the deprecated registry client (and half of its API implementation) on us;

@thaJeztah thaJeztah merged commit 1eeb0cc into docker:master Jul 25, 2025
87 checks passed
@thaJeztah thaJeztah deleted the fork_registry branch July 25, 2025 10:57
@thaJeztah
Copy link
Member Author

☝️ for context on the above;

  • the (deprecated) registry client originated from moby/moby
  • got moved (or re-implemented) in the distribution (AKA "docker OSS registry") code, because the registry needed a client for mirroring other registries
  • then moby/moby swapped out its own implementation for the one from the registry

But the implementation in the registry was tightly coupled to the registry API server, so now we ended up having (e.g.) gorilla/mux as dependency for a client, as well as really deprecated stuff, like docker/libtrust (legacy v0/v1 "signed" images).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactor PR's that refactor, or clean-up code status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants