oci

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 33 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package oci keeps container images for `monolith container`: it pulls them from registries and converts each into an ext4 disk image that a container VM boots as its root filesystem.

Layout under ~/.monolith/images/:

refs.json             image references -> image ID
<id>/rootfs.img       the image's filesystem (sparse ext4)
<id>/image.json       config (entrypoint, env, ...), references, sizes

An image ID is the hex digest of the image's config, like Docker's.

Index

Constants

This section is empty.

Variables

View Source
var (
	PlatformARM64 = v1.Platform{OS: "linux", Architecture: "arm64"}
	PlatformAMD64 = v1.Platform{OS: "linux", Architecture: "amd64"}
)
View Source
var ErrNotFound = errors.New("image not found")

ErrNotFound is returned when no local image matches a reference.

Functions

func Display

func Display(ref string) string

Display shortens a normalized reference the way Docker shows it: "index.docker.io/library/alpine:3.21" becomes "alpine:3.21".

func EstimateDiskSize

func EstimateDiskSize(compressed int64) int64

EstimateDiskSize sizes an image's filesystem from its compressed layers: four times their size (layers rarely compress better than that) plus 512 MiB, at least 1 GiB, in 256 MiB steps.

func HumanSize

func HumanSize(n int64) string

HumanSize formats bytes like Docker: "3.4MB", "1.2GB".

func LoadRef added in v0.0.2

func LoadRef(ref string) (name.Tag, error)

LoadRef parses a reference for loading. The image is written under this name, so it must have a tag (none means latest); digests are refused.

func Normalize

func Normalize(ref string) (string, error)

Normalize turns a user's reference ("alpine", "nginx:1.29", "ghcr.io/o/r@sha256:...") into its full form ("index.docker.io/library/alpine:latest").

func ParseLoadPlatform added in v0.0.2

func ParseLoadPlatform(s string) (*v1.Platform, error)

ParseLoadPlatform accepts the platforms a cluster can run: linux/arm64 natively, linux/amd64 through Rosetta.

func Relabel added in v0.0.2

func Relabel(img v1.Image) (v1.Image, error)

Relabel marks img as linux/arm64 without touching its layers, so the node accepts it; Rosetta then runs its x86-64 binaries.

func RelabelArchive added in v0.0.2

func RelabelArchive(path string, tag name.Tag, w io.Writer, progress func(int64)) error

RelabelArchive reads the image tag from a `docker save` archive at path and writes it to w relabelled as linux/arm64 (images exported from an amd64 docker host). progress gets the archive bytes read so far.

Types

type ConvertStats

type ConvertStats struct {
	Files, Dirs, Symlinks, Hardlinks int
	Skipped                          int // device nodes and FIFOs: devtmpfs provides /dev
	XattrsDropped                    int // files whose extended attributes were lost
	DiskBytes                        int64
}

ConvertStats describes a conversion.

func Convert

func Convert(img v1.Image, diskPath string, size int64) (ConvertStats, error)

Convert flattens img's layers (whiteouts applied) into a new ext4 disk image of size bytes at diskPath. It fails with errFull if they don't fit.

