Skip to main content

merge_default_cache_mounts

Function merge_default_cache_mounts 

Source
pub fn merge_default_cache_mounts(df: &mut Dockerfile, options: &BuildOptions)
Expand description

Merge the build’s default cache mounts into every RUN instruction of a Dockerfile IR, in place.

For each RUN instruction, every RunMount::Cache entry in options.default_cache_mounts is appended to run.mounts unless a cache mount with the same target is already present (step-level mounts win). Non-cache entries in default_cache_mounts are ignored (the field only ever carries cache mounts, but we filter defensively).

This lifts the auto-cache-mount injection that the buildah CLI backend used to do inline per-RUN so it now materializes as real IR before rendering — making the rendered Dockerfile carry the --mount=type=cache flags identically for any backend that renders the IR to text.

A no-op when options.default_cache_mounts is empty (the common case).