oci

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package oci loads container images into flat file trees that catalogers can walk. It reads two on-disk shapes without any registry access: a `docker save` tarball (manifest.json + layer tars) and an OCI image layout (an `oci-layout`/`index.json`/`blobs` directory, or that same layout inside a tar). Layers are applied in order with whiteout semantics so the result is the image's effective filesystem. It re-implements only what it needs from the OCI spec; it does not depend on any container tooling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Path is a slash-separated path relative to the tree root, with no
	// leading slash (e.g. "var/lib/dpkg/status").
	Path string
	Mode fs.FileMode
	Size int64
	// Data holds the full file contents. Images are loaded into memory; this
	// is fine for the small fixtures the tool is tested against and keeps
	// catalogers simple. Large-image streaming is a later concern.
	Data []byte
}

File is a regular file extracted from an image layer or a filesystem.

type FileTree

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

FileTree is the flattened, effective filesystem of an image (or a scanned directory): the union of all layers with whiteouts applied.

func TreeFromDir

func TreeFromDir(dir string) (*FileTree, error)

TreeFromDir walks an on-disk directory into a FileTree, as if it were a flattened image root. Symlinks are skipped; only regular files are read.

func TreeFromMap

func TreeFromMap(files map[string][]byte) *FileTree

TreeFromMap builds a FileTree from a path -> contents map. Paths are normalized (leading slashes and "./" stripped). It is a convenience for callers that already hold file contents in memory, and for tests.

func (*FileTree) Files

func (t *FileTree) Files() []*File

Files returns every file in the tree sorted by path, for deterministic walking by catalogers.

func (*FileTree) Get

func (t *FileTree) Get(p string) (*File, bool)

Get returns the file at path (with or without a leading slash) if present.

type Image

type Image struct {
	// RepoTags are the "name:tag" references recorded for the image, if any.
	RepoTags []string
	// ConfigDigest is the sha256 digest of the image config blob (e.g.
	// "sha256:abc..."), or "" if unknown.
	ConfigDigest string
	// Config is the raw image config JSON.
	Config []byte
	Layers []*Layer
}

Image is a loaded container image.

func Load

func Load(p string) (*Image, error)

Load reads an image from a path. The path may be a `docker save` tarball, an OCI-layout tarball, or an OCI-layout directory.

func (*Image) Flatten

func (img *Image) Flatten() *FileTree

Flatten collapses the image's layers into a single FileTree, applying whiteouts and opaque-directory markers in layer order.

type Layer

type Layer struct {
	Index  int
	Digest string
	Files  []*File
	// Whiteouts lists whiteout markers this layer carried, as cleaned paths of
	// the deleted target (opaque markers keep their ".wh..wh..opq" basename).
	Whiteouts []string
}

Layer is one image layer: the raw set of entries it introduced, before any whiteouts from later layers are applied. Keeping per-layer files available lets later capabilities (e.g. secret scanning) inspect deleted content.

Jump to

Keyboard shortcuts

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