Skip to content

Commit 0718529

Browse files
Merge pull request #6221 from thaJeztah/28.x_fork_registry
[28.x] add internal fork of docker/docker/registry
2 parents c754ac3 + efdf008 commit 0718529

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1101
-1801
lines changed

cli/command/image/push.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"github.com/docker/cli/cli/command/completion"
1717
"github.com/docker/cli/cli/streams"
1818
"github.com/docker/cli/internal/jsonstream"
19+
"github.com/docker/cli/internal/registry"
1920
"github.com/docker/cli/internal/tui"
2021
"github.com/docker/docker/api/types/auxprogress"
2122
"github.com/docker/docker/api/types/image"
2223
registrytypes "github.com/docker/docker/api/types/registry"
23-
"github.com/docker/docker/registry"
2424
"github.com/morikuni/aec"
2525
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2626
"github.com/pkg/errors"
@@ -105,10 +105,10 @@ To push the complete multi-platform image, remove the --platform flag.
105105
}
106106

107107
// Resolve the Repository name from fqn to RepositoryInfo
108-
repoInfo, _ := registry.ParseRepositoryInfo(ref)
108+
indexInfo := registry.NewIndexInfo(ref)
109109

110110
// Resolve the Auth config relevant for this server
111-
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), repoInfo.Index)
111+
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), indexInfo)
112112
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
113113
if err != nil {
114114
return err
@@ -134,7 +134,7 @@ To push the complete multi-platform image, remove the --platform flag.
134134
defer responseBody.Close()
135135
if !opts.untrusted {
136136
// TODO pushTrustedReference currently doesn't respect `--quiet`
137-
return pushTrustedReference(ctx, dockerCli, repoInfo, ref, authConfig, responseBody)
137+
return pushTrustedReference(ctx, dockerCli, indexInfo, ref, authConfig, responseBody)
138138
}
139139

140140
if opts.quiet {

cli/command/image/trust.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/docker/cli/internal/jsonstream"
1414
"github.com/docker/docker/api/types/image"
1515
registrytypes "github.com/docker/docker/api/types/registry"
16-
"github.com/docker/docker/registry"
1716
"github.com/opencontainers/go-digest"
1817
"github.com/pkg/errors"
1918
"github.com/sirupsen/logrus"
@@ -42,7 +41,11 @@ func newNotaryClient(cli command.Streams, imgRefAndAuth trust.ImageRefAndAuth) (
4241
}
4342

4443
// pushTrustedReference pushes a canonical reference to the trust server.
45-
func pushTrustedReference(ctx context.Context, ioStreams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error {
44+
func pushTrustedReference(ctx context.Context, ioStreams command.Streams, indexInfo *registrytypes.IndexInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error {
45+
repoInfo := &trust.RepositoryInfo{
46+
Name: reference.TrimNamed(ref),
47+
Index: indexInfo,
48+
}
4649
return trust.PushTrustedReference(ctx, ioStreams, repoInfo, ref, authConfig, in, command.UserAgent())
4750
}
4851

cli/command/plugin/install.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"github.com/docker/cli/cli/command/image"
1212
"github.com/docker/cli/internal/jsonstream"
1313
"github.com/docker/cli/internal/prompt"
14+
"github.com/docker/cli/internal/registry"
1415
"github.com/docker/docker/api/types"
1516
registrytypes "github.com/docker/docker/api/types/registry"
16-
"github.com/docker/docker/registry"
1717
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
1919
"github.com/spf13/pflag"
@@ -65,8 +65,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
6565
return types.PluginInstallOptions{}, err
6666
}
6767

68-
repoInfo, _ := registry.ParseRepositoryInfo(ref)
69-
68+
indexInfo := registry.NewIndexInfo(ref)
7069
remote := ref.String()
7170

7271
_, isCanonical := ref.(reference.Canonical)
@@ -84,7 +83,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti
8483
remote = reference.FamiliarString(trusted)
8584
}
8685

87-
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), repoInfo.Index)
86+
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), indexInfo)
8887
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
8988
if err != nil {
9089
return types.PluginInstallOptions{}, err

cli/command/plugin/push.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/cli/trust"
1010
"github.com/docker/cli/internal/jsonstream"
11+
"github.com/docker/cli/internal/registry"
1112
registrytypes "github.com/docker/docker/api/types/registry"
12-
"github.com/docker/docker/registry"
1313
"github.com/pkg/errors"
1414
"github.com/spf13/cobra"
1515
)
@@ -49,8 +49,8 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error
4949

