...

Source file src/edge-infra.dev/pkg/f8n/warehouse/oci/mutate/image.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/oci/mutate

     1  package mutate
     2  
     3  import (
     4  	v1 "github.com/google/go-containerregistry/pkg/v1"
     5  	"github.com/google/go-containerregistry/pkg/v1/empty"
     6  	"github.com/google/go-containerregistry/pkg/v1/mutate"
     7  )
     8  
     9  // TODO: implement v1.Image and use private struct for mutatings a la ggcr?
    10  
    11  // ReplaceLayers removes all v1.Layers from img and creates a new image containing
    12  // layers, preserving the media type and annotations from img.
    13  //
    14  // NOTE: v1.Layer is used instead of layer.Layer for interop and because this
    15  // function does not leverage any of the additional functionality layer.Layer
    16  // provides.
    17  func ReplaceLayers(img v1.Image, layers ...v1.Layer) (v1.Image, error) {
    18  	m, err := img.Manifest()
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	i, err := mutate.AppendLayers(empty.Image, layers...)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	return mutate.Annotations(
    29  		mutate.MediaType(i, m.MediaType),
    30  		m.Annotations,
    31  	).(v1.Image), nil
    32  }
    33  

View as plain text