@@ -8,15 +8,46 @@ import (
88 "github.com/docker/distribution/manifest/schema2"
99 "github.com/docker/distribution/reference"
1010 "github.com/opencontainers/go-digest"
11+ ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1112 "github.com/pkg/errors"
1213)
1314
1415// ImageManifest contains info to output for a manifest object.
1516type ImageManifest struct {
16- Ref * SerializableNamed
17- Digest digest.Digest
17+ Ref * SerializableNamed
18+ Descriptor ocispec.Descriptor
19+
20+ // SchemaV2Manifest is used for inspection
21+ // TODO: Deprecate this and store manifest blobs
1822 SchemaV2Manifest * schema2.DeserializedManifest `json:",omitempty"`
19- Platform manifestlist.PlatformSpec
23+ }
24+
25+ // OCIPlatform creates an OCI platform from a manifest list platform spec
26+ func OCIPlatform (ps * manifestlist.PlatformSpec ) * ocispec.Platform {
27+ if ps == nil {
28+ return nil
29+ }
30+ return & ocispec.Platform {
31+ Architecture : ps .Architecture ,
32+ OS : ps .OS ,
33+ OSVersion : ps .OSVersion ,
34+ OSFeatures : ps .OSFeatures ,
35+ Variant : ps .Variant ,
36+ }
37+ }
38+
39+ // PlatformSpecFromOCI creates a platfrom spec from OCI platform
40+ func PlatfromSpecFromOCI (p * ocispec.Platform ) * manifestlist.PlatformSpec {
41+ if p == nil {
42+ return nil
43+ }
44+ return & manifestlist.PlatformSpec {
45+ Architecture : p .Architecture ,
46+ OS : p .OS ,
47+ OSVersion : p .OSVersion ,
48+ OSFeatures : p .OSFeatures ,
49+ Variant : p .Variant ,
50+ }
2051}
2152
2253// Blobs returns the digests for all the blobs referenced by this manifest
@@ -30,6 +61,7 @@ func (i ImageManifest) Blobs() []digest.Digest {
3061
3162// Payload returns the media type and bytes for the manifest
3263func (i ImageManifest ) Payload () (string , []byte , error ) {
64+ // TODO: If available, read content from a content store by digest
3365 switch {
3466 case i .SchemaV2Manifest != nil :
3567 return i .SchemaV2Manifest .Payload ()
@@ -51,18 +83,11 @@ func (i ImageManifest) References() []distribution.Descriptor {
5183
5284// NewImageManifest returns a new ImageManifest object. The values for Platform
5385// are initialized from those in the image
54- func NewImageManifest (ref reference.Named , digest digest.Digest , img Image , manifest * schema2.DeserializedManifest ) ImageManifest {
55- platform := manifestlist.PlatformSpec {
56- OS : img .OS ,
57- Architecture : img .Architecture ,
58- OSVersion : img .OSVersion ,
59- OSFeatures : img .OSFeatures ,
60- }
86+ func NewImageManifest (ref reference.Named , desc ocispec.Descriptor , manifest * schema2.DeserializedManifest ) ImageManifest {
6187 return ImageManifest {
6288 Ref : & SerializableNamed {Named : ref },
63- Digest : digest ,
89+ Descriptor : desc ,
6490 SchemaV2Manifest : manifest ,
65- Platform : platform ,
6691 }
6792}
6893
@@ -88,20 +113,11 @@ func (s *SerializableNamed) MarshalJSON() ([]byte, error) {
88113 return json .Marshal (s .String ())
89114}
90115
91- // Image is the minimal set of fields required to set default platform settings
92- // on a manifest.
93- type Image struct {
94- Architecture string `json:"architecture,omitempty"`
95- OS string `json:"os,omitempty"`
96- OSVersion string `json:"os.version,omitempty"`
97- OSFeatures []string `json:"os.features,omitempty"`
98- }
99-
100- // NewImageFromJSON creates an Image configuration from json.
101- func NewImageFromJSON (src []byte ) (* Image , error ) {
102- img := & Image {}
103- if err := json .Unmarshal (src , img ); err != nil {
116+ // PlatformFromJSON returns an OCI platform from formatted JSON bytes
117+ func PlatformFromJSON (src []byte ) (* ocispec.Platform , error ) {
118+ var platform ocispec.Platform
119+ if err := json .Unmarshal (src , & platform ); err != nil {
104120 return nil , err
105121 }
106- return img , nil
122+ return & platform , nil
107123}
0 commit comments