sincecutoff.com
← all changes

mutate.Time and mutate.Canonical accept tarball.LayerOption

Introduced 2026-08-25 · score 0.93

HOW TO USE IT

When rebuilding an image and needing to preserve its layer compression or media type, pass the matching `tarball.LayerOption` values to `mutate.Time` or `mutate.Canonical`, then set the image and config media types with `mutate.MediaType` and `mutate.ConfigMediaType` as needed.

img, err := mutate.Time(img, t, tarball.WithCompression(compression.ZStd), tarball.WithMediaType(types.OCILayerZStd)) if err != nil { return err } img = mutate.MediaType(img, types.OCIManifestSchema1) img = mutate.ConfigMediaType(img, types. OCIConfigJSON)
img, err := mutate.Canonical(img, tarball.WithCompression(compression.ZStd), tarball.WithMediaType(types.OCILayerZStd)) if err != nil { return err } img = mutate.MediaType(img, types.OCIManifestSchema1) img = mutate.ConfigMediaType(img, types.OCIConfigJSON)

WHY THIS HELPS

When rebuilding an image while preserving its layer codec and media types, pass the required layer options and update the manifest and config media types.

BEFORE THIS CHANGE

Before this change, `mutate.Time` and `mutate.Canonical` accepted no layer options; rebuilt layers were dockerv2+gzip by default.

REQUIREMENTS AND LIMITATIONS

  • Version: v0.22.0
  • mutate.Time(img, t, opts...) (required): `img` is the image to mutate; `t` is the timestamp applied to image timestamps; `opts` are optional variadic `tarball.LayerOption` values. Layers default to dockerv2+gzip unless options say otherwise.
  • mutate.Canonical(img, opts...) (required): `img` is the image to canonicalize; `opts` are optional variadic `tarball.LayerOption` values.
  • tarball.WithCompression(comp): Overrides compression for uncompressed tarballs. For ZStd, use together with `WithMediaType(types.OCILayerZStd)`.
  • tarball.WithMediaType(mt): Overrides the layer media type. No mutual-exclusion rule documented.
  • mutate.MediaType(img, mt) (required): Sets the image media type.
  • mutate.ConfigMediaType(img, mt) (required): Sets the image config media type.
  • With no options passed, output is byte identical to before.
  • `Time` and `Canonical` can no longer be assigned to a `func(v1.Image) (v1.Image, error)` variable.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card