Skip to content

Commit

Permalink
Merge pull request #18998 from bernt-matthias/docker-volume-z
Browse files Browse the repository at this point in the history
Allow modes `z` and `Z` for docker volumes
  • Loading branch information
jdavcs authored Nov 12, 2024
2 parents 7f513fd + e09cba3 commit 784b5f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions lib/galaxy/tool_util/deps/container_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def parse_volume_str(rawstr: str) -> Tuple[str, str, str]:
('A', 'B', 'rw')
>>> Volume.parse_volume_str('A:ro')
('A', 'A', 'ro')
>>> Volume.parse_volume_str('A:z')
('A', 'A', 'z')
>>> Volume.parse_volume_str('A:Z')
('A', 'A', 'Z')
>>> Volume.parse_volume_str('A')
('A', 'A', 'rw')
>>> Volume.parse_volume_str(' ')
Expand All @@ -207,7 +211,9 @@ def parse_volume_str(rawstr: str) -> Tuple[str, str, str]:
target = volume_parts[1]
mode = volume_parts[2]
elif len(volume_parts) == 2:
if volume_parts[1] not in ("rw", "ro", "default_ro"):
# not really parsing/checking mode here, just figuring out if the 2nd component is target or mode
mode_parts = volume_parts[1].split(",")
if any(mode_part not in ("rw", "ro", "default_ro", "z", "Z") for mode_part in mode_parts):
source = volume_parts[0]
target = volume_parts[1]
mode = "rw"
Expand Down Expand Up @@ -400,6 +406,18 @@ def add_var(name, value):
return volumes_str


def _parse_volumes(volumes_raw: str, container_type: str) -> List[DockerVolume]:
"""
>>> volumes_raw = "$galaxy_root:ro,$tool_directory:ro,$job_directory:ro,$working_directory:z,$default_file_path:z"
>>> volumes = _parse_volumes(volumes_raw, "docker")
>>> [str(v) for v in volumes]
['"$galaxy_root:$galaxy_root:ro"', '"$tool_directory:$tool_directory:ro"', '"$job_directory:$job_directory:ro"', '"$working_directory:$working_directory:z"', '"$default_file_path:$default_file_path:z"']
"""
preprocessed_volumes_list = preprocess_volumes(volumes_raw, container_type)
# TODO: Remove redundant volumes...
return [DockerVolume.from_str(v) for v in preprocessed_volumes_list]


class DockerContainer(Container, HasDockerLikeVolumes):
container_type = DOCKER_CONTAINER_TYPE

Expand Down Expand Up @@ -439,9 +457,7 @@ def containerize_command(self, command: str) -> str:
raise Exception(f"Cannot containerize command [{working_directory}] without defined working directory.")

volumes_raw = self._expand_volume_str(self.destination_info.get("docker_volumes", "$defaults"))
preprocessed_volumes_list = preprocess_volumes(volumes_raw, self.container_type)
# TODO: Remove redundant volumes...
volumes = [DockerVolume.from_str(v) for v in preprocessed_volumes_list]
volumes = _parse_volumes(volumes_raw, self.container_type)
volumes_from = self.destination_info.get("docker_volumes_from", docker_util.DEFAULT_VOLUMES_FROM)

docker_host_props = self.docker_host_props
Expand Down Expand Up @@ -560,8 +576,7 @@ def containerize_command(self, command: str) -> str:
raise Exception(f"Cannot containerize command [{working_directory}] without defined working directory.")

volumes_raw = self._expand_volume_str(self.destination_info.get("singularity_volumes", "$defaults"))
preprocessed_volumes_list = preprocess_volumes(volumes_raw, self.container_type)
volumes = [DockerVolume.from_str(v) for v in preprocessed_volumes_list]
volumes = _parse_volumes(volumes_raw, self.container_type)

run_command = singularity_util.build_singularity_run_command(
command,
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/deps/container_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class ContainerVolume(metaclass=ABCMeta):
valid_modes = frozenset({"ro", "rw"})
valid_modes = frozenset({"ro", "rw", "z", "Z"})

def __init__(self, path: str, host_path: Optional[str] = None, mode: Optional[str] = None):
self.path = path
Expand Down Expand Up @@ -50,7 +50,7 @@ def from_str(cls, as_str: str) -> "DockerVolume":
kwds["path"] = kwds["host_path"]
elif len(parts) == 2:
# /host_path:mode is not (or is no longer?) valid Docker volume syntax
if parts[1] in DockerVolume.valid_modes:
if all(mode_part in DockerVolume.valid_modes for mode_part in parts[1].split(",")):
kwds["mode"] = parts[1]
kwds["path"] = kwds["host_path"]
else:
Expand Down

0 comments on commit 784b5f2

Please sign in to comment.