Skip to content

feat: share host conda package cache with Docker containers#1080

Closed
nh13 wants to merge 8 commits intobioconda:masterfrom
nh13:share-host-conda-cache
Closed

feat: share host conda package cache with Docker containers#1080
nh13 wants to merge 8 commits intobioconda:masterfrom
nh13:share-host-conda-cache

Conversation

@nh13
Copy link
Copy Markdown
Member

@nh13 nh13 commented Feb 20, 2026

Summary

  • Mounts the host's conda package cache (pkgs_dirs[0]) read-only inside Docker build containers
  • Container's build script symlinks cached repodata and packages into the container's writable pkgs dir, allowing reuse without modifying pkgs_dirs
  • Adds _get_host_pkgs_dir() helper that tries conda.base.context first, falls back to path heuristic
  • Adds --no-share-host-cache CLI flag for opt-out

Savings

30-90s per Docker build by avoiding redundant repodata downloads (~100+ MB from conda-forge).

Risks

  • :ro mount prevents any corruption of host cache
  • No lock file contention since :ro means no locks are created
  • Stale repodata: matches what the host would use (same TTL-based invalidation)
  • Fallback: if host pkgs dir is not found, silently skips (no change in behavior)

Test plan

  • Run existing test suite: pytest test/
  • Integration test: bioconda-utils build recipes/ config.yml --docker on a sample recipe
  • Verify Docker container can access cached repodata
  • Test with --no-share-host-cache to confirm opt-out works

Mount the host's conda package cache directory read-only inside the
Docker build container. This allows the container to reuse cached
repodata and packages instead of re-downloading them from scratch.

Changes:
- Add _get_host_pkgs_dir() helper to locate the host's pkgs directory
- Add share_host_cache parameter to RecipeBuilder (default: True)
- Mount host pkgs dir as read-only volume in build_recipe()
- Update BUILD_SCRIPT_TEMPLATE to prepend the mounted cache to pkgs_dirs
- Add --no-share-host-cache CLI flag for opt-out

The :ro mount prevents any corruption of the host cache. Conda handles
read-only pkgs_dirs gracefully. If the host pkgs dir is not found, the
feature is silently skipped with no change in behavior.

Saves 30-90s per Docker build by avoiding redundant repodata downloads.
@nh13 nh13 force-pushed the share-host-conda-cache branch from 4305e9e to 900c3f3 Compare February 20, 2026 00:32
nh13 added 3 commits February 19, 2026 18:24
Use conda config --system flag to avoid interference with CONDARC env var
inside the container, and ensure writable pkgs dir comes first.
…kgs_dirs

The CONDARC env var may reference a host path not mounted into the
container. Create the file if missing so conda config writes and later
pkgs_dirs resolution work correctly.
conda-build's clean_pkg_cache() calls PackageCacheData.first_writable()
on each pkgs_dir individually without catching NoWritablePkgsDirError,
so read-only entries in pkgs_dirs are not supported. Instead, symlink
the repodata cache files and package archives from the read-only host
mount into the container's writable /opt/conda/pkgs directory.
Copy link
Copy Markdown
Contributor

@johanneskoester johanneskoester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nh13
Copy link
Copy Markdown
Member Author

nh13 commented Feb 24, 2026

Thank-you for reviewing! I don't have permission to merge (squash), any chance you can do that?

@nh13
Copy link
Copy Markdown
Member Author

nh13 commented Mar 2, 2026

bump, I don't have merge permissions

@epruesse
Copy link
Copy Markdown
Member

epruesse commented Mar 2, 2026

Did you / do you still want to complete the test plan?

@nh13
Copy link
Copy Markdown
Member Author

nh13 commented Mar 25, 2026

Closing this: I misunderstood, CI runners start fresh each run so there's no warm host cache to share

@nh13 nh13 closed this Mar 25, 2026
@nh13 nh13 deleted the share-host-conda-cache branch March 25, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants