Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/command/manifest/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/manifest/types"
"github.com/docker/distribution/manifest/manifestlist"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -69,10 +70,12 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
}

// Try a local manifest list first
logrus.WithFields(logrus.Fields{"name": namedRef}).Debug("trying local manifest")
localManifestList, err := newManifestStore(dockerCli).GetList(namedRef)
if err == nil {
return printManifestList(dockerCli, namedRef, localManifestList, opts)
}
logrus.WithFields(logrus.Fields{"name": namedRef}).Debug("trying remote manifest")

// Next try a remote manifest
registryClient := newRegistryClient(dockerCli, opts.insecure)
Expand All @@ -82,6 +85,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
}

// Finally try a remote manifest list
logrus.WithFields(logrus.Fields{"name": namedRef}).Debug("trying remote manifest list")
manifestList, err := registryClient.GetManifestList(ctx, namedRef)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/registry/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *Service) Auth(ctx context.Context, authConfig *registry.AuthConfig, use
// Try next endpoint
log.G(ctx).WithFields(log.Fields{
"error": err,
"endpoint": endpoint,
"endpoint": endpoint.URL,
}).Infof("Error logging in to endpoint, trying next endpoint")
lastErr = err
continue
Expand Down
16 changes: 7 additions & 9 deletions internal/registryclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,24 @@ func (c *client) getHTTPTransportForRepoEndpoint(ctx context.Context, repoEndpoi
// GetManifest returns an ImageManifest for the reference
func (c *client) GetManifest(ctx context.Context, ref reference.Named) (manifesttypes.ImageManifest, error) {
var result manifesttypes.ImageManifest
fetch := func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
err := c.iterateEndpoints(ctx, ref, func(fetchCtx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
var err error
result, err = fetchManifest(ctx, repo, ref)
logrus.WithFields(logrus.Fields{"ref": ref}).Debug("fetching manifest")
result, err = fetchManifest(fetchCtx, repo, ref)
return result.Ref != nil, err
}

err := c.iterateEndpoints(ctx, ref, fetch)
})
return result, err
}

// GetManifestList returns a list of ImageManifest for the reference
func (c *client) GetManifestList(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error) {
result := []manifesttypes.ImageManifest{}
fetch := func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
err := c.iterateEndpoints(ctx, ref, func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
var err error
logrus.WithFields(logrus.Fields{"ref": ref}).Debug("fetching manifest list")
result, err = fetchList(ctx, repo, ref)
return len(result) > 0, err
}

err := c.iterateEndpoints(ctx, ref, fetch)
})
return result, err
}

Expand Down
14 changes: 12 additions & 2 deletions internal/registryclient/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ func fetchManifest(ctx context.Context, repo distribution.Repository, ref refere
case *ocischema.DeserializedManifest:
return pullManifestOCISchema(ctx, ref, repo, *v)
case *manifestlist.DeserializedManifestList:
mediaType, data, err := v.Payload()
if err == nil {
logrus.WithFields(logrus.Fields{"payload": string(data), "mediaType": mediaType}).Debugf("manifestlist for: %s", ref)
}
return types.ImageManifest{}, fmt.Errorf("%s is a manifest list", ref)
default:
return types.ImageManifest{}, fmt.Errorf("%s is not a manifest", ref)
}
return types.ImageManifest{}, fmt.Errorf("%s is not a manifest", ref)
}

func fetchList(ctx context.Context, repo distribution.Repository, ref reference.Named) ([]types.ImageManifest, error) {
Expand Down Expand Up @@ -163,6 +168,7 @@ func pullManifestList(ctx context.Context, ref reference.Named, repo distributio
if err != nil {
return nil, err
}
logrus.WithFields(logrus.Fields{"digest": manifestDescriptor.Digest}).Debug("pulling manifest")
manifest, err := manSvc.Get(ctx, manifestDescriptor.Digest)
if err != nil {
return nil, err
Expand Down Expand Up @@ -286,7 +292,11 @@ func allEndpoints(ctx context.Context, namedRef reference.Named, insecure bool)
return nil, err
}
endpoints, err := registryService.Endpoints(ctx, reference.Domain(namedRef))
logrus.Debugf("endpoints for %s: %v", namedRef, endpoints)
var epUrls []string
for _, ep := range endpoints {
epUrls = append(epUrls, ep.URL.String())
}
logrus.WithField("endpoints", epUrls).Debugf("resolved endpoints for %s", namedRef)
return endpoints, err
}

Expand Down
Loading