Skip to content

Commit 3ee64a6

Browse files
committed
Add persistent cache volume support via CACHE_VOLUME_NAME
Mount a Modal Volume at /cache when CACHE_VOLUME_NAME is set. Enables dependency caching across job runs for faster builds.
1 parent 3b1f2e4 commit 3ee64a6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

DEPLOY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ Every time a job is queued, Modal will spawn an ephemeral sandbox that runs the
113113
| `MAX_CONCURRENT_PER_REPO` | No | (unlimited) | Max concurrent sandboxes per repo |
114114
| `ALLOWED_CIDRS` | No | (allow all) | Comma-separated CIDR ranges for outbound |
115115
| `BLOCK_NETWORK` | No | `false` | Fully isolate sandbox network |
116+
| `CACHE_VOLUME_NAME` | No | - | Modal Volume name for persistent `/cache` mount |
116117
| `GITHUB_ENTERPRISE_DOMAIN` | No | - | Custom domain for GitHub Enterprise |

app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def format(self, record: logging.LogRecord) -> str:
105105
ALLOWED_CIDRS = [c.strip() for c in ALLOWED_CIDRS_STR.split(",") if c.strip()] if ALLOWED_CIDRS_STR else None
106106
BLOCK_NETWORK = os.environ.get("BLOCK_NETWORK", "").lower() in ("true", "1", "yes")
107107

108+
CACHE_VOLUME_NAME = os.environ.get("CACHE_VOLUME_NAME", "") or None
109+
108110

109111
def _get_gpu_config(gpu_key: str):
110112
attr_name = GPU_LABEL_TO_ATTR.get(gpu_key)
@@ -657,6 +659,12 @@ async def github_webhook(request: Request):
657659
)
658660
raise HTTPException(status_code=500, detail="Internal server error")
659661

662+
cache_volume = None
663+
sandbox_volumes = {}
664+
if CACHE_VOLUME_NAME:
665+
cache_volume = modal.Volume.from_name(CACHE_VOLUME_NAME, create_if_missing=True)
666+
sandbox_volumes["/cache"] = cache_volume
667+
660668
logger.info("Spawning sandbox", extra={"job_id": job_id, "repo": repo_full_name, "gpu": gpu_config is not None})
661669

662670
cmd = (
@@ -679,6 +687,7 @@ async def github_webhook(request: Request):
679687
gpu=gpu_config,
680688
cidr_allowlist=ALLOWED_CIDRS,
681689
block_network=BLOCK_NETWORK,
690+
volumes=sandbox_volumes,
682691
experimental_options={"enable_docker": True},
683692
)
684693

0 commit comments

Comments
 (0)