Browse Source

Remove compatibility wrapper

It's not necessary to repackage results from the docker regsitry
library.
Michael Bridgen 2 years ago
parent
commit
f01cfe57a8
3 changed files with 13 additions and 47 deletions
  1. 5
    5
      registry/client.go
  2. 8
    10
      registry/client_factory.go
  3. 0
    32
      registry/registry.go

+ 5
- 5
registry/client.go View File

@@ -29,7 +29,7 @@ type Client interface {
29 29
 // An implementation of Client that represents a Remote registry.
30 30
 // E.g. docker hub.
31 31
 type Remote struct {
32
-	Registry   *herokuManifestAdaptor
32
+	Registry   *dockerregistry.Registry
33 33
 	CancelFunc context.CancelFunc
34 34
 }
35 35
 
@@ -86,8 +86,8 @@ func (a *Remote) Manifest(id image.Ref) (image.Info, error) {
86 86
 }
87 87
 
88 88
 func (a *Remote) ManifestFromV1(id image.Ref) (image.Info, error) {
89
-	history, err := a.Registry.Manifest(id.Repository(), id.Tag)
90
-	if err != nil || history == nil {
89
+	manifest, err := a.Registry.Manifest(id.Repository(), id.Tag)
90
+	if err != nil || manifest == nil {
91 91
 		return image.Info{}, errors.Wrap(err, "getting remote manifest")
92 92
 	}
93 93
 
@@ -102,8 +102,8 @@ func (a *Remote) ManifestFromV1(id image.Ref) (image.Info, error) {
102 102
 	var topmost v1image
103 103
 	var img image.Info
104 104
 	img.ID = id
105
-	if len(history) > 0 {
106
-		if err = json.Unmarshal([]byte(history[0].V1Compatibility), &topmost); err == nil {
105
+	if len(manifest.History) > 0 {
106
+		if err = json.Unmarshal([]byte(manifest.History[0].V1Compatibility), &topmost); err == nil {
107 107
 			if !topmost.Created.IsZero() {
108 108
 				img.CreatedAt = topmost.Created
109 109
 			}

+ 8
- 10
registry/client_factory.go View File

@@ -44,19 +44,17 @@ func (f *RemoteClientFactory) ClientFor(host string, creds Credentials) (Client,
44 44
 		transport = f.Limiters.RoundTripper(transport, host)
45 45
 	}
46 46
 
47
-	herokuRegistry := herokuManifestAdaptor{
48
-		&dockerregistry.Registry{
49
-			URL: httphost,
50
-			Client: &http.Client{
51
-				Transport: transport,
52
-				Jar:       jar,
53
-				Timeout:   requestTimeout,
54
-			},
55
-			Logf: dockerregistry.Quiet,
47
+	registry := &dockerregistry.Registry{
48
+		URL: httphost,
49
+		Client: &http.Client{
50
+			Transport: transport,
51
+			Jar:       jar,
52
+			Timeout:   requestTimeout,
56 53
 		},
54
+		Logf: dockerregistry.Quiet,
57 55
 	}
58 56
 	client := &Remote{
59
-		Registry:   &herokuRegistry,
57
+		Registry:   registry,
60 58
 		CancelFunc: cancel,
61 59
 	}
62 60
 	return NewInstrumentedClient(client), nil

+ 0
- 32
registry/registry.go View File

@@ -3,9 +3,6 @@ package registry
3 3
 import (
4 4
 	"time"
5 5
 
6
-	"github.com/docker/distribution/manifest/schema1"
7
-	dockerregistry "github.com/heroku/docker-registry-client/registry"
8
-
9 6
 	"github.com/weaveworks/flux/image"
10 7
 )
11 8
 
@@ -17,32 +14,3 @@ type Registry interface {
17 14
 	GetRepository(image.Name) ([]image.Info, error)
18 15
 	GetImage(image.Ref) (image.Info, error)
19 16
 }
20
-
21
-// --- FIXME(michael): This is probably garbage?
22
-
23
-// This is an interface that represents the heroku docker registry library
24
-type HerokuRegistryLibrary interface {
25
-	Tags(repository string) (tags []string, err error)
26
-	Manifest(repository, reference string) ([]schema1.History, error)
27
-}
28
-
29
-// ---
30
-
31
-// Convert between types. dockerregistry returns the *same* type but from a
32
-// vendored library. Because golang doesn't like to apply interfaces to a
33
-// vendored type, we have to provide an adaptor to isolate it.
34
-type herokuManifestAdaptor struct {
35
-	*dockerregistry.Registry
36
-}
37
-
38
-func (h herokuManifestAdaptor) Manifest(repository, reference string) ([]schema1.History, error) {
39
-	manifest, err := h.Registry.Manifest(repository, reference)
40
-	if err != nil || manifest == nil {
41
-		return nil, err
42
-	}
43
-	var result []schema1.History
44
-	for _, item := range manifest.History {
45
-		result = append(result, schema1.History{item.V1Compatibility})
46
-	}
47
-	return result, err
48
-}

Loading…
Cancel
Save