Skip to content

Commit a3d565b

Browse files
authored
Merge pull request #1251 from mccalluc/mccalluc/change-docker-volume-to-mount-1250
Change from --volume to --mount
2 parents 4fd5ca5 + d682995 commit a3d565b

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Generated during tests
2+
pytestdebug.log
3+
tmp/
4+
15
# Python temps
26
__pycache__/
37
*.py[cod]

cwltool/docker.py

Lines changed: 16 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,11 +223,22 @@ 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
)
239+
# Unlike "--volume", "--mount" will fail if the volume doesn't already exist.
240+
if not os.path.exists(source):
241+
os.mkdir(source)
230242

231243
def add_file_or_directory_volume(
232244
self, runtime: List[str], volume: MapperEnt, host_outdir_tgt: Optional[str]

tests/test_docker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def test_docker_workflow(tmpdir):
2222
]
2323
)
2424
assert "completed success" in stderr
25+
assert (tmpdir / 'response.txt').read_text('utf-8') == 'hello'
2526
assert result_code == 0
2627

2728

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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(mocker):
10+
mocker.patch('os.mkdir')
11+
runtime = ['runtime']
12+
characters = ':,"\''
13+
DockerCommandLineJob.append_volume(
14+
runtime,
15+
'/source' + characters,
16+
'/target' + characters
17+
)
18+
assert runtime == [
19+
'runtime',
20+
'--mount=type=bind,'
21+
'"source=/source:,""\'",'
22+
'"target=/target:,""\'",'
23+
'readonly'
24+
]
25+
26+
def test_docker_append_volume_read_write(mocker):
27+
mocker.patch('os.mkdir')
28+
runtime = ['runtime']
29+
characters = ':,"\''
30+
DockerCommandLineJob.append_volume(
31+
runtime,
32+
'/source' + characters,
33+
'/target' + characters,
34+
True
35+
)
36+
assert runtime == [
37+
'runtime',
38+
'--mount=type=bind,'
39+
'"source=/source:,""\'",'
40+
'"target=/target:,""\'"'
41+
]

0 commit comments

Comments
 (0)