MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / craftImage

Function craftImage

pkg/blobmanager/oci/backend.go:142–166  ·  view source on GitHub ↗
(content []byte, resource *pb.CASResource)

Source from the content-addressed store, hash-verified

140}
141
142func craftImage(content []byte, resource *pb.CASResource) (v1.Image, error) {
143 if len(content) == 0 {
144 return nil, errors.New("content is empty")
145 }
146
147 if resource == nil || resource.FileName == "" || resource.Digest == "" {
148 return nil, errors.New("resource metadata is not valid")
149 }
150
151 base := mutate.MediaType(empty.Image, types.OCIManifestSchema1)
152 base = mutate.ConfigMediaType(base, types.OCIConfigJSON)
153 base = mutate.Annotations(base, map[string]string{
154 ocispec.AnnotationAuthors: backend.AuthorAnnotation,
155 // TODO: Move this annotation to layer
156 ocispec.AnnotationTitle: resource.FileName,
157 }).(v1.Image)
158
159 layer := static.NewLayer(content, backend.DetectedMediaType(content))
160 img, err := mutate.Append(base, mutate.Addendum{Layer: layer})
161 if err != nil {
162 return nil, err
163 }
164
165 return img, nil
166}
167
168func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, error) {
169 if digest == "" {

Callers 2

TestCraftImageMethod · 0.85
UploadMethod · 0.85

Calls 2

AnnotationsMethod · 0.80
AppendMethod · 0.80

Tested by 1

TestCraftImageMethod · 0.68