Skip to content

Feature request: dedicated environment variable for cache mount location #6554

@rassie

Description

@rassie

Is your feature request related to a problem?

When using RUN --mount=type=cache, buildah stores cache mounts at $TMPDIR/buildah-cache-<uid>/. The only way to control this location is via TMPDIR or image_copy_tmp_dir in containers.conf.

Both settings affect all buildah temporary operations (SSH agent sockets, heredoc files, build contexts, downloaded URLs, container bundles), not just cache mounts.

In CI/CD environments this forces a choice:

  • Redirect all temp operations to persistent storage (wasteful, stores ephemeral data)
  • Keep default TMPDIR and lose cache mount persistence between jobs

Describe the solution you'd like

A dedicated environment variable (e.g. BUILDAH_CACHE_DIR) that controls only the location of --mount=type=cache mounts, independent of TMPDIR.

Priority order:

  1. BUILDAH_CACHE_DIR (new, cache-specific)
  2. TMPDIR (existing behavior)
  3. image_copy_tmp_dir from containers.conf
  4. /var/tmp (default)

Describe alternatives you've considered

  1. Setting TMPDIR globally in runner config - affects all applications in all CI jobs, not just buildah. Node.js, Python, Java, and other tools would write temp files to persistent storage, causing unnecessary I/O and storage bloat. Also risks breaking tools that expect TMPDIR to be ephemeral.
  2. Using image_copy_tmp_dir - still affects all buildah temp operations, not just cache mounts
  3. Per-job TMPDIR in CI - requires job authors to know infrastructure details and remember to set it

Additional context

Use case: GitLab CI with Kubernetes runner

  • Jobs run in ephemeral pods
  • Shared PVC at /buildah-cache for cache persistence
  • Want ephemeral temp files to stay on local/tmpfs storage

Proposed implementation in internal/volumes/volumes.go:

func CacheParent() string {
    if cacheDir, ok := os.LookupEnv("BUILDAH_CACHE_DIR"); ok {
        return filepath.Join(cacheDir, buildahCacheDir+"-"+strconv.Itoa(unshare.GetRootlessUID()))
    }
    return filepath.Join(tmpdir.GetTempDir(), buildahCacheDir+"-"+strconv.Itoa(unshare.GetRootlessUID()))
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions