Stevedore.Image (Stevedore v0.2.0)

Copy Markdown View Source

An assembled image held in memory: a manifest, its config, the ordered layer descriptors, and the blob bytes backing them.

This is the unit Stevedore.Build and Stevedore.Mutate produce and that Stevedore.copy/3 consumes (a built image can be copied straight to any transport). assemble/3 is the single place that turns a config plus a list of layers into a digest-correct manifest — it always recomputes the config's rootfs.diff_ids, the per-layer/per-config sizes and digests, and the manifest digest, so callers never hand-maintain them.

Spec: OCI image-spec, config (the rootfs.diff_ids / history relationship) and manifest.md.

Summary

Types

A layer being assembled: its (compressed) descriptor, uncompressed diff_id, and bytes.

t()

Functions

The manifest's annotations, if any.

Assembles an image from a full image-config JSON map and a list of layer/0.

Fetches a blob's bytes by digest.

The image's manifest digest.

The image's manifest format (:oci or :docker), inferred from its media type.

Reconstructs the layer/0 records (descriptor + diff_id + bytes) from an assembled image, pairing each layer descriptor with its rootfs.diff_ids entry.

Types

layer()

@type layer() :: %{
  descriptor: Stevedore.Descriptor.t(),
  diff_id: Stevedore.Digest.t(),
  blob: binary()
}

A layer being assembled: its (compressed) descriptor, uncompressed diff_id, and bytes.

t()

@type t() :: %Stevedore.Image{
  blobs: %{optional(String.t()) => binary()},
  config: Stevedore.Config.t(),
  layers: [Stevedore.Descriptor.t()],
  manifest: Stevedore.Manifest.t(),
  referrers: [Stevedore.Descriptor.t()] | nil,
  tag: String.t() | nil
}

Functions

annotations(image)

@spec annotations(t()) :: map() | nil

The manifest's annotations, if any.

assemble(config_json, layers, opts \\ [])

@spec assemble(map(), [layer()], keyword()) :: {:ok, t()} | {:error, term()}

Assembles an image from a full image-config JSON map and a list of layer/0.

Recomputes rootfs.diff_ids from the layers, ensures the history length matches, and builds the config and manifest blobs with correct sizes and digests. opts: :format (:oci/:docker), :annotations (manifest annotations), :tag.

blob(image, digest)

@spec blob(t(), Stevedore.Digest.t()) :: {:ok, binary()} | {:error, :not_found}

Fetches a blob's bytes by digest.

digest(image)

@spec digest(t()) :: Stevedore.Digest.t()

The image's manifest digest.

format(image)

@spec format(t()) :: :oci | :docker

The image's manifest format (:oci or :docker), inferred from its media type.

layers(image)

@spec layers(t()) :: [layer()]

Reconstructs the layer/0 records (descriptor + diff_id + bytes) from an assembled image, pairing each layer descriptor with its rootfs.diff_ids entry.