Skip to content

Commit 3fe75db

Browse files
committed
Change from --volume to --mount
1 parent 4fd5ca5 commit 3fe75db

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

cwltool/docker.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Enables Docker software containers via the {dx-,u,}docker runtimes."""
22

33
import datetime
4+
import csv
45
import os
56
import re
67
import shutil
78
import sys
89
import tempfile
910
import threading
1011
from distutils import spawn
11-
from io import open # pylint: disable=redefined-builtin
12+
from io import open, StringIO # pylint: disable=redefined-builtin
1213
from typing import Dict, List, MutableMapping, Optional, Set, Tuple
1314

1415
import requests
@@ -222,10 +223,18 @@ def get_from_requirements(
222223
def append_volume(runtime, source, target, writable=False):
223224
# type: (List[str], str, str, bool) -> None
224225
"""Add binding arguments to the runtime list."""
226+
options = [
227+
'type=bind',
228+
'source=' + source,
229+
'target=' + target,
230+
]
231+
if not writable:
232+
options.append('readonly')
233+
output = StringIO()
234+
csv.writer(output).writerow(options)
235+
mount_arg = output.getvalue().strip()
225236
runtime.append(
226-
"--volume={}:{}:{}".format(
227-
docker_windows_path_adjust(source), target, "rw" if writable else "ro"
228-
)
237+
"--mount={}".format(mount_arg)
229238
)
230239

231240
def add_file_or_directory_volume(
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
from cwltool.docker import DockerCommandLineJob
4+
from cwltool.main import main
5+
6+
from .util import needs_docker
7+
8+
9+
def test_docker_append_volume_read_only():
10+
runtime = ['runtime']
11+
characters = ':,"\''
12+
DockerCommandLineJob.append_volume(
13+
runtime,
14+
'/source' + characters,
15+
'/target' + characters
16+
)
17+
assert runtime == [
18+
'runtime',
19+
'--mount=type=bind,'
20+
'"source=/source:,""\'",'
21+
'"target=/target:,""\'",'
22+
'readonly'
23+
]
24+
25+
def test_docker_append_volume_read_write():
26+
runtime = ['runtime']
27+
characters = ':,"\''
28+
DockerCommandLineJob.append_volume(
29+
runtime,
30+
'/source' + characters,
31+
'/target' + characters,
32+
True
33+
)
34+
assert runtime == [
35+
'runtime',
36+
'--mount=type=bind,'
37+
'"source=/source:,""\'",'
38+
'"target=/target:,""\'"'
39+
]

0 commit comments

Comments
 (0)