ocibuild_cache (ocibuild v0.10.4)

View Source

Layer caching for OCI image builds.

Caches downloaded base image layers locally to avoid re-downloading on every build. Designed for CI/CD workflows where caching the _build/ocibuild_cache directory provides significant build time improvements.

Cache location resolution (in order):

  1. OCIBUILD_CACHE_DIR environment variable (explicit override)
  2. Project root detection → <project>/_build/ocibuild_cache/
  3. Fall back to ./_build/ocibuild_cache/ (current directory)

Project root is detected by walking up the directory tree looking for rebar.config, mix.exs, or gleam.toml.

CI Integration Example:

# GitHub Actions
- uses: actions/cache@v4
  with:
    path: _build/ocibuild_cache
    key: ocibuild-${{ runner.os }}-${{ hashFiles('rebar.lock') }}

# GitLab CI
cache:
  paths:
    - _build/ocibuild_cache/

Summary

Functions

Get the cache directory path.

Clear the entire cache.

Get a cached blob by digest.

Store a blob in the cache.

Functions

cache_dir()

-spec cache_dir() -> file:filename().

Get the cache directory path.

Resolution order:

  1. OCIBUILD_CACHE_DIR environment variable
  2. Project root + _build/ocibuild_cache/
  3. ./_build/ocibuild_cache/ (current directory fallback)

clear()

-spec clear() -> ok | {error, term()}.

Clear the entire cache.

Removes all cached blobs. Use with caution as this will force re-download of all layers on the next build.

get(Digest)

-spec get(binary()) -> {ok, binary()} | {error, not_found | corrupted | {invalid_digest, binary()}}.

Get a cached blob by digest.

Returns {ok, Data} if the blob is found and its digest matches. Returns {error, not_found} if the blob is not in the cache. Returns {error, corrupted} if the cached blob doesn't match its digest. Returns {error, {invalid_digest, Digest}} if the digest format is invalid.

put(Digest, Data)

-spec put(binary(), binary()) -> ok | {error, term()}.

Store a blob in the cache.

The blob is stored under its digest, so it can be retrieved later with get/1. The digest is computed from the data, not provided as a parameter, to ensure that only valid data is cached.

Returns {error, {invalid_digest, Digest}} if the digest format is invalid.