From 34899cbe9ca281ff4da40d7ee504045ffca4e70d Mon Sep 17 00:00:00 2001 From: Nishant Totla Date: Mon, 8 May 2017 16:29:31 -0700 Subject: [PATCH] /distribution/{name}/json returns full Descriptor object Signed-off-by: Nishant Totla Upstream-commit: 12e232ee35b56cb2954c48d83ec9febb40cdeb90 Component: engine --- .../distribution/distribution_routes.go | 24 ++++++++++++++----- components/engine/api/swagger.yaml | 21 ++++++++++++---- .../engine/api/types/registry/registry.go | 7 +++--- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/components/engine/api/server/router/distribution/distribution_routes.go b/components/engine/api/server/router/distribution/distribution_routes.go index 3a0e13e3ac..fd57114495 100644 --- a/components/engine/api/server/router/distribution/distribution_routes.go +++ b/components/engine/api/server/router/distribution/distribution_routes.go @@ -58,6 +58,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res if err != nil { return err } + blobsrvc := distrepo.Blobs(ctx) if canonicalRef, ok := namedRef.(reference.Canonical); !ok { namedRef = reference.TagNameOnly(namedRef) @@ -67,25 +68,37 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res return errors.Errorf("image reference not tagged: %s", image) } - dscrptr, err := distrepo.Tags(ctx).Get(ctx, taggedRef.Tag()) + distributionInspect.Descriptor, err = distrepo.Tags(ctx).Get(ctx, taggedRef.Tag()) if err != nil { return err } - distributionInspect.Digest = dscrptr.Digest } else { - distributionInspect.Digest = canonicalRef.Digest() + // TODO(nishanttotla): Once manifests can be looked up as a blob, the + // descriptor should be set using blobsrvc.Stat(ctx, canonicalRef.Digest()) + // instead of having to manually fill in the fields + distributionInspect.Descriptor.Digest = canonicalRef.Digest() } - // at this point, we have a digest, so we can retrieve the manifest + // we have a digest, so we can retrieve the manifest mnfstsrvc, err := distrepo.Manifests(ctx) if err != nil { return err } - mnfst, err := mnfstsrvc.Get(ctx, distributionInspect.Digest) + mnfst, err := mnfstsrvc.Get(ctx, distributionInspect.Descriptor.Digest) if err != nil { return err } + mediaType, payload, err := mnfst.Payload() + if err != nil { + return err + } + // update MediaType because registry might return something incorrect + distributionInspect.Descriptor.MediaType = mediaType + if distributionInspect.Descriptor.Size == 0 { + distributionInspect.Descriptor.Size = int64(len(payload)) + } + // retrieve platform information depending on the type of manifest switch mnfstObj := mnfst.(type) { case *manifestlist.DeserializedManifestList: @@ -93,7 +106,6 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res distributionInspect.Platforms = append(distributionInspect.Platforms, m.Platform) } case *schema2.DeserializedManifest: - blobsrvc := distrepo.Blobs(ctx) configJSON, err := blobsrvc.Get(ctx, mnfstObj.Config.Digest) var platform manifestlist.PlatformSpec if err == nil { diff --git a/components/engine/api/swagger.yaml b/components/engine/api/swagger.yaml index 69b1ec9a9f..7d8adeaff4 100644 --- a/components/engine/api/swagger.yaml +++ b/components/engine/api/swagger.yaml @@ -8283,15 +8283,26 @@ paths: - "application/json" responses: 200: - description: "digest and platform information" + description: "descriptor and platform information" schema: type: "object" x-go-name: DistributionInspect - required: [Digest, ID, Platforms] + required: [Descriptor, Platforms] properties: - Digest: - type: "string" - x-nullable: false + Descriptor: + type: "object" + properties: + MediaType: + type: "string" + Size: + type: "integer" + format: "int64" + Digest: + type: "string" + URLs: + type: "array" + items: + type: "string" Platforms: type: "array" items: diff --git a/components/engine/api/types/registry/registry.go b/components/engine/api/types/registry/registry.go index 911dbc5838..94f594ae69 100644 --- a/components/engine/api/types/registry/registry.go +++ b/components/engine/api/types/registry/registry.go @@ -4,8 +4,8 @@ import ( "encoding/json" "net" + "github.com/docker/distribution" "github.com/docker/distribution/manifest/manifestlist" - digest "github.com/opencontainers/go-digest" ) // ServiceConfig stores daemon registry services configuration. @@ -109,8 +109,9 @@ type SearchResults struct { // DistributionInspect describes the result obtained from contacting the // registry to retrieve image metadata type DistributionInspect struct { - // Digest is the content addressable digest for the image on the registry - Digest digest.Digest + // Descriptor contains information about the manifest, including + // the content addressable digest + Descriptor distribution.Descriptor // Platforms contains the list of platforms supported by the image, // obtained by parsing the manifest Platforms []manifestlist.PlatformSpec