@@ -19,7 +19,8 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
19
19
forcerm = False , dockerfile = None , container_limits = None ,
20
20
decode = False , buildargs = None , gzip = False , shmsize = None ,
21
21
labels = None , cache_from = None , target = None , network_mode = None ,
22
- squash = None , extra_hosts = None , platform = None , isolation = None ):
22
+ squash = None , extra_hosts = None , platform = None , isolation = None ,
23
+ use_config_proxy = False ):
23
24
"""
24
25
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
25
26
needs to be set. ``path`` can be a local path (to a directory
@@ -103,6 +104,10 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
103
104
platform (str): Platform in the format ``os[/arch[/variant]]``
104
105
isolation (str): Isolation technology used during build.
105
106
Default: `None`.
107
+ use_config_proxy (bool): If ``True``, and if the docker client
108
+ configuration file (``~/.docker/config.json`` by default)
109
+ contains a proxy configuration, the corresponding environment
110
+ variables will be set in the container being built.
106
111
107
112
Returns:
108
113
A generator for the build output.
@@ -168,6 +173,10 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
168
173
}
169
174
params .update (container_limits )
170
175
176
+ if use_config_proxy :
177
+ proxy_args = self ._proxy_configs .get_environment ()
178
+ for k , v in proxy_args .items ():
179
+ buildargs .setdefault (k , v )
171
180
if buildargs :
172
181
params .update ({'buildargs' : json .dumps (buildargs )})
173
182
@@ -286,48 +295,31 @@ def _set_auth_headers(self, headers):
286
295
287
296
# If we don't have any auth data so far, try reloading the config
288
297
# file one more time in case anything showed up in there.
289
- if not self ._auth_configs :
298
+ if not self ._auth_configs or self . _auth_configs . is_empty :
290
299
log .debug ("No auth config in memory - loading from filesystem" )
291
- self ._auth_configs = auth .load_config ()
300
+ self ._auth_configs = auth .load_config (
301
+ credstore_env = self .credstore_env
302
+ )
292
303
293
304
# Send the full auth configuration (if any exists), since the build
294
305
# could use any (or all) of the registries.
295
306
if self ._auth_configs :
296
- auth_cfgs = self ._auth_configs
297
- auth_data = {}
298
- if auth_cfgs .get ('credsStore' ):
299
- # Using a credentials store, we need to retrieve the
300
- # credentials for each registry listed in the config.json file
301
- # Matches CLI behavior: https://github.com/docker/docker/blob/
302
- # 67b85f9d26f1b0b2b240f2d794748fac0f45243c/cliconfig/
303
- # credentials/native_store.go#L68-L83
304
- for registry in auth_cfgs .get ('auths' , {}).keys ():
305
- auth_data [registry ] = auth .resolve_authconfig (
306
- auth_cfgs , registry ,
307
- credstore_env = self .credstore_env ,
308
- )
309
- else :
310
- for registry in auth_cfgs .get ('credHelpers' , {}).keys ():
311
- auth_data [registry ] = auth .resolve_authconfig (
312
- auth_cfgs , registry ,
313
- credstore_env = self .credstore_env
314
- )
315
- for registry , creds in auth_cfgs .get ('auths' , {}).items ():
316
- if registry not in auth_data :
317
- auth_data [registry ] = creds
318
- # See https://github.com/docker/docker-py/issues/1683
319
- if auth .INDEX_NAME in auth_data :
320
- auth_data [auth .INDEX_URL ] = auth_data [auth .INDEX_NAME ]
307
+ auth_data = self ._auth_configs .get_all_credentials ()
308
+
309
+ # See https://github.com/docker/docker-py/issues/1683
310
+ if auth .INDEX_URL not in auth_data and auth .INDEX_URL in auth_data :
311
+ auth_data [auth .INDEX_URL ] = auth_data .get (auth .INDEX_NAME , {})
321
312
322
313
log .debug (
323
314
'Sending auth config ({0})' .format (
324
315
', ' .join (repr (k ) for k in auth_data .keys ())
325
316
)
326
317
)
327
318
328
- headers ['X-Registry-Config' ] = auth .encode_header (
329
- auth_data
330
- )
319
+ if auth_data :
320
+ headers ['X-Registry-Config' ] = auth .encode_header (
321
+ auth_data
322
+ )
331
323
else :
332
324
log .debug ('No auth config found' )
333
325
0 commit comments