Skip to content

Support a global persistent-cache namespace via BUILDKIT_CACHE_MOUNT_NS #1127

Description

@cpuguy83

Summary

Dalec creates many persistent cache mounts (DNF/TDNF, apt, gomod proxy, Go build, sccache, bazel, user-defined caches:). Cache IDs are namespaced ad-hoc per distro/platform/language, but there's no way to add a global prefix to all of them.

BuildKit's Dockerfile frontend supports BUILDKIT_CACHE_MOUNT_NS (a build-arg) which prefixes RUN --mount=type=cache IDs. It's purely a frontend convention — the solver has no notion of it; the frontend just concatenates the namespace onto each cache mount ID. We should adopt the same convention for a consistent, cross-frontend way to namespace persistent caches.

Motivation

A global cache namespace lets users isolate caches without editing every spec or distro config:

  • Multi-tenant / multi-project shared builders where caches must not collide or leak between projects.
  • CI lanes that want independent caches (e.g. per-branch or per-pipeline) without disabling caching.
  • Reproducing a build with a clean cache by changing the namespace, without nuking the shared cache.

Matching the existing BUILDKIT_CACHE_MOUNT_NS arg keeps the knob familiar to BuildKit/Dockerfile users.

Proposed behavior

When --build-arg BUILDKIT_CACHE_MOUNT_NS=<ns> is set, prefix the ID of every persistent cache mount with <ns>/ (or similar), layered on top of the existing distro/platform/language namespacing. Empty/unset preserves today's behavior.

Covers, at minimum:

  • RPM package caches — targets/linux/rpm/distro/distro.go, dnf_install.go
  • apt caches — helpers.go (WithMountedAptCache)
  • gomod proxy / Go build / sccache / bazel and user caches:cache.go, generator_gomod.go

Implementation notes

  • We already read build-arg: opts via client.BuildOpts().Opts (e.g. DALEC_DISABLE_DIFF_MERGE in frontend/request.go, frontend/gateway.go), so reading build-arg:BUILDKIT_CACHE_MOUNT_NS is straightforward.
  • Main work is threading the namespace down to the llb.AsPersistentCacheDir(...) call sites. The existing auto-namespacing helpers are the natural place to apply the prefix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions