Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/deps/dockerfiles.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 import logging | |
2 import os | |
3 | |
4 from galaxy.tool_util.deps import docker_util | |
5 from galaxy.tool_util.deps.container_classes import docker_cache_path | |
6 from galaxy.tool_util.deps.requirements import parse_requirements_from_xml | |
7 from galaxy.tool_util.loader_directory import load_tool_elements_from_path | |
8 from galaxy.util import commands | |
9 | |
10 log = logging.getLogger(__name__) | |
11 | |
12 | |
13 def docker_host_args(**kwds): | |
14 return dict( | |
15 docker_cmd=kwds["docker_cmd"], | |
16 sudo=kwds["docker_sudo"], | |
17 sudo_cmd=kwds["docker_sudo_cmd"], | |
18 host=kwds["docker_host"] | |
19 ) | |
20 | |
21 | |
22 def dockerfile_build(path, dockerfile=None, error=log.error, **kwds): | |
23 expected_container_names = set() | |
24 tool_directories = set() | |
25 for (tool_path, tool_xml) in load_tool_elements_from_path(path): | |
26 requirements, containers = parse_requirements_from_xml(tool_xml) | |
27 for container in containers: | |
28 if container.type == "docker": | |
29 expected_container_names.add(container.identifier) | |
30 tool_directories.add(os.path.dirname(tool_path)) | |
31 break | |
32 | |
33 if len(expected_container_names) == 0: | |
34 error("Could not find any docker identifiers to generate.") | |
35 | |
36 if len(expected_container_names) > 1: | |
37 error("Multiple different docker identifiers found for selected tools [%s]", expected_container_names) | |
38 | |
39 image_identifier = expected_container_names.pop() | |
40 | |
41 dockerfile = __find_dockerfile(dockerfile, tool_directories) | |
42 if dockerfile is not None: | |
43 docker_command_parts = docker_util.build_command( | |
44 image_identifier, | |
45 dockerfile, | |
46 **docker_host_args(**kwds) | |
47 ) | |
48 else: | |
49 docker_command_parts = docker_util.build_pull_command(image_identifier, **docker_host_args(**kwds)) | |
50 commands.execute(docker_command_parts) | |
51 | |
52 commands.execute(docker_command_parts) | |
53 docker_image_cache = kwds['docker_image_cache'] | |
54 if docker_image_cache: | |
55 destination = docker_cache_path(docker_image_cache, image_identifier) | |
56 save_image_command_parts = docker_util.build_save_image_command( | |
57 image_identifier, | |
58 destination, | |
59 **docker_host_args(**kwds) | |
60 ) | |
61 commands.execute(save_image_command_parts) | |
62 | |
63 | |
64 def __find_dockerfile(dockerfile, tool_directories): | |
65 if dockerfile is not None: | |
66 return dockerfile | |
67 search_directories = ["."] | |
68 if len(tool_directories) == 1: | |
69 tool_directory = tool_directories.pop() | |
70 search_directories.insert(0, tool_directory) | |
71 for directory in search_directories: | |
72 potential_dockerfile = os.path.join(directory, "Dockerfile") | |
73 if os.path.exists(potential_dockerfile): | |
74 return potential_dockerfile | |
75 return None |