Skip to content

Commit 82b121c

Browse files
committed
update docker code and adapt code
Signed-off-by: Antonio Murdaca <[email protected]>
1 parent 89631ab commit 82b121c

Some content is hidden

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

88 files changed

+2287
-2124
lines changed

docker/inspect.go

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ import (
44
"encoding/json"
55
"fmt"
66
"strings"
7+
"syscall"
78
"time"
89

910
"github.com/Sirupsen/logrus"
1011
"github.com/codegangsta/cli"
1112
"github.com/docker/distribution/digest"
1213
distreference "github.com/docker/distribution/reference"
14+
"github.com/docker/distribution/registry/api/errcode"
15+
"github.com/docker/distribution/registry/api/v2"
16+
"github.com/docker/distribution/registry/client"
1317
"github.com/docker/docker/api"
1418
"github.com/docker/docker/cliconfig"
19+
"github.com/docker/docker/distribution"
20+
"github.com/docker/docker/dockerversion"
1521
"github.com/docker/docker/image"
1622
"github.com/docker/docker/opts"
1723
versionPkg "github.com/docker/docker/pkg/version"
@@ -32,6 +38,7 @@ type fallbackError struct {
3238
// supports the v2 protocol. This is used to limit fallbacks to the v1
3339
// protocol.
3440
confirmedV2 bool
41+
transportOK bool
3542
}
3643

3744
// Error renders the FallbackError as a string.
@@ -84,7 +91,7 @@ func GetData(c *cli.Context, name string) (*types.ImageInspect, error) {
8491
ic.Secure = false
8592
}
8693

87-
endpoints, err := registryService.LookupPullEndpoints(repoInfo)
94+
endpoints, err := registryService.LookupPullEndpoints(repoInfo.Hostname())
8895
if err != nil {
8996
return nil, err
9097
}
@@ -96,11 +103,12 @@ func GetData(c *cli.Context, name string) (*types.ImageInspect, error) {
96103
discardNoSupportErrors bool
97104
imgInspect *types.ImageInspect
98105
confirmedV2 bool
106+
confirmedTLSRegistries = make(map[string]struct{})
99107
)
100108

101109
for _, endpoint := range endpoints {
102110
// make sure I can reach the registry, same as docker pull does
103-
v1endpoint, err := endpoint.ToV1Endpoint(nil)
111+
v1endpoint, err := endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(), nil)
104112
if err != nil {
105113
return nil, err
106114
}
@@ -115,6 +123,14 @@ func GetData(c *cli.Context, name string) (*types.ImageInspect, error) {
115123
logrus.Debugf("Skipping v1 endpoint %s because v2 registry was detected", endpoint.URL)
116124
continue
117125
}
126+
127+
if endpoint.URL.Scheme != "https" {
128+
if _, confirmedTLS := confirmedTLSRegistries[endpoint.URL.Host]; confirmedTLS {
129+
logrus.Debugf("Skipping non-TLS endpoint %s for host/port that appears to use TLS", endpoint.URL)
130+
continue
131+
}
132+
}
133+
118134
logrus.Debugf("Trying to fetch image manifest of %s repository from %s %s", repoInfo.Name(), endpoint.URL, endpoint.Version)
119135

120136
//fetcher, err := newManifestFetcher(endpoint, repoInfo, config)
@@ -133,11 +149,14 @@ func GetData(c *cli.Context, name string) (*types.ImageInspect, error) {
133149
if fallbackErr, ok := err.(fallbackError); ok {
134150
fallback = true
135151
confirmedV2 = confirmedV2 || fallbackErr.confirmedV2
152+
if fallbackErr.transportOK && endpoint.URL.Scheme == "https" {
153+
confirmedTLSRegistries[endpoint.URL.Host] = struct{}{}
154+
}
136155
err = fallbackErr.err
137156
}
138157
}
139158
if fallback {
140-
if _, ok := err.(registry.ErrNoSupport); !ok {
159+
if _, ok := err.(distribution.ErrNoSupport); !ok {
141160
// Because we found an error that's not ErrNoSupport, discard all subsequent ErrNoSupport errors.
142161
discardNoSupportErrors = true
143162
// save the current error
@@ -149,7 +168,7 @@ func GetData(c *cli.Context, name string) (*types.ImageInspect, error) {
149168
}
150169
continue
151170
}
152-
logrus.Debugf("Not continuing with error: %v", err)
171+
logrus.Errorf("Not continuing with pull after error: %v", err)
153172
return nil, err
154173
}
155174

@@ -290,3 +309,37 @@ func rawJSON(value interface{}) *json.RawMessage {
290309
}
291310
return (*json.RawMessage)(&jsonval)
292311
}
312+
313+
func continueOnError(err error) bool {
314+
switch v := err.(type) {
315+
case errcode.Errors:
316+
if len(v) == 0 {
317+
return true
318+
}
319+
return continueOnError(v[0])
320+
case distribution.ErrNoSupport:
321+
return continueOnError(v.Err)
322+
case errcode.Error:
323+
return shouldV2Fallback(v)
324+
case *client.UnexpectedHTTPResponseError:
325+
return true
326+
case ImageConfigPullError:
327+
return false
328+
case error:
329+
return !strings.Contains(err.Error(), strings.ToLower(syscall.ENOSPC.Error()))
330+
}
331+
// let's be nice and fallback if the error is a completely
332+
// unexpected one.
333+
// If new errors have to be handled in some way, please
334+
// add them to the switch above.
335+
return true
336+
}
337+
338+
// shouldV2Fallback returns true if this error is a reason to fall back to v1.
339+
func shouldV2Fallback(err errcode.Error) bool {
340+
switch err.Code {
341+
case errcode.ErrorCodeUnauthorized, v2.ErrorCodeManifestUnknown, v2.ErrorCodeNameUnknown:
342+
return true
343+
}
344+
return false
345+
}

docker/inspect_v1.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/Sirupsen/logrus"
1010
"github.com/docker/distribution"
1111
"github.com/docker/distribution/registry/client/transport"
12+
dockerdistribution "github.com/docker/docker/distribution"
13+
"github.com/docker/docker/dockerversion"
1214
"github.com/docker/docker/image"
1315
"github.com/docker/docker/image/v1"
1416
"github.com/docker/docker/reference"
@@ -35,7 +37,7 @@ func (mf *v1ManifestFetcher) Fetch(ctx context.Context, ref reference.Named) (*t
3537
)
3638
if _, isCanonical := ref.(reference.Canonical); isCanonical {
3739
// Allowing fallback, because HTTPS v1 is before HTTP v2
38-
return nil, fallbackError{err: registry.ErrNoSupport{errors.New("Cannot pull by digest with v1 registry")}}
40+
return nil, fallbackError{err: dockerdistribution.ErrNoSupport{errors.New("Cannot pull by digest with v1 registry")}}
3941
}
4042
tlsConfig, err := mf.service.TLSConfig(mf.repoInfo.Index.Name)
4143
if err != nil {
@@ -45,11 +47,11 @@ func (mf *v1ManifestFetcher) Fetch(ctx context.Context, ref reference.Named) (*t
4547
tr := transport.NewTransport(
4648
registry.NewTransport(tlsConfig),
4749
//registry.DockerHeaders(mf.config.MetaHeaders)...,
48-
registry.DockerHeaders(nil)...,
50+
registry.DockerHeaders(dockerversion.DockerUserAgent(), nil)...,
4951
)
5052
client := registry.HTTPClient(tr)
5153
//v1Endpoint, err := mf.endpoint.ToV1Endpoint(mf.config.MetaHeaders)
52-
v1Endpoint, err := mf.endpoint.ToV1Endpoint(nil)
54+
v1Endpoint, err := mf.endpoint.ToV1Endpoint(dockerversion.DockerUserAgent(), nil)
5355
if err != nil {
5456
logrus.Debugf("Could not get v1 endpoint: %v", err)
5557
return nil, fallbackError{err: err}

docker/inspect_v2.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ func (mf *v2ManifestFetcher) Fetch(ctx context.Context, ref reference.Named) (*t
4444
mf.repo, mf.confirmedV2, err = dockerdistribution.NewV2Repository(ctx, mf.repoInfo, mf.endpoint, nil, &mf.authConfig, "pull")
4545
if err != nil {
4646
logrus.Debugf("Error getting v2 registry: %v", err)
47-
return nil, fallbackError{err: err, confirmedV2: mf.confirmedV2}
47+
return nil, err
4848
}
4949

5050
imgInspect, err = mf.fetchWithRepository(ctx, ref)
5151
if err != nil {
5252
if _, ok := err.(fallbackError); ok {
5353
return nil, err
5454
}
55-
if registry.ContinueOnError(err) {
56-
err = fallbackError{err: err, confirmedV2: mf.confirmedV2}
55+
if continueOnError(err) {
56+
logrus.Errorf("Error trying v2 registry: %v", err)
57+
return nil, fallbackError{err: err, confirmedV2: mf.confirmedV2, transportOK: true}
5758
}
5859
}
5960
return imgInspect, err
@@ -294,7 +295,7 @@ func (mf *v2ManifestFetcher) pullSchema2(ctx context.Context, ref reference.Name
294295
go func() {
295296
configJSON, err := mf.pullSchema2ImageConfig(ctx, target.Digest)
296297
if err != nil {
297-
errChan <- err
298+
errChan <- ImageConfigPullError{Err: err}
298299
cancel()
299300
return
300301
}
@@ -369,6 +370,17 @@ func receiveConfig(configChan <-chan []byte, errChan <-chan error) ([]byte, imag
369370
}
370371
}
371372

373+
// ImageConfigPullError is an error pulling the image config blob
374+
// (only applies to schema2).
375+
type ImageConfigPullError struct {
376+
Err error
377+
}
378+
379+
// Error returns the error string for ImageConfigPullError.
380+
func (e ImageConfigPullError) Error() string {
381+
return "error pulling image configuration: " + e.Err.Error()
382+
}
383+
372384
// allowV1Fallback checks if the error is a possible reason to fallback to v1
373385
// (even if confirmedV2 has been set already), and if so, wraps the error in
374386
// a fallbackError with confirmedV2 set to false. Otherwise, it returns the
@@ -377,13 +389,13 @@ func allowV1Fallback(err error) error {
377389
switch v := err.(type) {
378390
case errcode.Errors:
379391
if len(v) != 0 {
380-
if v0, ok := v[0].(errcode.Error); ok && registry.ShouldV2Fallback(v0) {
381-
return fallbackError{err: err, confirmedV2: false}
392+
if v0, ok := v[0].(errcode.Error); ok && shouldV2Fallback(v0) {
393+
return fallbackError{err: err, confirmedV2: false, transportOK: true}
382394
}
383395
}
384396
case errcode.Error:
385-
if registry.ShouldV2Fallback(v) {
386-
return fallbackError{err: err, confirmedV2: false}
397+
if shouldV2Fallback(v) {
398+
return fallbackError{err: err, confirmedV2: false, transportOK: true}
387399
}
388400
}
389401
return err

hack/vendor.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ source 'hack/.vendor-helpers.sh'
77

88
clone git github.com/codegangsta/cli v1.2.0
99
clone git github.com/Sirupsen/logrus v0.8.7
10-
clone git github.com/vbatts/tar-split master
10+
clone git github.com/vbatts/tar-split v0.9.11
1111
clone git github.com/gorilla/mux master
1212
clone git github.com/gorilla/context master
1313
clone git golang.org/x/net master https://github.com/golang/net.git
1414
clone git github.com/go-check/check v1
1515

16-
clone git github.com/docker/docker v1.10.2
17-
clone git github.com/docker/engine-api v0.2.3
18-
clone git github.com/docker/distribution 0f2d99b13ae0cfbcf118eff103e6e680b726b47e
16+
clone git github.com/docker/docker 29bade2cd0a09191279f04ebc6aeedaa70c772a0
17+
clone git github.com/docker/engine-api 7f6071353fc48f69d2328c4ebe8f3bd0f7c75da4
18+
clone git github.com/docker/distribution 7b66c50bb7e0e4b3b83f8fd134a9f6ea4be08b57
1919

2020
clone git github.com/docker/go-connections master
2121
clone git github.com/docker/go-units master

vendor/github.com/docker/distribution/.mailmap

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/distribution/AUTHORS

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/distribution/MAINTAINERS

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/distribution/context/doc.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/distribution/context/trace.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/distribution/digest/set.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)