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 ¶
- Variables
- func Display(ref string) string
- func EstimateDiskSize(compressed int64) int64
- func HumanSize(n int64) string
- func LoadRef(ref string) (name.Tag, error)
- func Normalize(ref string) (string, error)
- func ParseLoadPlatform(s string) (*v1.Platform, error)
- func Relabel(img v1.Image) (v1.Image, error)
- func RelabelArchive(path string, tag name.Tag, w io.Writer, progress func(int64)) error
- type ConvertStats
- type Image
- type LayerReporter
- type LoadGroup
- type LoadView
- type PullOptions
- type Removal
- type Resolved
- type Store
- func (s *Store) DiskPath(id string) string
- func (s *Store) Fetch(ctx context.Context, r *Resolved, view LayerReporter) error
- func (s *Store) FilesystemSize(id string) (int64, error)
- func (s *Store) List() ([]Image, error)
- func (s *Store) Lookup(ref string) (Image, error)
- func (s *Store) Pull(ctx context.Context, ref string, opts PullOptions) (Image, error)
- func (s *Store) Reclaimable(ids []string) int64
- func (s *Store) Remove(ref string) (Removal, error)
- func (s *Store) SharedLock() (func(), error)
- func (s *Store) WriteTarball(r *Resolved, tag name.Tag, w io.Writer, progress func(int64)) error
Constants ¶
This section is empty.
Variables ¶
var ( PlatformARM64 = v1.Platform{OS: "linux", Architecture: "arm64"} PlatformAMD64 = v1.Platform{OS: "linux", Architecture: "amd64"} )
var ErrNotFound = errors.New("image not found")
ErrNotFound is returned when no local image matches a reference.
Functions ¶
func Display ¶
Display shortens a normalized reference the way Docker shows it: "index.docker.io/library/alpine:3.21" becomes "alpine:3.21".
func EstimateDiskSize ¶
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 LoadRef ¶ added in v0.0.2
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 ¶
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
ParseLoadPlatform accepts the platforms a cluster can run: linux/arm64 natively, linux/amd64 through Rosetta.
func Relabel ¶ added in v0.0.2
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
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 ¶
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.
type LayerReporter ¶ added in v0.0.2
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.
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.
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
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.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the local image store.
func (*Store) Fetch ¶ added in v0.0.2
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 ¶
FilesystemSize is the size of image id's filesystem: the smallest disk a container of it can have.
func (*Store) Pull ¶
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 ¶
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 ¶
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
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
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.