Skip to content

Commit f3717f5

Browse files
committed
Fix crash when building from remote sources
Avoid crashing when the Docker python client is able to load registry credentials when building using a remote source Signed-off-by: Vincent Giersch <[email protected]>
1 parent 39ee2d5 commit f3717f5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

docker/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
450450
# Send the full auth configuration (if any exists), since the build
451451
# could use any (or all) of the registries.
452452
if self._auth_configs:
453+
if headers is None:
454+
headers = {}
453455
headers['X-Registry-Config'] = auth.encode_full_header(
454456
self._auth_configs
455457
)

tests/test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,20 @@ def test_build_container_custom_context_gzip(self):
20032003
except Exception as e:
20042004
self.fail('Command should not raise exception: {0}'.format(e))
20052005

2006+
def test_build_remote_with_registry_auth(self):
2007+
try:
2008+
self.client._auth_configs = {
2009+
'https://example.com': {
2010+
'user': 'example',
2011+
'password': 'example',
2012+
'email': '[email protected]'
2013+
}
2014+
}
2015+
2016+
self.client.build(path='https://github.com/docker-library/mongo')
2017+
except Exception as e:
2018+
self.fail('Command should not raise exception: {0}'.format(e))
2019+
20062020
#######################
20072021
# PY SPECIFIC TESTS #
20082022
#######################

0 commit comments

Comments
 (0)