containerd/images
Tianon Gravi 21b3318ebe Fix several conversions of "ocispec.Image" to "ocispec.Platform"
Several bits of code unmarshal image config JSON into an `ocispec.Image`, and then immediately create an `ocispec.Platform` out of it, but then discard the original image *and* miss several potential platform fields (most notably, `variant`).

Because `ocispec.Platform` is a strict subset of `ocispec.Image`, most of these can be updated to simply unmarshal the image config directly to `ocispec.Platform` instead, which allows these additional fields to be picked up appropriately.

We can use `tianon/raspbian` as a concrete reproducer to demonstrate.

Before:

```console
$ ctr content fetch docker.io/tianon/raspbian:bullseye-slim
...

$ ctr image ls
REF                                     TYPE                                                 DIGEST                                                                  SIZE     PLATFORMS    LABELS
docker.io/tianon/raspbian:bullseye-slim application/vnd.docker.distribution.manifest.v2+json sha256:66e96f8af40691b335acc54e5f69711584ef7f926597b339e7d12ab90cc394ce 28.6 MiB linux/arm/v7 -
```

(Note that the `PLATFORMS` column lists `linux/arm/v7` -- the image itself is actually `linux/arm/v6`, but one of these bits of code leads to only `linux/arm` being extracted from the image config, which `platforms.Normalize` then updates to an explicit `v7`.)

After:

```console
$ ctr image ls
REF                                     TYPE                                                 DIGEST                                                                  SIZE     PLATFORMS    LABELS
docker.io/tianon/raspbian:bullseye-slim application/vnd.docker.distribution.manifest.v2+json sha256:66e96f8af40691b335acc54e5f69711584ef7f926597b339e7d12ab90cc394ce 28.6 MiB linux/arm/v6 -
```

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
2023-05-30 13:13:02 -07:00
..
archive archive: consistently respect value of WithSkipDockerManifest 2023-03-06 16:27:13 +00:00
converter go.mod: github.com/opencontainers/image-spec v1.1.0-rc3 2023-05-09 23:35:58 +09:00
annotations.go Use a single custom annotation for export 2019-05-21 17:21:26 -07:00
diffid.go go.mod: github.com/opencontainers/image-spec v1.1.0-rc3 2023-05-09 23:35:58 +09:00
handlers.go feat: replace github.com/pkg/errors to errors 2022-01-07 10:27:03 +08:00
image_test.go images: validate document type before unmarshal 2021-11-15 11:54:11 -08:00
image.go Fix several conversions of "ocispec.Image" to "ocispec.Platform" 2023-05-30 13:13:02 -07:00
importexport.go Refactor image importer 2018-09-14 14:21:26 -07:00
mediatypes.go go.mod: github.com/opencontainers/image-spec v1.1.0-rc3 2023-05-09 23:35:58 +09:00