@@ -21,6 +21,7 @@ import (
2121 "context"
2222 "encoding/json"
2323 "fmt"
24+ "path/filepath"
2425 "time"
2526
2627 modelspec "github.com/CloudNativeAI/modctl/pkg/spec"
@@ -38,7 +39,7 @@ type ModelConfig struct {
3839}
3940
4041// BuildLayer converts the file to the image blob and push it to the storage.
41- func BuildLayer (ctx context.Context , store storage.Storage , repo , path string ) (ocispec.Descriptor , error ) {
42+ func BuildLayer (ctx context.Context , store storage.Storage , repo , path , workDir string ) (ocispec.Descriptor , error ) {
4243 reader , err := TarFileToStream (path )
4344 if err != nil {
4445 return ocispec.Descriptor {}, fmt .Errorf ("failed to tar file: %w" , err )
@@ -49,11 +50,24 @@ func BuildLayer(ctx context.Context, store storage.Storage, repo, path string) (
4950 return ocispec.Descriptor {}, fmt .Errorf ("failed to push blob to storage: %w" , err )
5051 }
5152
53+ absPath , err := filepath .Abs (workDir )
54+ if err != nil {
55+ return ocispec.Descriptor {}, fmt .Errorf ("failed to get absolute path of workDir: %w" , err )
56+ }
57+
58+ filePath , err := filepath .Rel (absPath , path )
59+ if err != nil {
60+ return ocispec.Descriptor {}, fmt .Errorf ("failed to get relative path: %w" , err )
61+ }
62+
5263 return ocispec.Descriptor {
5364 ArtifactType : modelspec .ArtifactTypeModelLayer ,
5465 MediaType : ocispec .MediaTypeImageLayer ,
5566 Digest : godigest .Digest (digest ),
5667 Size : size ,
68+ Annotations : map [string ]string {
69+ modelspec .AnnotationFilepath : filePath ,
70+ },
5771 }, nil
5872}
5973
0 commit comments