Skip to content

Support modelpack/model-spec file path #498

@bitoku

Description

@bitoku

In the model-spec, org.cncf.model.filepath annotation is supposed to be used as a file path when mounting.

https://github.com/modelpack/model-spec/blob/e262ddc3d2bf8036b81de7768a5edfbe67045f4e/specs-go/v1/annotations.go#L22-L23

However libartifact can only use org.opencontainers.image.title as a file path.

// BlobMountPaths allows the caller to access the file names from the store and how they should be mounted.
func (as ArtifactStore) BlobMountPaths(ctx context.Context, nameOrDigest string, options *libartTypes.BlobMountPathOptions) ([]libartTypes.BlobMountPath, error) {
arty, imgSrc, err := getArtifactAndImageSource(ctx, as, nameOrDigest, &options.FilterBlobOptions)
if err != nil {
return nil, err
}
defer imgSrc.Close()
if len(options.Digest) > 0 || len(options.Title) > 0 {
digest, err := findDigest(arty, &options.FilterBlobOptions)
if err != nil {
return nil, err
}
// In case the digest is set we always use it as target name
// so we do not have to get the actual title annotation form the blob.
// Passing options.Title is enough because we know it is empty when digest
// is set as we only allow either one.
filename, err := generateArtifactBlobName(options.Title, digest)
if err != nil {
return nil, err
}
path, err := layout.GetLocalBlobPath(ctx, imgSrc, digest)
if err != nil {
return nil, err
}
return []libartTypes.BlobMountPath{{
SourcePath: path,
Name: filename,
}}, nil
}
mountPaths := make([]libartTypes.BlobMountPath, 0, len(arty.Manifest.Layers))
for _, l := range arty.Manifest.Layers {
title := l.Annotations[specV1.AnnotationTitle]
for _, mp := range mountPaths {
if title == mp.Name {
return nil, fmt.Errorf("annotation %q:%q is used in multiple different layers within artifact", specV1.AnnotationTitle, title)
}
}
filename, err := generateArtifactBlobName(title, l.Digest)
if err != nil {
return nil, err
}
path, err := layout.GetLocalBlobPath(ctx, imgSrc, l.Digest)
if err != nil {
return nil, err
}
mountPaths = append(mountPaths, libartTypes.BlobMountPath{
SourcePath: path,
Name: filename,
})
}
return mountPaths, nil
}

I'm not sure what is the best way though.
Off the top of my head, BlobMountPaths could accept file path annotation as an argument, or we could introduce a new option for filepath.
Do you have any plan to use org.cncf.model.filepath as a file path?

The past discussion regarding the file path annotation: modelpack/model-spec#58

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions