mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
libartifact: add BlobMountPaths()
The goal of this new interface is to expose the blob source path and the target file name for a bind mount into a container. libpod will call this and then take care of setting up the actual mounts based on the returned paths. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -346,6 +346,56 @@ func getArtifactAndImageSource(ctx context.Context, as ArtifactStore, nameOrDige
|
|||||||
return arty, imgSrc, err
|
return arty, imgSrc, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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]
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// Extract an artifact to local file or directory
|
// Extract an artifact to local file or directory
|
||||||
func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target string, options *libartTypes.ExtractOptions) error {
|
func (as ArtifactStore) Extract(ctx context.Context, nameOrDigest string, target string, options *libartTypes.ExtractOptions) error {
|
||||||
arty, imgSrc, err := getArtifactAndImageSource(ctx, as, nameOrDigest, &options.FilterBlobOptions)
|
arty, imgSrc, err := getArtifactAndImageSource(ctx, as, nameOrDigest, &options.FilterBlobOptions)
|
||||||
|
@ -25,3 +25,15 @@ type FilterBlobOptions struct {
|
|||||||
type ExtractOptions struct {
|
type ExtractOptions struct {
|
||||||
FilterBlobOptions
|
FilterBlobOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BlobMountPathOptions struct {
|
||||||
|
FilterBlobOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlobMountPath contains the info on how the artifact must be mounted
|
||||||
|
type BlobMountPath struct {
|
||||||
|
// Source path of the blob, i.e. full path in the blob dir.
|
||||||
|
SourcePath string
|
||||||
|
// Name of the file in the container.
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user