5050
named = reference.TagNameOnly(named)
5151

52-
repoInfo, _ := registry.ParseRepositoryInfo(named)
53-
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), repoInfo.Index)
52+
indexInfo := registry.NewIndexInfo(named)
53+
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), indexInfo)
5454
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
5555
if err != nil {
5656
return err
@@ -63,6 +63,10 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error
6363
defer responseBody.Close()
6464

6565
if !opts.untrusted {
66+
repoInfo := &trust.RepositoryInfo{
67+
Name: reference.TrimNamed(named),
68+
Index: indexInfo,
69+
}
6670
return trust.PushTrustedReference(ctx, dockerCli, repoInfo, named, authConfig, responseBody, command.UserAgent())
6771
}
6872

cli/command/registry/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"github.com/docker/cli/cli/config/configfile"
1616
configtypes "github.com/docker/cli/cli/config/types"
1717
"github.com/docker/cli/internal/oauth/manager"
18+
"github.com/docker/cli/internal/registry"
1819
"github.com/docker/cli/internal/tui"
1920
registrytypes "github.com/docker/docker/api/types/registry"
2021
"github.com/docker/docker/client"
21-
"github.com/docker/docker/registry"
2222
"github.com/pkg/errors"
2323
"github.com/spf13/cobra"
2424
"github.com/spf13/pflag"
@@ -288,7 +288,7 @@ func loginClientSide(ctx context.Context, auth registrytypes.AuthConfig) (*regis
288288
return nil, err
289289
}
290290

291-
_, token, err := svc.Auth(ctx, &auth, command.UserAgent())
291+
token, err := svc.Auth(ctx, &auth, command.UserAgent())
292292
if err != nil {
293293
return nil, err
294294
}

cli/command/registry/login_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
configtypes "github.com/docker/cli/cli/config/types"
1414
"github.com/docker/cli/cli/streams"
1515
"github.com/docker/cli/internal/prompt"
16+
"github.com/docker/cli/internal/registry"
1617
"github.com/docker/cli/internal/test"
1718
registrytypes "github.com/docker/docker/api/types/registry"
1819
"github.com/docker/docker/api/types/system"
1920
"github.com/docker/docker/client"
20-
"github.com/docker/docker/registry"
2121
"gotest.tools/v3/assert"
2222
is "gotest.tools/v3/assert/cmp"
2323
"gotest.tools/v3/fs"

cli/command/registry/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/cli/config/credentials"
1010
"github.com/docker/cli/internal/oauth/manager"
11-
"github.com/docker/docker/registry"
11+
"github.com/docker/cli/internal/registry"
1212
"github.com/spf13/cobra"
1313
)
1414

cli/command/registry/search.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package registry
33
import (
44
"context"
55
"fmt"
6+
"strings"
67

78
"github.com/docker/cli/cli"
89
"github.com/docker/cli/cli/command"
910
"github.com/docker/cli/cli/command/formatter"
1011
"github.com/docker/cli/opts"
1112
registrytypes "github.com/docker/docker/api/types/registry"
12-
"github.com/docker/docker/registry"
1313
"github.com/spf13/cobra"
1414
)
1515

