Skip to content

Commit 12e3973

Browse files
committed
Add multi-region support via MODAL_REGION env var
Pass region to modal.Sandbox.create() when set. Supports us-east-1, us-west-2, eu-west-1, ap-southeast-1.
1 parent 7d8cb13 commit 12e3973

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

app.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def format(self, record: logging.LogRecord) -> str:
107107

108108
CACHE_VOLUME_NAME = os.environ.get("CACHE_VOLUME_NAME", "") or None
109109

110+
MODAL_REGION = os.environ.get("MODAL_REGION", "") or None
111+
110112

111113
def _get_gpu_config(gpu_key: str):
112114
attr_name = GPU_LABEL_TO_ATTR.get(gpu_key)
@@ -676,10 +678,7 @@ async def github_webhook(request: Request):
676678
" && exec ./run.sh --jitconfig $GHA_JIT_CONFIG"
677679
)
678680

679-
sandbox = modal.Sandbox.create(
680-
"bash",
681-
"-c",
682-
cmd,
681+
sandbox_kwargs = dict(
683682
image=runner_image,
684683
app=app,
685684
timeout=TIMEOUT_SECONDS,
@@ -690,6 +689,15 @@ async def github_webhook(request: Request):
690689
volumes=sandbox_volumes,
691690
experimental_options={"enable_docker": True},
692691
)
692+
if MODAL_REGION:
693+
sandbox_kwargs["region"] = MODAL_REGION
694+
695+
sandbox = modal.Sandbox.create(
696+
"bash",
697+
"-c",
698+
cmd,
699+
**sandbox_kwargs,
700+
)
693701

694702
sandbox.set_tags({"job_id": str(job_id)})
695703

0 commit comments

Comments
 (0)