@@ -66,23 +66,30 @@ class LinuxContainerConfig(DeveloperEnvironmentConfig):
6666 ] = None
6767 # This parameter stores the raw volume specifications as provided by the user.
6868 # Use the `extra_mounts` property to get the list of extra mounts as Mount objects.
69- extra_mount_specs : Annotated [
69+ extra_volume_specs : Annotated [
7070 list [str ],
7171 msgspec .Meta (
7272 extra = {
7373 "params" : ["-v" , "--volume" ],
7474 "help" : (
7575 """\
76- Additional directories or volumes to be mounted into the dev env. This option may be supplied multiple
76+ Additional host directories to be mounted into the dev env. This option may be supplied multiple
7777times, and has the same syntax as the `-v/--volume` flag of `docker run`. Examples:
7878
7979- `./some-repo:/root/repos/some-repo` (bind mount from relative path on host to container)
8080- `/tmp/some-location:/location:ro` (bind mount from absolute path on host to container with read-only flag)
81- - `~/projects:/root/projects:ro,z` (bind mount from absolute path on host to container with read-only flag and `z` volume option)
82- - `some-volume:/location` (volume mount from named volume to container)
81+ - `~/projects:/root/projects:ro` (bind mount from absolute path on host to container with read-only flag)
82+
83+
84+ > **WARNING:**
85+ > This option only supports a subset of the syntax for the `-v/--volume` flag of `docker run`, and is provided only as a convenience.
86+ >
87+ > In particular, only bind mounts are supported, not volume mounts. Additionally, only the `ro` flag is supported.
88+ >
89+ > To mount a volume or use other options, use the more explicit `-m/--mount` option instead.
8390"""
8491 ),
85- "callback" : __validate_extra_mount_specs ,
92+ "callback" : __validate_extra_volume_specs ,
8693 }
8794 ),
8895 ] = msgspec .field (default_factory = list )
@@ -403,7 +410,7 @@ def extra_mounts(self) -> list[Mount]:
403410 from dda .utils .container .model import Mount
404411
405412 mounts = []
406- for spec in self .config .extra_mount_specs :
413+ for spec in self .config .extra_volume_specs :
407414 src , dst , * extra = spec .split (":" , 2 )
408415 flags = extra [0 ].split ("," ) if extra else []
409416 read_only = "ro" in flags
@@ -450,7 +457,7 @@ def repo_path(self, repo: str | None) -> str:
450457 return f"{ self .home_dir } /repos/{ repo } "
451458
452459
453- def __validate_extra_mount_specs (_ctx : Context , _param : Option , value : list [str ]) -> list [str ]:
460+ def __validate_extra_volume_specs (_ctx : Context , _param : Option , value : list [str ]) -> list [str ]:
454461 from click import BadParameter
455462
456463 from dda .utils .fs import Path
@@ -459,13 +466,16 @@ def __validate_extra_mount_specs(_ctx: Context, _param: Option, value: list[str]
459466 return value
460467
461468 for spec in value :
462- src , dst , * _ = spec .split (":" , 2 )
463- mount_type : Literal ["bind" , "volume" ] = "bind" if src .startswith (("/" , "." )) else "volume"
464- if mount_type == "bind" and not Path (src ).exists ():
465- msg = f"Invalid mount source: { spec } . Source must be an existing path on the host."
469+ src , dst , * extra = spec .split (":" , 2 )
470+ flag = extra [0 ] if extra else None
471+ if flag not in {None , "ro" , "rw" }:
472+ msg = f"Invalid volume flag: { flag } . Only the `ro` flag is supported."
473+ raise BadParameter (msg )
474+ if not Path (src ).exists ():
475+ # NOTE: We have here a slight discrepancy with the behavior of `docker run -v`, which will create the directory if it doesn't exist.
476+ msg = f"Invalid volume source: { src } . Source must be an existing path on the host."
466477 raise BadParameter (msg )
467-
468478 if not Path (dst ).is_absolute ():
469- msg = f"Invalid mount destination: { spec } . Destination must be an absolute path."
479+ msg = f"Invalid volume destination: { dst } . Destination must be an absolute path."
470480 raise BadParameter (msg )
471481 return value
0 commit comments