Unverified Kaydet (Commit) 55a62c26 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #2221 from docker/proxy_env_fixes

Remove use_config_proxy from exec. Add use_config_proxy docs to DockerClient
......@@ -91,7 +91,7 @@ def runTests = { Map settings ->
--network ${testNetwork} \\
--volumes-from ${dindContainerName} \\
${testImage} \\
py.test -v -rxs tests/integration
py.test -v -rxs --cov=docker tests/
"""
} finally {
sh """
......
......@@ -8,8 +8,7 @@ class ExecApiMixin(object):
@utils.check_resource('container')
def exec_create(self, container, cmd, stdout=True, stderr=True,
stdin=False, tty=False, privileged=False, user='',
environment=None, workdir=None, detach_keys=None,
use_config_proxy=False):
environment=None, workdir=None, detach_keys=None):
"""
Sets up an exec instance in a running container.
......@@ -32,10 +31,6 @@ class ExecApiMixin(object):
or `ctrl-<value>` where `<value>` is one of:
`a-z`, `@`, `^`, `[`, `,` or `_`.
~/.docker/config.json is used by default.
use_config_proxy (bool): If ``True``, and if the docker client
configuration file (``~/.docker/config.json`` by default)
contains a proxy configuration, the corresponding environment
variables will be set in the container being created.
Returns:
(dict): A dictionary with an exec ``Id`` key.
......@@ -55,9 +50,6 @@ class ExecApiMixin(object):
if isinstance(environment, dict):
environment = utils.utils.format_environment(environment)
if use_config_proxy:
environment = \
self._proxy_configs.inject_proxy_environment(environment)
data = {
'Container': container,
......
......@@ -144,8 +144,7 @@ class Container(Model):
def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
privileged=False, user='', detach=False, stream=False,
socket=False, environment=None, workdir=None, demux=False,
use_config_proxy=False):
socket=False, environment=None, workdir=None, demux=False):
"""
Run a command inside this container. Similar to
``docker exec``.
......@@ -168,10 +167,6 @@ class Container(Model):
``{"PASSWORD": "xxx"}``.
workdir (str): Path to working directory for this exec session
demux (bool): Return stdout and stderr separately
use_config_proxy (bool): If ``True``, and if the docker client
configuration file (``~/.docker/config.json`` by default)
contains a proxy configuration, the corresponding environment
variables will be set in the command's environment.
Returns:
(ExecResult): A tuple of (exit_code, output)
......@@ -190,7 +185,7 @@ class Container(Model):
resp = self.client.api.exec_create(
self.id, cmd, stdout=stdout, stderr=stderr, stdin=stdin, tty=tty,
privileged=privileged, user=user, environment=environment,
workdir=workdir, use_config_proxy=use_config_proxy,
workdir=workdir,
)
exec_output = self.client.api.exec_start(
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket,
......@@ -682,6 +677,7 @@ class ContainerCollection(Collection):
For example:
``{"Name": "on-failure", "MaximumRetryCount": 5}``
runtime (str): Runtime to use with this container.
security_opt (:py:class:`list`): A list of string values to
customize labels for MLS systems, such as SELinux.
shm_size (str or int): Size of /dev/shm (e.g. ``1G``).
......@@ -713,6 +709,10 @@ class ContainerCollection(Collection):
tty (bool): Allocate a pseudo-TTY.
ulimits (:py:class:`list`): Ulimits to set inside the container,
as a list of :py:class:`docker.types.Ulimit` instances.
use_config_proxy (bool): If ``True``, and if the docker client
configuration file (``~/.docker/config.json`` by default)
contains a proxy configuration, the corresponding environment
variables will be set in the container being built.
user (str or int): Username or UID to run commands as inside the
container.
userns_mode (str): Sets the user namespace mode for the container
......@@ -737,7 +737,6 @@ class ContainerCollection(Collection):
volumes_from (:py:class:`list`): List of container names or IDs to
get volumes from.
working_dir (str): Path to the working directory.
runtime (str): Runtime to use with this container.
Returns:
The container logs, either ``STDOUT``, ``STDERR``, or both,
......@@ -952,6 +951,7 @@ RUN_CREATE_KWARGS = [
'stdin_open',
'stop_signal',
'tty',
'use_config_proxy',
'user',
'volume_driver',
'working_dir',
......
......@@ -258,6 +258,10 @@ class ImageCollection(Collection):
platform (str): Platform in the format ``os[/arch[/variant]]``.
isolation (str): Isolation technology used during build.
Default: `None`.
use_config_proxy (bool): If ``True``, and if the docker client
configuration file (``~/.docker/config.json`` by default)
contains a proxy configuration, the corresponding environment
variables will be set in the container being built.
Returns:
(tuple): The first item is the :py:class:`Image` object for the
......
......@@ -163,6 +163,19 @@ class ContainerCollectionTest(BaseIntegrationTest):
assert logs[0] == b'hello\n'
assert logs[1] == b'world\n'
def test_run_with_proxy_config(self):
client = docker.from_env(version=TEST_API_VERSION)
client.api._proxy_configs = docker.utils.proxy.ProxyConfig(
ftp='sakuya.jp:4967'
)
out = client.containers.run(
'alpine', 'sh -c "env"', use_config_proxy=True
)
assert b'FTP_PROXY=sakuya.jp:4967\n' in out
assert b'ftp_proxy=sakuya.jp:4967\n' in out
def test_get(self):
client = docker.from_env(version=TEST_API_VERSION)
container = client.containers.run("alpine", "sleep 300", detach=True)
......
......@@ -416,7 +416,7 @@ class ContainerTest(unittest.TestCase):
client.api.exec_create.assert_called_with(
FAKE_CONTAINER_ID, "echo hello world", stdout=True, stderr=True,
stdin=False, tty=False, privileged=True, user='', environment=None,
workdir=None, use_config_proxy=False,
workdir=None,
)
client.api.exec_start.assert_called_with(
FAKE_EXEC_ID, detach=False, tty=False, stream=True, socket=False,
......@@ -430,7 +430,7 @@ class ContainerTest(unittest.TestCase):
client.api.exec_create.assert_called_with(
FAKE_CONTAINER_ID, "docker ps", stdout=True, stderr=True,
stdin=False, tty=False, privileged=True, user='', environment=None,
workdir=None, use_config_proxy=False,
workdir=None,
)
client.api.exec_start.assert_called_with(
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment