Stevedore.Mutate (Stevedore v0.1.0)

Copy Markdown View Source

Rewrite an assembled Stevedore.Image — config, annotations, tag, base, or layer set — without re-pulling layers where possible. Every mutation recomputes the dependent digests through Stevedore.Image.assemble/3; bytes that don't change keep their digests.

Spec: crane mutate/rebase/flatten semantics (https://github.com/google/go-containerregistry/tree/main/cmd/crane) and OCI image-spec config.md/layer.md.

Summary

Functions

Merges annotations into the manifest's annotations. Config and layers are untouched.

Rewrites the runtime config. changes is a map of :entrypoint/:cmd/:env/:user/ :working_dir/:labels (labels are merged, the rest replaced) or a (Config.t -> Config.t) function. Layers are untouched.

Flattens all layers into a single layer, applying whiteouts (.wh.<name> deletions and .wh..wh..opq opaque dirs) so the result is the effective filesystem. The runtime config is preserved.

Rebases image from old_base onto new_base: the bottom layers matching old_base are swapped for new_base's layers, keeping the application layers on top. Fails with :base_mismatch if image doesn't actually start with old_base's layers.

Sets the tag the image will be written under by a subsequent copy.

Functions

annotations(image, annotations)

@spec annotations(Stevedore.Image.t(), map()) :: Stevedore.Image.t()

Merges annotations into the manifest's annotations. Config and layers are untouched.

config(image, changes)

Rewrites the runtime config. changes is a map of :entrypoint/:cmd/:env/:user/ :working_dir/:labels (labels are merged, the rest replaced) or a (Config.t -> Config.t) function. Layers are untouched.

flatten(image, opts \\ [])

@spec flatten(
  Stevedore.Image.t(),
  keyword()
) :: {:ok, Stevedore.Image.t()} | {:error, term()}

Flattens all layers into a single layer, applying whiteouts (.wh.<name> deletions and .wh..wh..opq opaque dirs) so the result is the effective filesystem. The runtime config is preserved.

rebase(image, old_base, new_base)

@spec rebase(Stevedore.Image.t(), Stevedore.Image.t(), Stevedore.Image.t()) ::
  {:ok, Stevedore.Image.t()} | {:error, :base_mismatch}

Rebases image from old_base onto new_base: the bottom layers matching old_base are swapped for new_base's layers, keeping the application layers on top. Fails with :base_mismatch if image doesn't actually start with old_base's layers.

retag(image, tag)

Sets the tag the image will be written under by a subsequent copy.