diff --git a/Jenkinsfile b/Jenkinsfile index 33a0fc31..8724c10f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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 """ diff --git a/docker/api/exec_api.py b/docker/api/exec_api.py index 830432a7..d13b1289 100644 --- a/docker/api/exec_api.py +++ b/docker/api/exec_api.py @@ -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-` where `` 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, diff --git a/docker/models/containers.py b/docker/models/containers.py index 817d5db5..10f667d7 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -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', diff --git a/docker/models/images.py b/docker/models/images.py index 30e86f10..af94520d 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -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 diff --git a/tests/integration/models_containers_test.py b/tests/integration/models_containers_test.py index b48f6fb6..92eca36d 100644 --- a/tests/integration/models_containers_test.py +++ b/tests/integration/models_containers_test.py @@ -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) diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index b35aeb6a..f44e3658 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -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,