Skip to content

Commit 119488b

Browse files
committed
test docker machine mounts
1 parent da2c4a6 commit 119488b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cwltool/docker.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@
2828

2929
found_images = set() # type: Set[Text]
3030
found_images_lock = threading.Lock()
31+
__docker_machine_mounts = None # type: List[Text]
32+
__docker_machine_mounts_lock = threading.Lock()
33+
34+
def _get_docker_machine_mounts(): # type: () -> List[Text]
35+
global __docker_machine_mounts
36+
if __docker_machine_mounts is None:
37+
with __docker_machine_mounts_lock:
38+
if 'DOCKER_MACHINE_NAME' not in os.environ:
39+
__docker_machine_mounts = []
40+
else:
41+
__docker_machine_mounts = [u'/' + line.split(None, 1)[0]
42+
for line in subprocess.check_output(
43+
['docker-machine', 'ssh',
44+
os.environ['DOCKER_MACHINE_NAME'],
45+
'mount', '-t', 'vboxsf'],
46+
universal_newlines=True).splitlines()]
47+
return __docker_machine_mounts
48+
49+
def _check_docker_machine_path(path): # type: (Text) -> None
50+
mounts = _get_docker_machine_mounts()
51+
if mounts:
52+
found = False
53+
for mount in mounts:
54+
if path.startswith(mount):
55+
found = True
56+
break
57+
if not found:
58+
raise WorkflowException(
59+
"Input path {path} is not in the list of host paths mounted "
60+
"into the Docker virtual machine named {name}. Already mounted "
61+
"paths: {mounts}.\n"
62+
"See https://docs.docker.com/toolbox/toolbox_install_windows/#optional-add-shared-directories"
63+
" for instructions on how to add this path to your VM.".format(path=path,
64+
name=os.environ["DOCKER_MACHINE_NAME"], mounts=mounts))
65+
3166

3267
class DockerCommandLineJob(ContainerCommandLineJob):
3368

@@ -162,6 +197,8 @@ def add_volumes(self, pathmapper, runtime, secret_store=None):
162197
host_outdir_tgt = None
163198
if vol.type in ("File", "Directory"):
164199
if not vol.resolved.startswith("_:"):
200+
_check_docker_machine_path(docker_windows_path_adjust(
201+
vol.resolved))
165202
runtime.append(u"--volume=%s:%s:ro" % (
166203
docker_windows_path_adjust(vol.resolved),
167204
docker_windows_path_adjust(vol.target)))

0 commit comments

Comments
 (0)