From feb03428b60cb6ed541016772fd7cd91daa1f010 Mon Sep 17 00:00:00 2001 From: Michael Waskom Date: Fri, 2 Aug 2024 13:50:54 -0400 Subject: [PATCH] Add a --volume flag to `modal shell` (#2067) --- modal/cli/run.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modal/cli/run.py b/modal/cli/run.py index 032de2e36..a6dbd3c25 100644 --- a/modal/cli/run.py +++ b/modal/cli/run.py @@ -26,6 +26,7 @@ from ..image import Image from ..runner import deploy_app, interactive_shell, run_app from ..serving import serve_app +from ..volume import Volume from .import_refs import import_app, import_function from .utils import ENV_OPTION, ENV_OPTION_HELP, stream_app_logs @@ -332,7 +333,10 @@ def serve( def shell( func_ref: Optional[str] = typer.Argument( default=None, - help="Path to a Python file with an App or Modal function whose container to run.", + help=( + "Path to a Python file with an App or Modal function with container parameters." + " Can also include a function specifier, like `module.py::func`, when the file defines multiple functions." + ), metavar="FUNC_REF", ), cmd: str = typer.Option(default="/bin/bash", help="Command to run inside the Modal image."), @@ -341,6 +345,13 @@ def shell( default=None, help="Container image tag for inside the shell (if not using FUNC_REF)." ), add_python: Optional[str] = typer.Option(default=None, help="Add Python to the image (if not using FUNC_REF)."), + volume: Optional[typing.List[str]] = typer.Option( + default=None, + help=( + "Name of a `modal.Volume` to mount inside the shell at `/mnt/{name}` (if not using FUNC_REF)." + " Can be used multiple times." + ), + ), cpu: Optional[int] = typer.Option( default=None, help="Number of CPUs to allocate to the shell (if not using FUNC_REF)." ), @@ -419,6 +430,7 @@ def shell( ) else: modal_image = Image.from_registry(image, add_python=add_python) if image else None + volumes = {} if volume is None else {f"/mnt/{vol}": Volume.from_name(vol) for vol in volume} start_shell = partial( interactive_shell, image=modal_image, @@ -426,6 +438,7 @@ def shell( memory=memory, gpu=gpu, cloud=cloud, + volumes=volumes, region=region.split(",") if region else [], )