mirror of
https://github.com/distribution/distribution
synced 2024-11-06 19:35:52 +01:00
Remove duplicated platform field from oci index
It is desirable to remove Platform from distribution.Descriptor because it doesn't really belong there. However this would be a further breaking change because the References() call would no longer be returning plaform information when it reurns descriptors of manifests, which is started to for OCI Indices after c94f288 and this feature was added to Docker Manifest Lists in 1a059fe. I don't want to take away something people clearly want. Signed-off-by: Bracken Dawson <abdawson@gmail.com>
This commit is contained in:
parent
973bfbb676
commit
9d1a8fc929
@ -45,21 +45,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A ManifestDescriptor references a platform-specific manifest.
|
|
||||||
type ManifestDescriptor struct {
|
|
||||||
distribution.Descriptor
|
|
||||||
|
|
||||||
// Platform specifies which platform the manifest pointed to by the
|
|
||||||
// descriptor runs on.
|
|
||||||
Platform *v1.Platform `json:"platform,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ImageIndex references manifests for various platforms.
|
// ImageIndex references manifests for various platforms.
|
||||||
type ImageIndex struct {
|
type ImageIndex struct {
|
||||||
manifest.Versioned
|
manifest.Versioned
|
||||||
|
|
||||||
// Manifests references a list of manifests
|
// Manifests references a list of manifests
|
||||||
Manifests []ManifestDescriptor `json:"manifests"`
|
Manifests []distribution.Descriptor `json:"manifests"`
|
||||||
|
|
||||||
// Annotations is an optional field that contains arbitrary metadata for the
|
// Annotations is an optional field that contains arbitrary metadata for the
|
||||||
// image index
|
// image index
|
||||||
@ -69,13 +60,7 @@ type ImageIndex struct {
|
|||||||
// References returns the distribution descriptors for the referenced image
|
// References returns the distribution descriptors for the referenced image
|
||||||
// manifests.
|
// manifests.
|
||||||
func (ii ImageIndex) References() []distribution.Descriptor {
|
func (ii ImageIndex) References() []distribution.Descriptor {
|
||||||
references := make([]distribution.Descriptor, len(ii.Manifests))
|
return ii.Manifests
|
||||||
for i := range ii.Manifests {
|
|
||||||
references[i] = ii.Manifests[i].Descriptor
|
|
||||||
references[i].Platform = ii.Manifests[i].Platform
|
|
||||||
}
|
|
||||||
|
|
||||||
return references
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeserializedImageIndex wraps ManifestList with a copy of the original
|
// DeserializedImageIndex wraps ManifestList with a copy of the original
|
||||||
@ -91,12 +76,12 @@ type DeserializedImageIndex struct {
|
|||||||
// returns a DeserializedManifestList which contains the resulting manifest list
|
// returns a DeserializedManifestList which contains the resulting manifest list
|
||||||
// and its JSON representation. If annotations is nil or empty then the
|
// and its JSON representation. If annotations is nil or empty then the
|
||||||
// annotations property will be omitted from the JSON representation.
|
// annotations property will be omitted from the JSON representation.
|
||||||
func FromDescriptors(descriptors []ManifestDescriptor, annotations map[string]string) (*DeserializedImageIndex, error) {
|
func FromDescriptors(descriptors []distribution.Descriptor, annotations map[string]string) (*DeserializedImageIndex, error) {
|
||||||
return fromDescriptorsWithMediaType(descriptors, annotations, v1.MediaTypeImageIndex)
|
return fromDescriptorsWithMediaType(descriptors, annotations, v1.MediaTypeImageIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fromDescriptorsWithMediaType is for testing purposes, it's useful to be able to specify the media type explicitly
|
// fromDescriptorsWithMediaType is for testing purposes, it's useful to be able to specify the media type explicitly
|
||||||
func fromDescriptorsWithMediaType(descriptors []ManifestDescriptor, annotations map[string]string, mediaType string) (_ *DeserializedImageIndex, err error) {
|
func fromDescriptorsWithMediaType(descriptors []distribution.Descriptor, annotations map[string]string, mediaType string) (_ *DeserializedImageIndex, err error) {
|
||||||
m := ImageIndex{
|
m := ImageIndex{
|
||||||
Versioned: manifest.Versioned{
|
Versioned: manifest.Versioned{
|
||||||
SchemaVersion: IndexSchemaVersion.SchemaVersion,
|
SchemaVersion: IndexSchemaVersion.SchemaVersion,
|
||||||
@ -105,7 +90,7 @@ func fromDescriptorsWithMediaType(descriptors []ManifestDescriptor, annotations
|
|||||||
Annotations: annotations,
|
Annotations: annotations,
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Manifests = make([]ManifestDescriptor, len(descriptors))
|
m.Manifests = make([]distribution.Descriptor, len(descriptors))
|
||||||
copy(m.Manifests, descriptors)
|
copy(m.Manifests, descriptors)
|
||||||
|
|
||||||
deserialized := DeserializedImageIndex{
|
deserialized := DeserializedImageIndex{
|
||||||
|
@ -51,34 +51,28 @@ const expectedOCIImageIndexSerialization = `{
|
|||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
func makeTestOCIImageIndex(t *testing.T, mediaType string) ([]ManifestDescriptor, *DeserializedImageIndex) {
|
func makeTestOCIImageIndex(t *testing.T, mediaType string) ([]distribution.Descriptor, *DeserializedImageIndex) {
|
||||||
manifestDescriptors := []ManifestDescriptor{
|
manifestDescriptors := []distribution.Descriptor{
|
||||||
{
|
{
|
||||||
Descriptor: distribution.Descriptor{
|
|
||||||
MediaType: "application/vnd.oci.image.manifest.v1+json",
|
MediaType: "application/vnd.oci.image.manifest.v1+json",
|
||||||
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
||||||
Size: 985,
|
Size: 985,
|
||||||
},
|
|
||||||
Platform: &v1.Platform{
|
Platform: &v1.Platform{
|
||||||
Architecture: "amd64",
|
Architecture: "amd64",
|
||||||
OS: "linux",
|
OS: "linux",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Descriptor: distribution.Descriptor{
|
|
||||||
MediaType: "application/vnd.oci.image.manifest.v1+json",
|
MediaType: "application/vnd.oci.image.manifest.v1+json",
|
||||||
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
||||||
Size: 985,
|
Size: 985,
|
||||||
Annotations: map[string]string{"platform": "none"},
|
Annotations: map[string]string{"platform": "none"},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Descriptor: distribution.Descriptor{
|
|
||||||
MediaType: "application/vnd.oci.image.manifest.v1+json",
|
MediaType: "application/vnd.oci.image.manifest.v1+json",
|
||||||
Digest: "sha256:6346340964309634683409684360934680934608934608934608934068934608",
|
Digest: "sha256:6346340964309634683409684360934680934608934608934608934068934608",
|
||||||
Size: 2392,
|
Size: 2392,
|
||||||
Annotations: map[string]string{"what": "for"},
|
Annotations: map[string]string{"what": "for"},
|
||||||
},
|
|
||||||
Platform: &v1.Platform{
|
Platform: &v1.Platform{
|
||||||
Architecture: "sun4m",
|
Architecture: "sun4m",
|
||||||
OS: "sunos",
|
OS: "sunos",
|
||||||
@ -135,15 +129,8 @@ func TestOCIImageIndex(t *testing.T) {
|
|||||||
if len(references) != 3 {
|
if len(references) != 3 {
|
||||||
t.Fatalf("unexpected number of references: %d", len(references))
|
t.Fatalf("unexpected number of references: %d", len(references))
|
||||||
}
|
}
|
||||||
for i := range references {
|
if !reflect.DeepEqual(references, manifestDescriptors) {
|
||||||
expectedPlatform := manifestDescriptors[i].Platform
|
t.Errorf("expected references:\n%v\nbut got:\n%v", references, manifestDescriptors)
|
||||||
if !reflect.DeepEqual(references[i].Platform, expectedPlatform) {
|
|
||||||
t.Fatalf("unexpected value %d returned by References: %v", i, references[i])
|
|
||||||
}
|
|
||||||
references[i].Platform = nil
|
|
||||||
if !reflect.DeepEqual(references[i], manifestDescriptors[i].Descriptor) {
|
|
||||||
t.Fatalf("unexpected value %d returned by References: %v", i, references[i])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,9 +186,7 @@ func TestValidateIndex(t *testing.T) {
|
|||||||
Layers: []distribution.Descriptor{{Size: 2}},
|
Layers: []distribution.Descriptor{{Size: 2}},
|
||||||
}
|
}
|
||||||
index := ImageIndex{
|
index := ImageIndex{
|
||||||
Manifests: []ManifestDescriptor{
|
Manifests: []distribution.Descriptor{{Size: 3}},
|
||||||
{Descriptor: distribution.Descriptor{Size: 3}},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
t.Run("valid", func(t *testing.T) {
|
t.Run("valid", func(t *testing.T) {
|
||||||
b, err := json.Marshal(index)
|
b, err := json.Marshal(index)
|
||||||
|
@ -464,20 +464,12 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo
|
|||||||
t.Fatalf("%s: unexpected error getting manifest descriptor", testname)
|
t.Fatalf("%s: unexpected error getting manifest descriptor", testname)
|
||||||
}
|
}
|
||||||
descriptor.MediaType = v1.MediaTypeImageManifest
|
descriptor.MediaType = v1.MediaTypeImageManifest
|
||||||
|
descriptor.Platform = &v1.Platform{
|
||||||
platformSpec := v1.Platform{
|
|
||||||
Architecture: "atari2600",
|
Architecture: "atari2600",
|
||||||
OS: "CP/M",
|
OS: "CP/M",
|
||||||
}
|
}
|
||||||
|
|
||||||
manifestDescriptors := []ocischema.ManifestDescriptor{
|
imageIndex, err := ociIndexFromDesriptorsWithMediaType([]distribution.Descriptor{descriptor}, indexMediaType)
|
||||||
{
|
|
||||||
Descriptor: descriptor,
|
|
||||||
Platform: &platformSpec,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
imageIndex, err := ociIndexFromDesriptorsWithMediaType(manifestDescriptors, indexMediaType)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: unexpected error creating image index: %v", testname, err)
|
t.Fatalf("%s: unexpected error creating image index: %v", testname, err)
|
||||||
}
|
}
|
||||||
@ -575,7 +567,7 @@ func TestLinkPathFuncs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ociIndexFromDesriptorsWithMediaType(descriptors []ocischema.ManifestDescriptor, mediaType string) (*ocischema.DeserializedImageIndex, error) {
|
func ociIndexFromDesriptorsWithMediaType(descriptors []distribution.Descriptor, mediaType string) (*ocischema.DeserializedImageIndex, error) {
|
||||||
manifest, err := ocischema.FromDescriptors(descriptors, nil)
|
manifest, err := ocischema.FromDescriptors(descriptors, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user