Skip to content

Commit a579e9e

Browse files
committed
Remove use_config_proxy from exec. Add use_config_proxy docs to DockerClient
Signed-off-by: Joffrey F <[email protected]>
1 parent 1073b73 commit a579e9e

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def runTests = { Map settings ->
9191
--network ${testNetwork} \\
9292
--volumes-from ${dindContainerName} \\
9393
${testImage} \\
94-
py.test -v -rxs tests/integration
94+
py.test -v -rxs --cov=docker tests/
9595
"""
9696
} finally {
9797
sh """

docker/api/exec_api.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ 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,
12-
use_config_proxy=False):
11+
environment=None, workdir=None, detach_keys=None):
1312
"""
1413
Sets up an exec instance in a running container.
1514
@@ -32,10 +31,6 @@ def exec_create(self, container, cmd, stdout=True, stderr=True,
3231
or `ctrl-<value>` where `<value>` is one of:
3332
`a-z`, `@`, `^`, `[`, `,` or `_`.
3433
~/.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.
3934
4035
Returns:
4136
(dict): A dictionary with an exec ``Id`` key.
@@ -55,9 +50,6 @@ def exec_create(self, container, cmd, stdout=True, stderr=True,
5550

5651
if isinstance(environment, dict):
5752
environment = utils.utils.format_environment(environment)
58-
if use_config_proxy:
59-
environment = \
60-
self._proxy_configs.inject_proxy_environment(environment)
6153

6254
data = {
6355
'Container': container,

docker/models/containers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ 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,
148-
use_config_proxy=False):
147+
socket=False, environment=None, workdir=None, demux=False):
149148
"""
150149
Run a command inside this container. Similar to
151150
``docker exec``.
@@ -168,10 +167,6 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
168167
``{"PASSWORD": "xxx"}``.
169168
workdir (str): Path to working directory for this exec session
170169
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.
175170
176171
Returns:
177172
(ExecResult): A tuple of (exit_code, output)
@@ -190,7 +185,7 @@ def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
190185
resp = self.client.api.exec_create(
191186
self.id, cmd, stdout=stdout, stderr=stderr, stdin=stdin, tty=tty,
192187
privileged=privileged, user=user, environment=environment,
193-
workdir=workdir, use_config_proxy=use_config_proxy,
188+
workdir=workdir,
194189
)
195190
exec_output = self.client.api.exec_start(
196191
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket,
@@ -682,6 +677,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
682677
For example:
683678
``{"Name": "on-failure", "MaximumRetryCount": 5}``
684679
680+
runtime (str): Runtime to use with this container.
685681
security_opt (:py:class:`list`): A list of string values to
686682
customize labels for MLS systems, such as SELinux.
687683
shm_size (str or int): Size of /dev/shm (e.g. ``1G``).
@@ -713,6 +709,10 @@ def run(self, image, command=None, stdout=True, stderr=False,
713709
tty (bool): Allocate a pseudo-TTY.
714710
ulimits (:py:class:`list`): Ulimits to set inside the container,
715711
as a list of :py:class:`docker.types.Ulimit` instances.
712+
use_config_proxy (bool): If ``True``, and if the docker client
713+
configuration file (``~/.docker/config.json`` by default)
714+
contains a proxy configuration, the corresponding environment
715+
variables will be set in the container being built.
716716
user (str or int): Username or UID to run commands as inside the
717717
container.
718718
userns_mode (str): Sets the user namespace mode for the container
@@ -737,7 +737,6 @@ def run(self, image, command=None, stdout=True, stderr=False,
737737
volumes_from (:py:class:`list`): List of container names or IDs to
738738
get volumes from.
739739
working_dir (str): Path to the working directory.
740-
runtime (str): Runtime to use with this container.
741740
742741
Returns:
743742
The container logs, either ``STDOUT``, ``STDERR``, or both,
@@ -952,6 +951,7 @@ def prune(self, filters=None):
952951
'stdin_open',
953952
'stop_signal',
954953
'tty',
954+
'use_config_proxy',
955955
'user',
956956
'volume_driver',
957957
'working_dir',

docker/models/images.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ def build(self, **kwargs):
258258
platform (str): Platform in the format ``os[/arch[/variant]]``.
259259
isolation (str): Isolation technology used during build.
260260
Default: `None`.
261+
use_config_proxy (bool): If ``True``, and if the docker client
262+
configuration file (``~/.docker/config.json`` by default)
263+
contains a proxy configuration, the corresponding environment
264+
variables will be set in the container being built.
261265
262266
Returns:
263267
(tuple): The first item is the :py:class:`Image` object for the

tests/integration/models_containers_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ def test_run_with_streamed_logs_and_cancel(self):
163163
assert logs[0] == b'hello\n'
164164
assert logs[1] == b'world\n'
165165

166+
def test_run_with_proxy_config(self):
167+
client = docker.from_env(version=TEST_API_VERSION)
168+
client.api._proxy_configs = docker.utils.proxy.ProxyConfig(
169+
ftp='sakuya.jp:4967'
170+
)
171+
172+
out = client.containers.run(
173+
'alpine', 'sh -c "env"', use_config_proxy=True
174+
)
175+
176+
assert b'FTP_PROXY=sakuya.jp:4967\n' in out
177+
assert b'ftp_proxy=sakuya.jp:4967\n' in out
178+
166179
def test_get(self):
167180
client = docker.from_env(version=TEST_API_VERSION)
168181
container = client.containers.run("alpine", "sleep 300", detach=True)

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, use_config_proxy=False,
419+
workdir=None,
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, use_config_proxy=False,
433+
workdir=None,
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)