ImageConfig returns the OCI config of a given image. Use [ImageWithPlatform] to select a platform from an Index or Manifest List.
(ctx context.Context, r ref.Ref, opts ...ImageOpts)
| 467 | // ImageConfig returns the OCI config of a given image. |
| 468 | // Use [ImageWithPlatform] to select a platform from an Index or Manifest List. |
| 469 | func (rc *RegClient) ImageConfig(ctx context.Context, r ref.Ref, opts ...ImageOpts) (*blob.BOCIConfig, error) { |
| 470 | opt := imageOpt{ |
| 471 | platform: "local", |
| 472 | } |
| 473 | for _, optFn := range opts { |
| 474 | optFn(&opt) |
| 475 | } |
| 476 | // dedup warnings |
| 477 | if w := warning.FromContext(ctx); w == nil { |
| 478 | ctx = warning.NewContext(ctx, &warning.Warning{Hook: warning.DefaultHook()}) |
| 479 | } |
| 480 | p, err := platform.Parse(opt.platform) |
| 481 | if err != nil { |
| 482 | return nil, fmt.Errorf("failed to parse platform %s: %w", opt.platform, err) |
| 483 | } |
| 484 | m, err := rc.ManifestGet(ctx, r, WithManifestPlatform(p)) |
| 485 | if err != nil { |
| 486 | return nil, fmt.Errorf("failed to get manifest: %w", err) |
| 487 | } |
| 488 | for m.IsList() { |
| 489 | mi, ok := m.(manifest.Indexer) |
| 490 | if !ok { |
| 491 | return nil, fmt.Errorf("unsupported manifest type: %s", m.GetDescriptor().MediaType) |
| 492 | } |
| 493 | ml, err := mi.GetManifestList() |
| 494 | if err != nil { |
| 495 | return nil, fmt.Errorf("failed to get manifest list: %w", err) |
| 496 | } |
| 497 | d, err := descriptor.DescriptorListSearch(ml, descriptor.MatchOpt{Platform: &p}) |
| 498 | if err != nil { |
| 499 | return nil, fmt.Errorf("failed to find platform in manifest list: %w", err) |
| 500 | } |
| 501 | m, err = rc.ManifestGet(ctx, r, WithManifestDesc(d)) |
| 502 | if err != nil { |
| 503 | return nil, fmt.Errorf("failed to get manifest: %w", err) |
| 504 | } |
| 505 | } |
| 506 | mi, ok := m.(manifest.Imager) |
| 507 | if !ok { |
| 508 | return nil, fmt.Errorf("unsupported manifest type: %s", m.GetDescriptor().MediaType) |
| 509 | } |
| 510 | d, err := mi.GetConfig() |
| 511 | if err != nil { |
| 512 | return nil, fmt.Errorf("failed to get image config: %w", err) |
| 513 | } |
| 514 | if d.MediaType != mediatype.OCI1ImageConfig && d.MediaType != mediatype.Docker2ImageConfig { |
| 515 | return nil, fmt.Errorf("unsupported config media type %s: %w", d.MediaType, errs.ErrUnsupportedMediaType) |
| 516 | } |
| 517 | return rc.BlobGetOCIConfig(ctx, r, d) |
| 518 | } |
| 519 | |
| 520 | // ImageCopy copies an image. |
| 521 | // This will retag an image in the same repository, only pushing and pulling the top level manifest. |