1
1
import datetime
2
+ import json
2
3
import os
3
4
import shutil
4
5
import socket
33
34
from girder_worker_utils import _walk_obj
34
35
35
36
36
- BLACKLISTED_DOCKER_RUN_ARGS = ['tty' , 'detach' ]
37
+ BLACKLISTED_DOCKER_RUN_ARGS = ['tty' , 'detach' , 'volumes' ]
37
38
38
39
39
40
def _pull_image (image ):
@@ -364,6 +365,28 @@ def _cleanup_temp_volumes(self, temp_volumes, default_temp_volume):
364
365
shutil .rmtree (v .host_path )
365
366
366
367
368
+ def _add_environment_kargs (run_kwargs ):
369
+ envkey = 'GIRDER_WORKER_DOCKER_RUN_OPTIONS'
370
+ if envkey not in os .environ :
371
+ return
372
+ try :
373
+ opts = json .loads (os .environ [envkey ])
374
+ extra_run_kwargs = {k : v for k , v in opts .items () if k not in BLACKLISTED_DOCKER_RUN_ARGS }
375
+ run_kwargs .update (extra_run_kwargs )
376
+ if 'volumes' in opts :
377
+ if isinstance (opts ['volumes' ], list ):
378
+ opts ['volumes' ] = {
379
+ v .split (':' )[0 ]: {
380
+ 'bind' : v .split (':' )[1 ],
381
+ 'mode' : (v + ':ro' ).split (':' )[2 ]}
382
+ for v in opts ['volumes' ]}
383
+ if 'volumes' not in run_kwargs :
384
+ run_kwargs ['volumes' ] = {}
385
+ run_kwargs ['volumes' ].update (opts ['volumes' ])
386
+ except Exception :
387
+ logger .exception (f'Failed to parse { envkey } ' )
388
+
389
+
367
390
def _docker_run (task , image , pull_image = True , entrypoint = None , container_args = None ,
368
391
volumes = None , remove_container = True , stream_connectors = None , ** kwargs ):
369
392
volumes = volumes or {}
@@ -382,6 +405,7 @@ def _docker_run(task, image, pull_image=True, entrypoint=None, container_args=No
382
405
'volumes' : volumes ,
383
406
'detach' : True
384
407
}
408
+ _add_environment_kargs (run_kwargs )
385
409
386
410
# Allow run args to be overridden,filter out any we don't want to override
387
411
extra_run_kwargs = {k : v for k , v in kwargs .items () if k not in BLACKLISTED_DOCKER_RUN_ARGS }
0 commit comments