|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "fmt" |
5 | 6 | "regexp" |
6 | 7 | "strconv" |
7 | 8 |
|
8 | 9 | "github.com/google/go-containerregistry/pkg/name" |
| 10 | + containerregistryv1 "github.com/google/go-containerregistry/pkg/v1" |
9 | 11 | "github.com/google/go-containerregistry/pkg/v1/remote" |
| 12 | + ocispecv1 "github.com/opencontainers/image-spec/specs-go/v1" |
10 | 13 | ) |
11 | 14 |
|
12 | 15 | const ( |
13 | 16 | DefaultPgMajor = 18 |
14 | 17 | DefaultDistribution = "trixie" |
15 | 18 | ) |
16 | 19 |
|
17 | | -// getImageLabels returns the OCI labels given an image ref. |
18 | | -func getImageLabels(imageRef string) (map[string]string, error) { |
| 20 | +// getImageAnnotations returns the OCI annotations given an image ref. |
| 21 | +func getImageAnnotations(imageRef string) (map[string]string, error) { |
19 | 22 | ref, err := name.ParseReference(imageRef) |
20 | 23 | if err != nil { |
21 | 24 | return nil, err |
22 | 25 | } |
23 | 26 |
|
24 | | - desc, err := remote.Get(ref) |
| 27 | + head, err := remote.Get(ref) |
25 | 28 | if err != nil { |
26 | 29 | return nil, err |
27 | 30 | } |
28 | 31 |
|
29 | | - img, err := desc.Image() |
30 | | - if err != nil { |
31 | | - return nil, err |
32 | | - } |
33 | | - |
34 | | - cfg, err := img.ConfigFile() |
35 | | - if err != nil { |
36 | | - return nil, err |
| 32 | + switch head.MediaType { |
| 33 | + case ocispecv1.MediaTypeImageIndex: |
| 34 | + indexManifest, err := containerregistryv1.ParseIndexManifest(bytes.NewReader(head.Manifest)) |
| 35 | + if err != nil { |
| 36 | + return nil, err |
| 37 | + } |
| 38 | + return indexManifest.Annotations, nil |
| 39 | + case ocispecv1.MediaTypeImageManifest: |
| 40 | + manifest, err := containerregistryv1.ParseManifest(bytes.NewReader(head.Manifest)) |
| 41 | + if err != nil { |
| 42 | + return nil, err |
| 43 | + } |
| 44 | + return manifest.Annotations, nil |
37 | 45 | } |
38 | 46 |
|
39 | | - return cfg.Config.Labels, nil |
| 47 | + return nil, fmt.Errorf("unsupported media type: %s", head.MediaType) |
40 | 48 | } |
41 | 49 |
|
42 | 50 | // getDefaultExtensionImage returns the default extension image for a given extension, |
43 | 51 | // resolved from the metadata. |
44 | 52 | func getDefaultExtensionImage(metadata *extensionMetadata) (string, error) { |
45 | 53 | packageVersion := metadata.Versions[DefaultDistribution][strconv.Itoa(DefaultPgMajor)] |
| 54 | + if packageVersion == "" { |
| 55 | + return "", fmt.Errorf("no package version found for distribution %q and version %d", |
| 56 | + DefaultDistribution, DefaultPgMajor) |
| 57 | + } |
| 58 | + |
46 | 59 | re := regexp.MustCompile(`^(\d+(?:\.\d+)+)`) |
47 | 60 | matches := re.FindStringSubmatch(packageVersion) |
48 | 61 | if len(matches) < 2 { |
|
0 commit comments