@@ -52,13 +52,7 @@ func runSearch(ctx context.Context, dockerCli command.Cli, options searchOptions
5252
if options.filter.Value().Contains("is-automated") {
5353
_, _ = fmt.Fprintln(dockerCli.Err(), `WARNING: the "is-automated" filter is deprecated, and searching for "is-automated=true" will not yield any results in future.`)
5454
}
55-
indexInfo, err := registry.ParseSearchIndexInfo(options.term)
56-
if err != nil {
57-
return err
58-
}
59-
60-
authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), indexInfo)
61-
encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig)
55+
encodedAuth, err := getAuth(dockerCli, options.term)
6256
if err != nil {
6357
return err
6458
}
@@ -80,3 +74,37 @@ func runSearch(ctx context.Context, dockerCli command.Cli, options searchOptions
8074
}
8175
return SearchWrite(searchCtx, results)
8276
}
77+
78+
// authConfigKey is the key used to store credentials for Docker Hub. It is
79+
// a copy of [registry.IndexServer].
80+
//
81+
// [registry.IndexServer]: https://pkg.go.dev/github.com/docker/docker/registry#IndexServer
82+
const authConfigKey = "https://index.docker.io/v1/"
83+
84+
// getAuth will use fetch auth based on the given search-term. If the search
85+
// does not contain a hostname for the registry, it assumes Docker Hub is used,
86+
// and resolves authentication for Docker Hub, otherwise it resolves authentication
87+
// for the given registry.
88+
func getAuth(dockerCLI command.Cli, reposName string) (encodedAuth string, err error) {
89+
authCfgKey := splitReposSearchTerm(reposName)
90+
if authCfgKey == "docker.io" || authCfgKey == "index.docker.io" {
91+
authCfgKey = authConfigKey
92+
}
93+
94+
// Ignoring errors here, which was the existing behavior (likely
95+
// "no credentials found"). We'll get an error when search failed,
96+
// so fine to ignore in most situations.
97+
authConfig, _ := dockerCLI.ConfigFile().GetAuthConfig(authCfgKey)
98+
return registrytypes.EncodeAuthConfig(registrytypes.AuthConfig(authConfig))
99+
}
100+
101+
// splitReposSearchTerm breaks a search term into an index name and remote name
102+
func splitReposSearchTerm(reposName string) string {
103+
nameParts := strings.SplitN(reposName, "/", 2)
104+
if len(nameParts) == 1 || (!strings.Contains(nameParts[0], ".") && !strings.Contains(nameParts[0], ":") && nameParts[0] != "localhost") {
105+
// This is a Docker Hub repository (ex: samalba/hipache or ubuntu),
106+
// use the default Docker Hub registry (docker.io)
107+
return "docker.io"
108+
}
109+
return nameParts[0]
110+
}

cli/command/service/trust.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/distribution/reference"
77
"github.com/docker/cli/cli/command"
88
"github.com/docker/cli/cli/trust"
9+
"github.com/docker/cli/internal/registry"
910
"github.com/docker/docker/api/types/swarm"
10-
"github.com/docker/docker/registry"
1111
"github.com/opencontainers/go-digest"
1212
"github.com/pkg/errors"
1313
"github.com/sirupsen/logrus"
@@ -51,9 +51,12 @@ func resolveServiceImageDigestContentTrust(dockerCli command.Cli, service *swarm
5151
}
5252

5353
func trustedResolveDigest(cli command.Cli, ref reference.NamedTagged) (reference.Canonical, error) {
54-
repoInfo, _ := registry.ParseRepositoryInfo(ref)
55-
authConfig := command.ResolveAuthConfig(cli.ConfigFile(), repoInfo.Index)
56-
54+
indexInfo := registry.NewIndexInfo(ref)
55+
authConfig := command.ResolveAuthConfig(cli.ConfigFile(), indexInfo)
56+
repoInfo := &trust.RepositoryInfo{
57+
Name: reference.TrimNamed(ref),
58+
Index: indexInfo,
59+
}
5760
notaryRepo, err := trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, &authConfig, "pull")
5861
if err != nil {
5962
return nil, errors.Wrap(err, "error establishing connection to trust repository")

cli/command/system/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"github.com/docker/cli/cli/debug"
2020
flagsHelper "github.com/docker/cli/cli/flags"
2121
"github.com/docker/cli/internal/lazyregexp"
22+
"github.com/docker/cli/internal/registry"
2223
"github.com/docker/cli/templates"
2324
"github.com/docker/docker/api/types/swarm"
2425
"github.com/docker/docker/api/types/system"
2526
"github.com/docker/docker/client"
26-
"github.com/docker/docker/registry"
2727
"github.com/docker/go-units"
2828
"github.com/spf13/cobra"
2929
)

0 commit comments

Comments
 (0)