mirror of https://github.com/docker/docker-py.git
Remove use_config_proxy from exec. Add use_config_proxy docs to DockerClient
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
1073b73648
commit
a579e9e205
|
|
@ -91,7 +91,7 @@ def runTests = { Map settings ->
|
||||||
--network ${testNetwork} \\
|
--network ${testNetwork} \\
|
||||||
--volumes-from ${dindContainerName} \\
|
--volumes-from ${dindContainerName} \\
|
||||||
${testImage} \\
|
${testImage} \\
|
||||||
py.test -v -rxs tests/integration
|
py.test -v -rxs --cov=docker tests/
|
||||||
"""
|
"""
|
||||||
} finally {
|
} finally {
|
||||||
sh """
|
sh """
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,7 @@ class ExecApiMixin(object):
|
||||||
@utils.check_resource('container')
|
@utils.check_resource('container')
|
||||||
def exec_create(self, container, cmd, stdout=True, stderr=True,
|
def exec_create(self, container, cmd, stdout=True, stderr=True,
|
||||||
stdin=False, tty=False, privileged=False, user='',
|
stdin=False, tty=False, privileged=False, user='',
|
||||||
environment=None, workdir=None, detach_keys=None,
|
environment=None, workdir=None, detach_keys=None):
|
||||||
use_config_proxy=False):
|
|
||||||
"""
|
"""
|
||||||
Sets up an exec instance in a running container.
|
Sets up an exec instance in a running container.
|
||||||
|
|
||||||
|
|
@ -32,10 +31,6 @@ class ExecApiMixin(object):
|
||||||
or `ctrl-<value>` where `<value>` is one of:
|
or `ctrl-<value>` where `<value>` is one of:
|
||||||
`a-z`, `@`, `^`, `[`, `,` or `_`.
|
`a-z`, `@`, `^`, `[`, `,` or `_`.
|
||||||
~/.docker/config.json is used by default.
|
~/.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:
|
Returns:
|
||||||
(dict): A dictionary with an exec ``Id`` key.
|
(dict): A dictionary with an exec ``Id`` key.
|
||||||
|
|
@ -55,9 +50,6 @@ class ExecApiMixin(object):
|
||||||
|
|
||||||
if isinstance(environment, dict):
|
if isinstance(environment, dict):
|
||||||
environment = utils.utils.format_environment(environment)
|
environment = utils.utils.format_environment(environment)
|
||||||
if use_config_proxy:
|
|
||||||
environment = \
|
|
||||||
self._proxy_configs.inject_proxy_environment(environment)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'Container': container,
|
'Container': container,
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,7 @@ class Container(Model):
|
||||||
|
|
||||||
def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
|
def exec_run(self, cmd, stdout=True, stderr=True, stdin=False, tty=False,
|
||||||
privileged=False, user='', detach=False, stream=False,
|
privileged=False, user='', detach=False, stream=False,
|
||||||
socket=False, environment=None, workdir=None, demux=False,
|
socket=False, environment=None, workdir=None, demux=False):
|
||||||
use_config_proxy=False):
|
|
||||||
"""
|
"""
|
||||||
Run a command inside this container. Similar to
|
Run a command inside this container. Similar to
|
||||||
``docker exec``.
|
``docker exec``.
|
||||||
|
|
@ -168,10 +167,6 @@ class Container(Model):
|
||||||
``{"PASSWORD": "xxx"}``.
|
``{"PASSWORD": "xxx"}``.
|
||||||
workdir (str): Path to working directory for this exec session
|
workdir (str): Path to working directory for this exec session
|
||||||
demux (bool): Return stdout and stderr separately
|
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:
|
Returns:
|
||||||
(ExecResult): A tuple of (exit_code, output)
|
(ExecResult): A tuple of (exit_code, output)
|
||||||
|
|
@ -190,7 +185,7 @@ class Container(Model):
|
||||||
resp = self.client.api.exec_create(
|
resp = self.client.api.exec_create(
|
||||||
self.id, cmd, stdout=stdout, stderr=stderr, stdin=stdin, tty=tty,
|
self.id, cmd, stdout=stdout, stderr=stderr, stdin=stdin, tty=tty,
|
||||||
privileged=privileged, user=user, environment=environment,
|
privileged=privileged, user=user, environment=environment,
|
||||||
workdir=workdir, use_config_proxy=use_config_proxy,
|
workdir=workdir,
|
||||||
)
|
)
|
||||||
exec_output = self.client.api.exec_start(
|
exec_output = self.client.api.exec_start(
|
||||||
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket,
|
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket,
|
||||||
|
|
@ -682,6 +677,7 @@ class ContainerCollection(Collection):
|
||||||
For example:
|
For example:
|
||||||
``{"Name": "on-failure", "MaximumRetryCount": 5}``
|
``{"Name": "on-failure", "MaximumRetryCount": 5}``
|
||||||
|
|
||||||
|
runtime (str): Runtime to use with this container.
|
||||||
security_opt (:py:class:`list`): A list of string values to
|
security_opt (:py:class:`list`): A list of string values to
|
||||||
customize labels for MLS systems, such as SELinux.
|
customize labels for MLS systems, such as SELinux.
|
||||||
shm_size (str or int): Size of /dev/shm (e.g. ``1G``).
|
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.
|
tty (bool): Allocate a pseudo-TTY.
|
||||||
ulimits (:py:class:`list`): Ulimits to set inside the container,
|
ulimits (:py:class:`list`): Ulimits to set inside the container,
|
||||||
as a list of :py:class:`docker.types.Ulimit` instances.
|
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
|
user (str or int): Username or UID to run commands as inside the
|
||||||
container.
|
container.
|
||||||
userns_mode (str): Sets the user namespace mode for 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
|
volumes_from (:py:class:`list`): List of container names or IDs to
|
||||||
get volumes from.
|
get volumes from.
|
||||||
working_dir (str): Path to the working directory.
|
working_dir (str): Path to the working directory.
|
||||||
runtime (str): Runtime to use with this container.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The container logs, either ``STDOUT``, ``STDERR``, or both,
|
The container logs, either ``STDOUT``, ``STDERR``, or both,
|
||||||
|
|
@ -952,6 +951,7 @@ RUN_CREATE_KWARGS = [
|
||||||
'stdin_open',
|
'stdin_open',
|
||||||
'stop_signal',
|
'stop_signal',
|
||||||
'tty',
|
'tty',
|
||||||
|
'use_config_proxy',
|
||||||
'user',
|
'user',
|
||||||
'volume_driver',
|
'volume_driver',
|
||||||
'working_dir',
|
'working_dir',
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,10 @@ class ImageCollection(Collection):
|
||||||
platform (str): Platform in the format ``os[/arch[/variant]]``.
|
platform (str): Platform in the format ``os[/arch[/variant]]``.
|
||||||
isolation (str): Isolation technology used during build.
|
isolation (str): Isolation technology used during build.
|
||||||
Default: `None`.
|
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:
|
Returns:
|
||||||
(tuple): The first item is the :py:class:`Image` object for the
|
(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[0] == b'hello\n'
|
||||||
assert logs[1] == b'world\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):
|
def test_get(self):
|
||||||
client = docker.from_env(version=TEST_API_VERSION)
|
client = docker.from_env(version=TEST_API_VERSION)
|
||||||
container = client.containers.run("alpine", "sleep 300", detach=True)
|
container = client.containers.run("alpine", "sleep 300", detach=True)
|
||||||
|
|
|
||||||
|
|
@ -416,7 +416,7 @@ class ContainerTest(unittest.TestCase):
|
||||||
client.api.exec_create.assert_called_with(
|
client.api.exec_create.assert_called_with(
|
||||||
FAKE_CONTAINER_ID, "echo hello world", stdout=True, stderr=True,
|
FAKE_CONTAINER_ID, "echo hello world", stdout=True, stderr=True,
|
||||||
stdin=False, tty=False, privileged=True, user='', environment=None,
|
stdin=False, tty=False, privileged=True, user='', environment=None,
|
||||||
workdir=None, use_config_proxy=False,
|
workdir=None,
|
||||||
)
|
)
|
||||||
client.api.exec_start.assert_called_with(
|
client.api.exec_start.assert_called_with(
|
||||||
FAKE_EXEC_ID, detach=False, tty=False, stream=True, socket=False,
|
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(
|
client.api.exec_create.assert_called_with(
|
||||||
FAKE_CONTAINER_ID, "docker ps", stdout=True, stderr=True,
|
FAKE_CONTAINER_ID, "docker ps", stdout=True, stderr=True,
|
||||||
stdin=False, tty=False, privileged=True, user='', environment=None,
|
stdin=False, tty=False, privileged=True, user='', environment=None,
|
||||||
workdir=None, use_config_proxy=False,
|
workdir=None,
|
||||||
)
|
)
|
||||||
client.api.exec_start.assert_called_with(
|
client.api.exec_start.assert_called_with(
|
||||||
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False,
|
FAKE_EXEC_ID, detach=False, tty=False, stream=False, socket=False,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue