Skip to content

Commit 9682c0c

Browse files
committed
Add custom sandbox env vars and Makefile
SANDBOX_EXTRA_ENV accepts a JSON string of extra env vars merged into every sandbox. Makefile adds deploy/serve/test/lint/logs targets for local development.
1 parent b883628 commit 9682c0c

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: deploy serve test lint logs
2+
3+
deploy:
4+
modal deploy app.py
5+
6+
serve:
7+
modal serve app.py
8+
9+
test:
10+
pytest tests/ -v
11+
12+
lint:
13+
ruff check app.py
14+
15+
logs:
16+
modal app logs modal-github-runner

app.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def format(self, record: logging.LogRecord) -> str:
109109

110110
MODAL_REGION = os.environ.get("MODAL_REGION", "") or None
111111

112+
SANDBOX_EXTRA_ENV: dict = {}
113+
_extra_env_raw = os.environ.get("SANDBOX_EXTRA_ENV", "")
114+
if _extra_env_raw:
115+
try:
116+
parsed = json.loads(_extra_env_raw)
117+
if isinstance(parsed, dict):
118+
SANDBOX_EXTRA_ENV = {str(k): str(v) for k, v in parsed.items()}
119+
else:
120+
logger.warning("SANDBOX_EXTRA_ENV is not a JSON object, ignoring")
121+
except json.JSONDecodeError:
122+
logger.warning("SANDBOX_EXTRA_ENV is not valid JSON, ignoring")
123+
112124

113125
def _get_gpu_config(gpu_key: str):
114126
attr_name = GPU_LABEL_TO_ATTR.get(gpu_key)
@@ -720,7 +732,7 @@ async def github_webhook(request: Request):
720732
image=runner_image,
721733
app=app,
722734
timeout=TIMEOUT_SECONDS,
723-
env={"GHA_JIT_CONFIG": jit_config},
735+
env={"GHA_JIT_CONFIG": jit_config, **SANDBOX_EXTRA_ENV},
724736
gpu=gpu_config,
725737
cidr_allowlist=ALLOWED_CIDRS,
726738
block_network=BLOCK_NETWORK,

0 commit comments

Comments
 (0)