All images in the default registry (AKA docker.io, index.docker.io, and
registry-1.docker.io) are available via the v2 protocol, so there's no
reason to use the v1 protocol. Disabling it prevents useless fallbacks.
Signed-off-by: Noah Treuhaft <noah.treuhaft@docker.com>
| ... | ... |
@@ -36,20 +36,16 @@ var ( |
| 36 | 36 |
// that carries Registry version info |
| 37 | 37 |
DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version" |
| 38 | 38 |
|
| 39 |
- // IndexServer is the v1 registry server used for user auth + account creation |
|
| 40 |
- IndexServer = DefaultV1Registry.String() + "/v1/" |
|
| 39 |
+ // IndexHostname is the index hostname |
|
| 40 |
+ IndexHostname = "index.docker.io" |
|
| 41 |
+ // IndexServer is used for user auth and image search |
|
| 42 |
+ IndexServer = "https://" + IndexHostname + "/v1/" |
|
| 41 | 43 |
// IndexName is the name of the index |
| 42 | 44 |
IndexName = "docker.io" |
| 43 | 45 |
|
| 44 | 46 |
// NotaryServer is the endpoint serving the Notary trust server |
| 45 | 47 |
NotaryServer = "https://notary.docker.io" |
| 46 | 48 |
|
| 47 |
- // DefaultV1Registry is the URI of the default v1 registry |
|
| 48 |
- DefaultV1Registry = &url.URL{
|
|
| 49 |
- Scheme: "https", |
|
| 50 |
- Host: "index.docker.io", |
|
| 51 |
- } |
|
| 52 |
- |
|
| 53 | 49 |
// DefaultV2Registry is the URI of the default v2 registry |
| 54 | 50 |
DefaultV2Registry = &url.URL{
|
| 55 | 51 |
Scheme: "https", |
| ... | ... |
@@ -1,25 +1,13 @@ |
| 1 | 1 |
package registry |
| 2 | 2 |
|
| 3 |
-import ( |
|
| 4 |
- "net/url" |
|
| 5 |
- |
|
| 6 |
- "github.com/docker/go-connections/tlsconfig" |
|
| 7 |
-) |
|
| 3 |
+import "net/url" |
|
| 8 | 4 |
|
| 9 | 5 |
func (s *DefaultService) lookupV1Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
| 10 |
- tlsConfig := tlsconfig.ServerDefault() |
|
| 11 |
- if hostname == DefaultNamespace {
|
|
| 12 |
- endpoints = append(endpoints, APIEndpoint{
|
|
| 13 |
- URL: DefaultV1Registry, |
|
| 14 |
- Version: APIVersion1, |
|
| 15 |
- Official: true, |
|
| 16 |
- TrimHostname: true, |
|
| 17 |
- TLSConfig: tlsConfig, |
|
| 18 |
- }) |
|
| 19 |
- return endpoints, nil |
|
| 6 |
+ if hostname == DefaultNamespace || hostname == DefaultV2Registry.Host || hostname == IndexHostname {
|
|
| 7 |
+ return []APIEndpoint{}, nil
|
|
| 20 | 8 |
} |
| 21 | 9 |
|
| 22 |
- tlsConfig, err = s.tlsConfig(hostname) |
|
| 10 |
+ tlsConfig, err := s.tlsConfig(hostname) |
|
| 23 | 11 |
if err != nil {
|
| 24 | 12 |
return nil, err |
| 25 | 13 |
} |
| 26 | 14 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+package registry |
|
| 1 |
+ |
|
| 2 |
+import "testing" |
|
| 3 |
+ |
|
| 4 |
+func TestLookupV1Endpoints(t *testing.T) {
|
|
| 5 |
+ s := NewService(ServiceOptions{})
|
|
| 6 |
+ |
|
| 7 |
+ cases := []struct {
|
|
| 8 |
+ hostname string |
|
| 9 |
+ expectedLen int |
|
| 10 |
+ }{
|
|
| 11 |
+ {"example.com", 1},
|
|
| 12 |
+ {DefaultNamespace, 0},
|
|
| 13 |
+ {DefaultV2Registry.Host, 0},
|
|
| 14 |
+ {IndexHostname, 0},
|
|
| 15 |
+ } |
|
| 16 |
+ |
|
| 17 |
+ for _, c := range cases {
|
|
| 18 |
+ if ret, err := s.lookupV1Endpoints(c.hostname); err != nil || len(ret) != c.expectedLen {
|
|
| 19 |
+ t.Errorf("lookupV1Endpoints(`"+c.hostname+"`) returned %+v and %+v", ret, err)
|
|
| 20 |
+ } |
|
| 21 |
+ } |
|
| 22 |
+} |
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
| 11 | 11 |
tlsConfig := tlsconfig.ServerDefault() |
| 12 |
- if hostname == DefaultNamespace || hostname == DefaultV1Registry.Host {
|
|
| 12 |
+ if hostname == DefaultNamespace || hostname == IndexHostname {
|
|
| 13 | 13 |
// v2 mirrors |
| 14 | 14 |
for _, mirror := range s.config.Mirrors {
|
| 15 | 15 |
if !strings.HasPrefix(mirror, "http://") && !strings.HasPrefix(mirror, "https://") {
|