oci

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportToDir

func ExportToDir(img *Image, dstDir string) error

ExportToDir copies the prebaked runtime artifacts for img into dstDir. The destination will contain config.json plus all referenced *.idx/*.contents.

func IsLocalTar

func IsLocalTar(imageRef string) bool

IsLocalTar checks if the image reference is a local tar file.

func ParseImageRef

func ParseImageRef(imageRef string) (registry string, image string, tag string, err error)

ParseImageRef parses an OCI image reference into registry, image, and tag.

func ValidateImageName added in v0.0.2

func ValidateImageName(imageRef string, checkRegistry bool) error

ValidateImageName validates an OCI image name format and optionally checks if it exists in the registry. If checkRegistry is true, it will make a HEAD request to verify the image exists.

func ValidateTar added in v0.0.2

func ValidateTar(tarPath string) error

ValidateTar checks if a file is a valid Docker/OCI tar archive. It opens the tar and verifies it contains a valid manifest.json.

Types

type ArchitectureMismatchError added in v0.0.2

type ArchitectureMismatchError struct {
	Expected string
	Actual   string
}

ArchitectureMismatchError is returned when an image's architecture doesn't match the expected architecture.

func (*ArchitectureMismatchError) Error added in v0.0.2

func (e *ArchitectureMismatchError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an OCI registry client that handles image pulling and caching.

func NewClient

func NewClient(cacheDir string) (*Client, error)

NewClient creates a new OCI client with the specified cache directory.

func (*Client) CacheDir added in v0.0.2

func (c *Client) CacheDir() string

CacheDir returns the cache directory used by this client.

func (*Client) LoadFromTar

func (c *Client) LoadFromTar(tarPath string, arch hv.CpuArchitecture) (*Image, error)

LoadFromTar loads a Docker image from a tar archive created by `docker save`.

func (*Client) Pull

func (c *Client) Pull(imageRef string) (*Image, error)

Pull downloads an OCI image and returns it ready for use.

func (*Client) PullForArch

func (c *Client) PullForArch(imageRef string, arch hv.CpuArchitecture) (*Image, error)

PullForArch downloads an OCI image for a specific architecture.

func (*Client) SetBlobContext added in v0.0.2

func (c *Client) SetBlobContext(index, count int)

SetBlobContext sets the current blob index and total count for progress reporting. This should be called before each blob download to track overall progress.

func (*Client) SetProgressCallback

func (c *Client) SetProgressCallback(callback ProgressCallback)

SetProgressCallback sets a callback function that will be called during downloads. The callback receives progress updates with current/total bytes and filename. Set to nil to disable progress reporting.

type ContainerFS

type ContainerFS struct {
	// contains filtered or unexported fields
}

ContainerFS implements vfs.AbstractDir to provide a layered filesystem view of an OCI container image.

func NewContainerFS

func NewContainerFS(img *Image) (*ContainerFS, error)

NewContainerFS creates a new container filesystem from an OCI image.

func (*ContainerFS) Close

func (cfs *ContainerFS) Close() error

Close releases resources held by the container filesystem.

func (*ContainerFS) Lookup

func (cfs *ContainerFS) Lookup(name string) (vfs.AbstractEntry, error)

Lookup implements vfs.AbstractDir.

func (*ContainerFS) ModTime

func (cfs *ContainerFS) ModTime() time.Time

ModTime implements vfs.AbstractDir.

func (*ContainerFS) ReadDir

func (cfs *ContainerFS) ReadDir() ([]vfs.AbstractDirEntry, error)

ReadDir implements vfs.AbstractDir.

func (*ContainerFS) ResolvePath

func (cfs *ContainerFS) ResolvePath(p string) (string, error)

ResolvePath resolves a path within the container filesystem, following symlinks (including in intermediate components). The returned path is absolute (starts with "/").

This is useful for exec'ing symlink entrypoints as their real targets so the dynamic loader sees the correct executable location (e.g. for $ORIGIN-based RUNPATH).

func (*ContainerFS) Stat

func (cfs *ContainerFS) Stat() fs.FileMode

Stat implements vfs.AbstractDir.

type DownloadProgress

type DownloadProgress struct {
	Current  int64  // Bytes downloaded so far
	Total    int64  // Total bytes to download (-1 if unknown)
	Filename string // Name/path being downloaded

	// Blob count tracking
	BlobIndex int // Index of current blob (0-based)
	BlobCount int // Total number of blobs to download

	// Speed and ETA tracking
	BytesPerSecond float64       // Current download speed in bytes per second
	ETA            time.Duration // Estimated time remaining (-1 if unknown)
}

DownloadProgress represents the current state of a download.

type Image

type Image struct {
	Config RuntimeConfig
	Layers []ImageLayer
	Dir    string // directory containing the image files
}

Image represents a pulled OCI image ready for use.

func LoadFromDir

func LoadFromDir(dir string) (*Image, error)

LoadFromDir loads an image from a prebaked directory containing config.json and layer *.idx/*.contents files.

func LoadFromDirForArch added in v0.0.2

func LoadFromDirForArch(dir string, expectedArch hv.CpuArchitecture) (*Image, error)

LoadFromDirForArch loads an image from a prebaked directory and validates that the image architecture matches the expected architecture.

func (*Image) Command

func (img *Image) Command(overrideCmd []string) []string

Command returns the command to run, combining entrypoint and cmd. If overrideCmd is provided, it replaces the cmd portion.

type ImageLayer

type ImageLayer struct {
	Hash         string // sha256:... digest
	IndexPath    string // path to .idx file
	ContentsPath string // path to .contents file
}

ImageLayer represents a single layer in an OCI image.

type LayeredContainerFS added in v0.0.2

type LayeredContainerFS struct {
	// contains filtered or unexported fields
}

LayeredContainerFS wraps a ContainerFS and adds additional layers on top. It implements vfs.AbstractDir to provide a unified view of all layers.

func NewLayeredContainerFS added in v0.0.2

func NewLayeredContainerFS(base *ContainerFS, layers []ImageLayer) (*LayeredContainerFS, error)

NewLayeredContainerFS creates a new layered container filesystem.

func (*LayeredContainerFS) Base added in v0.0.2

func (lcfs *LayeredContainerFS) Base() *ContainerFS

Base returns the underlying ContainerFS.

func (*LayeredContainerFS) Close added in v0.0.2

func (lcfs *LayeredContainerFS) Close() error

Close releases resources held by the layered container filesystem.

func (*LayeredContainerFS) Lookup added in v0.0.2

func (lcfs *LayeredContainerFS) Lookup(name string) (vfs.AbstractEntry, error)

Lookup implements vfs.AbstractDir.

func (*LayeredContainerFS) ModTime added in v0.0.2

func (lcfs *LayeredContainerFS) ModTime() time.Time

ModTime implements vfs.AbstractDir.

func (*LayeredContainerFS) ReadDir added in v0.0.2

func (lcfs *LayeredContainerFS) ReadDir() ([]vfs.AbstractDirEntry, error)

ReadDir implements vfs.AbstractDir.

func (*LayeredContainerFS) Stat added in v0.0.2

func (lcfs *LayeredContainerFS) Stat() fs.FileMode

Stat implements vfs.AbstractDir.

type ProgressCallback

type ProgressCallback func(progress DownloadProgress)

ProgressCallback is called periodically during downloads.

type RuntimeConfig

type RuntimeConfig struct {
	Layers       []string          `json:"layers"`
	Env          []string          `json:"env,omitempty"`
	Entrypoint   []string          `json:"entrypoint,omitempty"`
	Cmd          []string          `json:"cmd,omitempty"`
	WorkingDir   string            `json:"workingDir,omitempty"`
	User         string            `json:"user,omitempty"`
	UID          *int              `json:"uid,omitempty"`
	GID          *int              `json:"gid,omitempty"`
	Labels       map[string]string `json:"labels,omitempty"`
	Architecture string            `json:"architecture,omitempty"`
}

RuntimeConfig holds the runtime configuration extracted from an OCI image.

Jump to

Keyboard shortcuts

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