images

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAmbiguous = errors.New("image ref resolves to multiple backends")

ErrAmbiguous reports an image ref that matches more than one backend.

Functions

func BuildGCModule

func BuildGCModule[I any](cfg GCModuleConfig[I]) gc.Module[ImageGCSnapshot]

BuildGCModule constructs a gc.Module from the config.

func GCCollectBlobs

func GCCollectBlobs(ctx context.Context, module, tempDir string, dirOnly bool, ids []string, removers ...func(string) error) error

GCCollectBlobs removes temp files and blob artifacts by hex ID; module names the gc subsystem for log routing. removers are called for each hex; fs.ErrNotExist errors are ignored.

func GCStaleTemp

func GCStaleTemp(ctx context.Context, dir string, dirOnly bool) []error

GCStaleTemp removes temp entries older than StaleTempAge; dirOnly=true skips files. .lock files are never removed — flock syncs on inode, so deleting one races with a current holder.

func LookupRefs

func LookupRefs[E Entry](images map[string]*E, id string, normalizers ...func(string) (string, bool)) []string

LookupRefs returns all ref keys matching id by exact key, normalizer, or digest prefix.

func NewStore

func NewStore[T any](filePath, lockPath string) (storage.Store[T], lock.Locker)

NewStore returns a JSON-backed Store and its locker; both share the same flock file so the locker can be passed to gc.Module independently.

func ReferencedDigests

func ReferencedDigests[E Entry](images map[string]*E) map[string]struct{}

ReferencedDigests collects all blob digest hex strings referenced by any (*entry).

Types

type BaseConfig

type BaseConfig struct {
	Root    *config.Config
	Subdir  string
	BlobExt string
}

BaseConfig is the directory layout shared by all image backends.

func (*BaseConfig) BackendDir

func (c *BaseConfig) BackendDir() string

func (*BaseConfig) BlobPath

func (c *BaseConfig) BlobPath(hex string) string

func (*BaseConfig) BlobsDir

func (c *BaseConfig) BlobsDir() string

func (*BaseConfig) DBDir

func (c *BaseConfig) DBDir() string

func (*BaseConfig) EnsureBaseDirs

func (c *BaseConfig) EnsureBaseDirs() error

func (*BaseConfig) IndexFile

func (c *BaseConfig) IndexFile() string

func (*BaseConfig) IndexLock

func (c *BaseConfig) IndexLock() string

func (*BaseConfig) TempDir

func (c *BaseConfig) TempDir() string

type Digest

type Digest string

Digest represents a content-addressable digest in "algorithm:hex" format (e.g., "sha256:abcdef..."). Backed by opencontainers/go-digest.

func NewDigest

func NewDigest(hex string) Digest

func (Digest) Hex

func (d Digest) Hex() string

func (Digest) String

func (d Digest) String() string

type Entry

type Entry interface {
	EntryID() string
	EntryRef() string
	EntryCreatedAt() time.Time
	DigestHexes() []string
}

Entry defines the common behavior of an image index (*entry). Both OCI and cloudimg imageEntry types implement this with value receivers.

type GCModuleConfig

type GCModuleConfig[I any] struct {
	Name   string
	Locker lock.Locker
	Store  storage.Store[I]
	// ReadRefs extracts referenced digest hexes from the index.
	ReadRefs func(*I) map[string]struct{}
	// ScanDisk returns digest hexes found on disk (blobs).
	ScanDisk func() ([]string, error)
	// ExtraDisk returns additional hex IDs on disk (e.g., OCI boot dirs). Optional.
	ExtraDisk func() ([]string, error)
	// Removers are called per hex ID during collect.
	Removers []func(string) error
	// TempDir for stale temp cleanup.
	TempDir string
	// DirOnly: true for OCI (temp dirs), false for cloudimg (temp files).
	DirOnly bool
}

GCModuleConfig configures a generic image GC module.

type ImageGCSnapshot

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

ImageGCSnapshot is the unified GC snapshot for image backends.

type Images

type Images interface {
	Type() string

	Pull(ctx context.Context, ref string, force bool, tracker progress.Tracker) error
	Import(ctx context.Context, name string, tracker progress.Tracker, file ...string) error
	Inspect(context.Context, string) (*types.Image, error)
	List(context.Context) ([]*types.Image, error)
	Delete(context.Context, []string) ([]string, error)
	RegisterGC(*gc.Orchestrator)

	Config(context.Context, []*types.VMConfig) ([][]*types.StorageConfig, []*types.BootConfig, error)
}

Images defines the interface for an image backend (OCI, cloudimg).

type Index

type Index[E any] struct {
	Images map[string]*E `json:"images"`
}

Index is the shared generic base for image indices. Both backends embed Index[imageEntry] to inherit Init() and the Images map.

func (*Index[E]) Init

func (idx *Index[E]) Init()

Init implements storage.Initer. Called automatically by storejson.Store after loading.

type Ops

type Ops[I any, E Entry] struct {
	Store      storage.Store[I]
	Type       string
	LookupRefs func(*I, string) []string
	Entries    func(*I) map[string]*E
	Sizer      func(*E) int64
}

Ops bundles the store and callbacks shared by Inspect/List/Delete. Each backend creates one Ops instance during initialization.

func (Ops[I, E]) Delete

func (ops Ops[I, E]) Delete(ctx context.Context, ids []string) (deleted []string, err error)

Delete deletes entries from an index by ids and returns removed refs.

func (Ops[I, E]) Inspect

func (ops Ops[I, E]) Inspect(ctx context.Context, id string) (result *types.Image, err error)

Inspect returns (nil, nil) when no entry matches id.

func (Ops[I, E]) List

func (ops Ops[I, E]) List(ctx context.Context) (result []*types.Image, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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