By default, disable proxy support

This is to avoid a breaking change

Signed-off-by: Corentin Henry <corentinhenry@gmail.com>
This commit is contained in:
Corentin Henry 2018-12-15 14:32:10 +01:00 committed by Joffrey F
parent 73c17f85e5
commit 2c4a8651a8
7 changed files with 45 additions and 19 deletions

View File

@ -19,7 +19,8 @@ class BuildApiMixin(object):
forcerm=False, dockerfile=None, container_limits=None, forcerm=False, dockerfile=None, container_limits=None,
decode=False, buildargs=None, gzip=False, shmsize=None, decode=False, buildargs=None, gzip=False, shmsize=None,
labels=None, cache_from=None, target=None, network_mode=None, labels=None, cache_from=None, target=None, network_mode=None,
squash=None, extra_hosts=None, platform=None, isolation=None): squash=None, extra_hosts=None, platform=None, isolation=None,
use_config_proxy=False):
""" """
Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
needs to be set. ``path`` can be a local path (to a directory needs to be set. ``path`` can be a local path (to a directory
@ -103,6 +104,10 @@ class BuildApiMixin(object):
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:
A generator for the build output. A generator for the build output.
@ -168,9 +173,10 @@ class BuildApiMixin(object):
} }
params.update(container_limits) params.update(container_limits)
proxy_args = self._proxy_configs.get_environment() if use_config_proxy:
for k, v in proxy_args.items(): proxy_args = self._proxy_configs.get_environment()
buildargs.setdefault(k, v) for k, v in proxy_args.items():
buildargs.setdefault(k, v)
if buildargs: if buildargs:
params.update({'buildargs': json.dumps(buildargs)}) params.update({'buildargs': json.dumps(buildargs)})

View File

@ -221,7 +221,8 @@ class ContainerApiMixin(object):
working_dir=None, domainname=None, host_config=None, working_dir=None, domainname=None, host_config=None,
mac_address=None, labels=None, stop_signal=None, mac_address=None, labels=None, stop_signal=None,
networking_config=None, healthcheck=None, networking_config=None, healthcheck=None,
stop_timeout=None, runtime=None): stop_timeout=None, runtime=None,
use_config_proxy=False):
""" """
Creates a container. Parameters are similar to those for the ``docker Creates a container. Parameters are similar to those for the ``docker
run`` command except it doesn't support the attach options (``-a``). run`` command except it doesn't support the attach options (``-a``).
@ -390,6 +391,10 @@ class ContainerApiMixin(object):
runtime (str): Runtime to use with this container. runtime (str): Runtime to use with this container.
healthcheck (dict): Specify a test to perform to check that the healthcheck (dict): Specify a test to perform to check that the
container is healthy. container is healthy.
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:
A dictionary with an image 'Id' key and a 'Warnings' key. A dictionary with an image 'Id' key and a 'Warnings' key.
@ -405,7 +410,9 @@ class ContainerApiMixin(object):
if isinstance(environment, dict): if isinstance(environment, dict):
environment = utils.utils.format_environment(environment) environment = utils.utils.format_environment(environment)
environment = self._proxy_configs.inject_proxy_environment(environment) if use_config_proxy:
environment = \
self._proxy_configs.inject_proxy_environment(environment)
config = self.create_container_config( config = self.create_container_config(
image, command, hostname, user, detach, stdin_open, tty, image, command, hostname, user, detach, stdin_open, tty,

View File

@ -8,7 +8,8 @@ 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.
@ -31,6 +32,10 @@ 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.
@ -50,7 +55,9 @@ class ExecApiMixin(object):
if isinstance(environment, dict): if isinstance(environment, dict):
environment = utils.utils.format_environment(environment) environment = utils.utils.format_environment(environment)
environment = self._proxy_configs.inject_proxy_environment(environment) if use_config_proxy:
environment = \
self._proxy_configs.inject_proxy_environment(environment)
data = { data = {
'Container': container, 'Container': container,

View File

@ -144,7 +144,8 @@ 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``.
@ -167,6 +168,10 @@ 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)
@ -185,7 +190,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 workdir=workdir, use_config_proxy=use_config_proxy,
) )
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,

View File

@ -7,7 +7,7 @@ class ProxyConfig(dict):
''' '''
@property @property
def http(self): def http(self):
return self['http'] return self.get('http')
@http.setter @http.setter
def http(self, value): def http(self, value):
@ -15,7 +15,7 @@ class ProxyConfig(dict):
@property @property
def https(self): def https(self):
return self['https'] return self.get('https')
@https.setter @https.setter
def https(self, value): def https(self, value):
@ -23,7 +23,7 @@ class ProxyConfig(dict):
@property @property
def ftp(self): def ftp(self):
return self['ftp'] return self.get('ftp')
@ftp.setter @ftp.setter
def ftp(self, value): def ftp(self, value):
@ -31,7 +31,7 @@ class ProxyConfig(dict):
@property @property
def no_proxy(self): def no_proxy(self):
return self['no_proxy'] return self.get('no_proxy')
@no_proxy.setter @no_proxy.setter
def no_proxy(self, value): def no_proxy(self, value):

View File

@ -20,10 +20,11 @@ class ExecTest(BaseAPIIntegrationTest):
self.client.start(id) self.client.start(id)
self.tmp_containers.append(id) self.tmp_containers.append(id)
cmd = 'sh -c "env | grep -i proxy"'
# First, just make sure the environment variables from the custom # First, just make sure the environment variables from the custom
# config are set # config are set
res = self.client.exec_create( res = self.client.exec_create(id, cmd=cmd, use_config_proxy=True)
id, cmd='sh -c "env | grep -i proxy"')
output = self.client.exec_start(res).decode('utf-8').split('\n') output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [ expected = [
'ftp_proxy=a', 'https_proxy=b', 'http_proxy=c', 'no_proxy=d', 'ftp_proxy=a', 'https_proxy=b', 'http_proxy=c', 'no_proxy=d',
@ -34,7 +35,7 @@ class ExecTest(BaseAPIIntegrationTest):
# Overwrite some variables with a custom environment # Overwrite some variables with a custom environment
env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'} env = {'https_proxy': 'xxx', 'HTTPS_PROXY': 'XXX'}
res = self.client.exec_create( res = self.client.exec_create(
id, cmd='sh -c "env | grep -i proxy"', environment=env) id, cmd=cmd, environment=env, use_config_proxy=True)
output = self.client.exec_start(res).decode('utf-8').split('\n') output = self.client.exec_start(res).decode('utf-8').split('\n')
expected = [ expected = [
'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d', 'ftp_proxy=a', 'https_proxy=xxx', 'http_proxy=c', 'no_proxy=d',

View File

@ -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 workdir=None, use_config_proxy=False,
) )
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 workdir=None, use_config_proxy=False,
) )
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,