go-diskfs has gaps this works around: it has no hard links (the target's content is copied), no device nodes (skipped) and no extended attributes (dropped, which loses file capabilities). Writing to a directory also resets the mode and owner of inodes written before, so all metadata is applied in a final pass. Its mkfs writes out every inode table, so the zero runs are punched out of the file at the end. Its reserved GDT blocks (resize_inode) are misplaced, which makes the kernel refuse to grow the filesystem, so they're left out: without them the kernel grows it by switching to meta_bg.

type Image

type Image struct {
	ID        string    `json:"id"`         // config digest, hex
	Refs      []string  `json:"refs"`       // normalized references pointing at it
	Config    v1.Config `json:"config"`     // entrypoint, cmd, env, user, workdir, ...
	Platform  string    `json:"platform"`   // e.g. "linux/arm64"
	Created   time.Time `json:"created"`    // when it was pulled
	Size      int64     `json:"size"`       // compressed layer bytes, as registries report it
	DiskBytes int64     `json:"disk_bytes"` // space rootfs.img takes on the Mac
	Layers    []string  `json:"layers"`     // layer digests, kept in the blob cache
}

Image is a converted image in the store.

func (Image) ShortID

func (i Image) ShortID() string

ShortID is the first 12 hex digits of the ID.

type LayerReporter added in v0.0.2

type LayerReporter interface {
	SetLayer(i int, status string, done, total int64)
}

LayerReporter receives per-layer progress (LoadGroup implements it).

type LoadGroup added in v0.0.2

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

LoadGroup is one image in a LoadView.

func (*LoadGroup) Done added in v0.0.2

func (g *LoadGroup) Done()

Done finishes the image.

func (*LoadGroup) Fail added in v0.0.2

func (g *LoadGroup) Fail(err error)

Fail finishes the image with an error.

func (*LoadGroup) SetLayer added in v0.0.2

func (g *LoadGroup) SetLayer(i int, status string, done, total int64)

SetLayer updates layer line i.

func (*LoadGroup) Stage added in v0.0.2

func (g *LoadGroup) Stage(status string, done, total int64)

Stage sets the image's stage line ("Loading into cluster-default"). Off a terminal a changed stage is printed.

func (*LoadGroup) Start added in v0.0.2

func (g *LoadGroup) Start(note string, layerIDs []string)

Start marks the image active with a note ("arm64") and its layer ids.

type LoadView added in v0.0.2

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

LoadView shows several images loading at once, like `docker pull` per image: a header, one line per layer and a stage line. On a terminal the active images are redrawn in place; a finished image is printed once, as a single line, above them, so a long list never outgrows the screen. Off a terminal each image prints a line per stage.

func NewLoadView added in v0.0.2

func NewLoadView(w io.Writer, tty bool) *LoadView

func (*LoadView) Add added in v0.0.2

func (v *LoadView) Add(name string) *LoadGroup

Add appends an image, waiting until Start.

func (*LoadView) Close added in v0.0.2

func (v *LoadView) Close()

Close draws the final state and stops redrawing.

type PullOptions

type PullOptions struct {
	Platform v1.Platform // default linux/arm64
	Log      io.Writer   // progress; nil discards it
	TTY      bool        // Log is a terminal: redraw progress in place
}

PullOptions configures Pull.

type Removal

type Removal struct {
	Image   Image
	Deleted bool // false: only the reference was dropped (others remain)
	// KeptLayers counts the image's cached layers kept because other
	// images (SharedWith) use them.
	KeptLayers int
	SharedWith []string
	Freed      int64 // bytes given back: the image disk's private part and deleted layers
}

Removal describes what Remove did.

type Resolved added in v0.0.2

type Resolved struct {
	Image     v1.Image
	Platform  v1.Platform   // the variant picked
	Relabel   bool          // not arm64: relabel it, Rosetta runs it
	Available []v1.Platform // what the registry has
	Size      int64         // compressed layers, as the registry reports
	Layers    []v1.Layer
}

Resolved is an image picked for loading.

func Resolve added in v0.0.2

func Resolve(ctx context.Context, ref name.Tag, want *v1.Platform) (*Resolved, error)

Resolve looks ref up in its registry and picks the variant to load: want if given, else arm64, else amd64.

type Store

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

Store is the local image store.

func Open

func Open() (*Store, error)

Open returns the store at ~/.monolith/images.

func OpenAt

func OpenAt(dir string) (*Store, error)

OpenAt returns a store rooted at dir (tests use a temporary directory).

func (*Store) DiskPath

func (s *Store) DiskPath(id string) string

DiskPath is the root filesystem image of image id.

func (*Store) Fetch added in v0.0.2

func (s *Store) Fetch(ctx context.Context, r *Resolved, view LayerReporter) error

Fetch downloads r's layers into the blob cache, reporting each on line i of view. Hold SharedLock while fetching and writing.

func (*Store) FilesystemSize

func (s *Store) FilesystemSize(id string) (int64, error)

FilesystemSize is the size of image id's filesystem: the smallest disk a container of it can have.

func (*Store) List

func (s *Store) List() ([]Image, error)

List returns all images, newest first.

func (*Store) Lookup

func (s *Store) Lookup(ref string) (Image, error)

Lookup finds a local image by reference, full ID or unique ID prefix.

func (*Store) Pull

func (s *Store) Pull(ctx context.Context, ref string, opts PullOptions) (Image, error)

Pull fetches ref from its registry and converts it, unless the same image is already in the store, in which case only the reference is updated. Credentials come from the Docker config (~/.docker/config.json and its credential helpers).

func (*Store) Reclaimable

func (s *Store) Reclaimable(ids []string) int64

Reclaimable estimates the space removing images ids would free: the part of each image's disk not shared with containers' clones, plus the cached layers only those images use.

func (*Store) Remove

func (s *Store) Remove(ref string) (Removal, error)

Remove deletes an image by reference or ID. Removing by reference only drops that reference while others remain; the image itself goes with its last reference, or at once when removed by ID. Cached layers go with the last image that uses them.

func (*Store) SharedLock added in v0.0.2

func (s *Store) SharedLock() (func(), error)

SharedLock keeps pulls and removals (which prune unused blobs) out while the caller reads the blob cache, but lets other shared holders in: one `cluster load` takes it for its whole run.

func (*Store) WriteTarball added in v0.0.2

func (s *Store) WriteTarball(r *Resolved, tag name.Tag, w io.Writer, progress func(int64)) error

WriteTarball writes r (relabelled if needed) as a `docker save` tarball named tag, reading the layers Fetch put in the blob cache. progress gets the layer bytes read so far.

Jump to

Keyboard shortcuts

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