container

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractLayer

func ExtractLayer(ctx context.Context, dst string, src oras.ReadOnlyTarget, desc ocispec.Descriptor) (*os.File, error)

ExtractLayer is like ExtractLayers but applied to a single layer.

func ExtractLayers

func ExtractLayers(ctx context.Context, dst string, src oras.ReadOnlyTarget, layers []ocispec.Descriptor) ([]*os.File, error)

ExtractLayers fetches the image layers represented by the list of descriptors and extracts them at the dst file path.

The content of the layers is written in a directory named after their digest algorithm, and uncompressed in a tar archive named with their digest hash.

(dst)
 └── sha256
    └── 8c6d1654570f041603f4cef49c320c8f6f3e401324913009d92a19132cbf1ac0
        ...

The function performs the extraction of each layer concurrently, each layer is processed in a dedicated goroutine.

The operation is atomic, either the creation of the layer fully succeeds or it fails and the layer is not present in the directory.

func FetchImage

func FetchImage(ctx context.Context, src oras.ReadOnlyTarget, ref string, p *ocispec.Platform) (image *ocispec.Image, layers []ocispec.Descriptor, err error)

FetchImage retrieves an image from src. The image is identified by the given reference and filtered to match the specified platform.

The function returns the pair of the image definition and the list of descriptors to retrieve the image layers (see ExtractLayers).

The platform must not be nil or the function errors.

func FetchLayer

func FetchLayer(ctx context.Context, src oras.ReadOnlyTarget, desc ocispec.Descriptor) (io.ReadCloser, error)

FetchLayer returns a reader exposing the uncompressed content of an image layer retrieved from src and represented by desc.

func RootFS

func RootFS(ctx context.Context, dst string, src oras.ReadOnlyTarget, image *ocispec.Image, layers []ocispec.Descriptor) ([]*os.File, error)

RootFS returns a slice of files opened on the tar files of layers making the root file system of a container image.

The function automatically fetches and extracts missing layers using the src store and the list of descriptors representing the compressed image layers.

The dst parameter is the directory where the layers are extracted, it must exist or the function will error.

Types

type ImageCache

type ImageCache struct {
	// The local store where images and tags are cached.
	//
	// If nil, the cache does not store images but still performs resolution of
	// the image names.
	LocalStore oras.Target
	// If non-nil, configures a platform of images that can be fetched.
	TargetPlatform *ocispec.Platform
	// A function used to construct the remote repository used to lookupg remote
	// images.
	//
	// This function can usually be left nil, the cache will create instances of
	// remote.Repository by default. It is useful to set if the configuration of
	// the remote.Repository instance needs to be customized.
	RemoteRepository func(registry.Reference) oras.ReadOnlyTarget
}

ImageCache is an implementation of oras.ReadOnlyRegistry which copies remote images fetched by the program to a local store for faster retrieval.

The cache uses the "org.opencontainers.image.ref.name" annotation to perform automatic name resolution on the images.

ImageCache values are safe for concurrent use by multiple goroutines as long as none of its properties are mutated while its methods are called.

func (*ImageCache) Exists

func (c *ImageCache) Exists(ctx context.Context, target ocispec.Descriptor) (bool, error)

func (*ImageCache) Fetch

func (c *ImageCache) Fetch(ctx context.Context, target ocispec.Descriptor) (io.ReadCloser, error)

func (*ImageCache) Resolve

func (c *ImageCache) Resolve(ctx context.Context, reference string) (ocispec.Descriptor, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL