Skip to content

Commit 2c4a865

Browse files
little-dudeshin-
authored andcommitted
By default, disable proxy support
This is to avoid a breaking change Signed-off-by: Corentin Henry <[email protected]>
1 parent 73c17f8 commit 2c4a865

File tree

7 files changed

+45
-19
lines changed

7 files changed

+45
-19
lines changed

docker/api/build.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
1919
forcerm=False, dockerfile=None, container_limits=None,
2020
decode=False, buildargs=None, gzip=False, shmsize=None,
2121
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):
2324
"""
2425
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
2526
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,
103104
platform (str): Platform in the format ``os[/arch[/variant]]``
104105
isolation (str): Isolation technology used during build.
105106
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.
106111
107112
Returns:
108113
A generator for the build output.
@@ -168,9 +173,10 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
168173
}
169174
params.update(container_limits)
170175

171-
proxy_args = self._proxy_configs.get_environment()
172-
for k, v in proxy_args.items():
173-
buildargs.setdefault(k, v)
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)
174180
if buildargs:
175181
params.update({'buildargs': json.dumps(buildargs)})
176182

docker/api/container.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ def create_container(self, image, command=None, hostname=None, user=None,
221221
working_dir=None, domainname=None, host_config=None,
222222
mac_address=None, labels=None, stop_signal=None,
223223
networking_config=None, healthcheck=None,
224-
stop_timeout=None, runtime=None):
224+
stop_timeout=None, runtime=None,
225+
use_config_proxy=False):
225226
"""
226227
Creates a container. Parameters are similar to those for the ``docker
227228
run`` command except it doesn't support the attach options (``-a``).
@@ -390,6 +391,10 @@ def create_container(self, image, command=None, hostname=None, user=None,
390391
runtime (str): Runtime to use with this container.
391392
healthcheck (dict): Specify a test to perform to check that the
392393
container is healthy.
394+
use_config_proxy (bool): If ``True``, and if the docker client
395+
configuration file (``~/.docker/config.json`` by default)
396+
contains a proxy configuration, the corresponding environment
397+
variables will be set in the container being created.
393398
394399
Returns:
395400
A dictionary with an image 'Id' key and a 'Warnings' key.
@@ -405,7 +410,9 @@ def create_container(self, image, command=None, hostname=None, user=None,
405410

406411
if isinstance(environment, dict):
407412
environment = utils.utils.format_environment(environment)
408-
environment = self._proxy_configs.inject_proxy_environment(environment)
413+
if use_config_proxy:
414+
environment = \
415+
self._proxy_configs.inject_proxy_environment(environment)
409416

410417
config = self.create_container_config(
411418
image, command, hostname, user, detach, stdin_open, tty,

docker/api/exec_api.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ class ExecApiMixin(object):
88
@utils.check_resource('container')
99
def exec_create(self, container, cmd, stdout=True, stderr=True,
1010
stdin=False, tty=False, privileged=False, user='',
11-
environment=None, workdir=None, detach_keys=None):
11+
environment=None, workdir=None, detach_keys=None,
12+
use_config_proxy=False):
1213
"""
1314
Sets up an exec instance in a running container.
1415
@@ -31,6 +32,10 @@ def exec_create(self, container, cmd, stdout=True, stderr=True,
3132
or `ctrl-<value>` where `<value>` is one of:
3233
`a-z`, `@`, `^`, `[`, `,` or `_`.
3334
~/.docker/config.json is used by default.
35+
use_config_proxy (bool): If ``True``, and if the docker client
36+
configuration file (``~/.docker/config.json`` by default)
37+
contains a proxy configuration, the corresponding environment
38+
variables will be set in the container being created.
3439
3540
Returns:
3641
(dict): A dictionary with an exec ``Id`` key.
@@ -50,7 +55,9 @@ def exec_create(self, container, cmd, stdout=True, stderr=True,
5055

5156
if isinstance(environment, dict):
5257
environment = utils.utils.format_environment(environment)
53-
environment = self._proxy_configs.inject_proxy_environment(environment)
58+
if use_config_proxy:
59+
environment = \
60+
self._proxy_configs.inject_proxy_environment(environment)
5461

5562
data = {
5663
'Container': container,

docker/models/containers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def diff(self):
144144

145145
def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
146146
privileged=False, user='', detach=False, stream=False,
147-
socket=False, environment=None, workdir=None, demux=False):
147+
socket=False, environment=None, workdir=None, demux=False,
148+
use_config_proxy=False):
148149
"""
149150
Run a command inside this container. Similar to
150151
``docker exec``.
@@ -167,6 +168,10 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
167168
``{"PASSWORD": "xxx"}``.
168169
workdir (str): Path to working directory for this exec session
169170
demux (bool): Return stdout and stderr separately
171+
use_config_proxy (bool): If ``True``, and if the docker client
172+
configuration file (``~/.docker/config.json`` by default)
173+
contains a proxy configuration, the corresponding environment
174+
variables will be set in the command's environment.
170175
171176
Returns:
172177
(ExecResult): A tuple of (exit_code, output)
@@ -185,7 +190,7 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
185190
resp = self.client.api.exec_create(
186191
self.id, cmd, stdout=stdout, stderr=stderr, stdin=stdin, tty=tty,
187192
privileged=privileged, user=user, environment=environment,
188-
workdir=workdir
193+
workdir=workdir, use_config_proxy=use_config_proxy,
189194
)
190195
exec_output = self.client.api.exec_start(
191196
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket,

docker/utils/proxy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ class ProxyConfig(dict):
77
'''
88
@property
99
def http(self):
10-
return self['http']
10+
return self.get('http')
1111

1212
@http.setter
1313
def http(self, value):
1414
self['http'] = value
1515

1616
@property
1717
def https(self):
18-
return self['https']
18+
return self.get('https')
1919

2020
@https.setter
2121
def https(self, value):
2222
self['https'] = value
2323

2424
@property
2525
def ftp(self):
26-
return self['ftp']
26+
return self.get('ftp')
2727

2828
@ftp.setter
2929
def ftp(self, value):
3030
self['ftp'] = value
3131

3232
@property
3333
def no_proxy(self):
34-
return self['no_proxy']
34+
return self.get('no_proxy')
3535

3636
@no_proxy.setter
3737
def no_proxy(self, value):

tests/integration/api_exec_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ def test_execute_proxy_env(self):
2020
self.client.start(id)
2121
self.tmp_containers.append(id)
2222

23+
cmd = 'sh -c "env | grep -i proxy"'
24+
2325
# First, just make sure the environment variables from the custom
2426
# config are set
25-
res = self.client.exec_create(
26-
id, cmd='sh -c "env | grep -i proxy"')
27+
res = self.client.exec_create(id, cmd=cmd, use_config_proxy=True)
2728
output = self.client.exec_start(res).decode('utf-8').split('\n')
2829
expected = [
2930
'ftp_proxy=a', 'https_proxy=b', 'http_proxy=c', 'no_proxy=d',
@@ -34,7 +35,7 @@ def test_execute_proxy_env(self):
3435
# Overwrite some variables with a custom environment
3536
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}
3637
res = self.client.exec_create(
37-
id, cmd='sh -c "env | grep -i proxy"', environment=env)
38+
id, cmd=cmd, environment=env, use_config_proxy=True)
3839
output = self.client.exec_start(res).decode('utf-8').split('\n')
3940
expected = [
4041
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',

tests/unit/models_containers_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def test_exec_run(self):
416416
client.api.exec_create.assert_called_with(
417417
FAKE_CONTAINER_ID, "echo hello world", stdout=True, stderr=True,
418418
stdin=False, tty=False, privileged=True, user='', environment=None,
419-
workdir=None
419+
workdir=None, use_config_proxy=False,
420420
)
421421
client.api.exec_start.assert_called_with(
422422
FAKE_EXEC_ID, detach=False, tty=False, stream=True, socket=False,
@@ -430,7 +430,7 @@ def test_exec_run_failure(self):
430430
client.api.exec_create.assert_called_with(
431431
FAKE_CONTAINER_ID, "docker ps", stdout=True, stderr=True,
432432
stdin=False, tty=False, privileged=True, user='', environment=None,
433-
workdir=None
433+
workdir=None, use_config_proxy=False,
434434
)
435435
client.api.exec_start.assert_called_with(
436436
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False,

0 commit comments

Comments
 (0)