11
11
12
12
import datetime
13
13
import requests
14
- from typing import (Dict , List , Text , Any , MutableMapping )
14
+ from typing import (Dict , List , Text , Any , MutableMapping , Set )
15
+ import threading
15
16
16
17
from .docker_id import docker_vm_id
17
18
from .errors import WorkflowException
22
23
23
24
_logger = logging .getLogger ("cwltool" )
24
25
26
+ found_images = set () # type: Set[Text]
27
+ found_images_lock = threading .Lock ()
25
28
26
29
class DockerCommandLineJob (ContainerCommandLineJob ):
27
30
28
31
@staticmethod
29
- def get_image (dockerRequirement , pull_image , dry_run = False ):
30
- # type: (Dict[Text, Text], bool, bool) -> bool
32
+ def get_image (dockerRequirement , pull_image , dry_run = False , force_pull = False ):
33
+ # type: (Dict[Text, Text], bool, bool, bool ) -> bool
31
34
found = False
32
35
33
36
if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement :
34
37
dockerRequirement ["dockerImageId" ] = dockerRequirement ["dockerPull" ]
35
38
39
+ with found_images_lock :
40
+ if dockerRequirement ["dockerImageId" ] in found_images :
41
+ return True
42
+
36
43
for ln in subprocess .check_output (
37
44
["docker" , "images" , "--no-trunc" , "--all" ]).decode ('utf-8' ).splitlines ():
38
45
try :
@@ -58,7 +65,7 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
58
65
except ValueError :
59
66
pass
60
67
61
- if not found and pull_image :
68
+ if ( force_pull or not found ) and pull_image :
62
69
cmd = [] # type: List[Text]
63
70
if "dockerPull" in dockerRequirement :
64
71
cmd = ["docker" , "pull" , str (dockerRequirement ["dockerPull" ])]
@@ -106,10 +113,14 @@ def get_image(dockerRequirement, pull_image, dry_run=False):
106
113
subprocess .check_call (cmd , stdout = sys .stderr )
107
114
found = True
108
115
116
+ if found :
117
+ with found_images_lock :
118
+ found_images .add (dockerRequirement ["dockerImageId" ])
119
+
109
120
return found
110
121
111
- def get_from_requirements (self , r , req , pull_image , dry_run = False ):
112
- # type: (Dict[Text, Text], bool, bool, bool) -> Text
122
+ def get_from_requirements (self , r , req , pull_image , dry_run = False , force_pull = False ):
123
+ # type: (Dict[Text, Text], bool, bool, bool, bool ) -> Text
113
124
if r :
114
125
errmsg = None
115
126
try :
@@ -125,7 +136,7 @@ def get_from_requirements(self, r, req, pull_image, dry_run=False):
125
136
else :
126
137
return None
127
138
128
- if self .get_image (r , pull_image , dry_run ):
139
+ if self .get_image (r , pull_image , dry_run , force_pull = force_pull ):
129
140
return r ["dockerImageId" ]
130
141
else :
131
142
if req :
0 commit comments