1- import docker
2- from os .path import join
1+ import logging
2+ from os .path import join , expanduser
33
4+ import docker
45from apluslms_yamlidator .utils .decorator import cached_property
56
67from ..utils .translation import _
1213
1314Mount = docker .types .Mount
1415
16+ logger = logging .getLogger (__name__ )
17+
1518
1619class DockerBackend (Backend ):
1720 name = 'docker'
@@ -22,14 +25,28 @@ class DockerBackend(Backend):
2225 @cached_property
2326 def _client (self ):
2427 env = self .environment .environ
25- kwargs = {}
26- version = env .get ('DOCKER_VERSION' , None )
27- if version :
28- kwargs ['version' ] = version
29- timeout = env .get ('DOCKER_TIMEOUT' , None )
30- if timeout :
31- kwargs ['timeout' ] = timeout
32- return docker .from_env (environment = env , ** kwargs )
28+ params = {
29+ 'base_url' : env .get ('host' ),
30+ 'version' : env .get ('version' ),
31+ }
32+ if 'timeout' in env :
33+ params ['timeout' ] = env ['timeout' ]
34+
35+ # false values: 0, false, '', unset
36+ # true values: 1, true, "yes"
37+ tls_verify = bool (env .get ('tls_verify' , False ))
38+ cert_path = env .get ('cert_path' ) or None
39+ if tls_verify or cert_path :
40+ if not cert_path :
41+ cert_path = join (expanduser ('~' ), '.docker' )
42+ params ['tls' ] = docker .tls .TLSConfig (
43+ client_cert = (join (cert_path , 'cert.pem' ), join (cert_path , 'key.pem' )),
44+ ca_cert = join (cert_path , 'ca.pem' ),
45+ verify = tls_verify ,
46+ ssl_version = env .get ('tls_ssl_version' ),
47+ assert_hostname = tls_verify and env .get ('tls_assert_hostname' ),
48+ )
49+ return docker .DockerClient (** params )
3350
3451 def _run_opts (self , task , step ):
3552 env = self .environment
@@ -41,9 +58,12 @@ def _run_opts(self, task, step):
4158 user = '{}:{}' .format (env .uid , env .gid ),
4259 )
4360
61+ path = self .remap_path (task .path )
62+
63+ logger .debug ("Final path is:%s" , path )
4464 # mounts and workdir
4565 if step .mnt :
46- opts ['mounts' ] = [Mount (step .mnt , task . path , type = 'bind' , read_only = False )]
66+ opts ['mounts' ] = [Mount (step .mnt , path , type = 'bind' , read_only = False )]
4767 opts ['working_dir' ] = step .mnt
4868 else :
4969 wpath = self .WORK_PATH
0 commit comments