Browse code

registry: Do not push to mirrors

This patch splits LookupEndpoints into LookupPullEndpoints and
LookupPushEndpoints so that mirrors added with --registry-mirror are
skipped in the list returned by LookupPushEndpoints.

Fixes https://github.com/docker/distribution/issues/823

Signed-off-by: Tibor Vass <tibor@docker.com>

Tibor Vass authored on 2015/08/07 06:41:59
Showing 3 changed files
... ...
@@ -76,7 +76,7 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
76 76
 		return err
77 77
 	}
78 78
 
79
-	endpoints, err := s.registryService.LookupEndpoints(repoInfo.CanonicalName)
79
+	endpoints, err := s.registryService.LookupPullEndpoints(repoInfo.CanonicalName)
80 80
 	if err != nil {
81 81
 		return err
82 82
 	}
... ...
@@ -77,7 +77,7 @@ func (s *TagStore) Push(localName string, imagePushConfig *ImagePushConfig) erro
77 77
 		return err
78 78
 	}
79 79
 
80
-	endpoints, err := s.registryService.LookupEndpoints(repoInfo.CanonicalName)
80
+	endpoints, err := s.registryService.LookupPushEndpoints(repoInfo.CanonicalName)
81 81
 	if err != nil {
82 82
 		return err
83 83
 	}
... ...
@@ -109,27 +109,40 @@ func (s *Service) tlsConfigForMirror(mirror string) (*tls.Config, error) {
109 109
 	return s.TLSConfig(mirrorURL.Host)
110 110
 }
111 111
 
112
-// LookupEndpoints creates an list of endpoints to try, in order of preference.
112
+// LookupPullEndpoints creates an list of endpoints to try to pull from, in order of preference.
113 113
 // It gives preference to v2 endpoints over v1, mirrors over the actual
114 114
 // registry, and HTTPS over plain HTTP.
115
-func (s *Service) LookupEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
115
+func (s *Service) LookupPullEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
116
+	return s.lookupEndpoints(repoName, false)
117
+}
118
+
119
+// LookupPushEndpoints creates an list of endpoints to try to push to, in order of preference.
120
+// It gives preference to v2 endpoints over v1, and HTTPS over plain HTTP.
121
+// Mirrors are not included.
122
+func (s *Service) LookupPushEndpoints(repoName string) (endpoints []APIEndpoint, err error) {
123
+	return s.lookupEndpoints(repoName, true)
124
+}
125
+
126
+func (s *Service) lookupEndpoints(repoName string, isPush bool) (endpoints []APIEndpoint, err error) {
116 127
 	var cfg = tlsconfig.ServerDefault
117 128
 	tlsConfig := &cfg
118 129
 	if strings.HasPrefix(repoName, DefaultNamespace+"/") {
119
-		// v2 mirrors
120
-		for _, mirror := range s.Config.Mirrors {
121
-			mirrorTLSConfig, err := s.tlsConfigForMirror(mirror)
122
-			if err != nil {
123
-				return nil, err
130
+		if !isPush {
131
+			// v2 mirrors for pull only
132
+			for _, mirror := range s.Config.Mirrors {
133
+				mirrorTLSConfig, err := s.tlsConfigForMirror(mirror)
134
+				if err != nil {
135
+					return nil, err
136
+				}
137
+				endpoints = append(endpoints, APIEndpoint{
138
+					URL: mirror,
139
+					// guess mirrors are v2
140
+					Version:      APIVersion2,
141
+					Mirror:       true,
142
+					TrimHostname: true,
143
+					TLSConfig:    mirrorTLSConfig,
144
+				})
124 145
 			}
125
-			endpoints = append(endpoints, APIEndpoint{
126
-				URL: mirror,
127
-				// guess mirrors are v2
128
-				Version:      APIVersion2,
129
-				Mirror:       true,
130
-				TrimHostname: true,
131
-				TLSConfig:    mirrorTLSConfig,
132
-			})
133 146
 		}
134 147
 		// v2 registry
135 148
 		endpoints = append(endpoints, APIEndpoint{