Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Fixes #147 COMPOSE_HTTP_TIMEOUT regression #660

Closed
wants to merge 8 commits into from
23 changes: 21 additions & 2 deletions container/docker/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from docker.errors import DockerException
from docker.api.container import ContainerApiMixin
from docker.models.containers import RUN_HOST_CONFIG_KWARGS
from docker.constants import DEFAULT_TIMEOUT_SECONDS
except ImportError:
raise ImportError(
u'You must install Ansible Container with Docker(tm) support. '
Expand Down Expand Up @@ -83,6 +84,23 @@ def __wrapped__(self, *args, **kwargs):
return fn(self, *args, **kwargs)
return __wrapped__

def get_timeout():
timeout = DEFAULT_TIMEOUT_SECONDS
source = None
if os.environ.get('DOCKER_CLIENT_TIMEOUT'):
timeout_value = os.environ.get('DOCKER_CLIENT_TIMEOUT')
source = 'DOCKER_CLIENT_TIMEOUT'
elif os.environ.get('COMPOSE_HTTP_TIMEOUT'):
timeout_value = os.environ.get('COMPOSE_HTTP_TIMEOUT')
source = 'COMPOSE_HTTP_TIMEOUT'
if source:
try:
timeout = int(timeout_value)
except ValueError:
raise Exception("Error: {0} set to '{1}'. Expected an integer.".format(source, timeout_value))
logger.debug("Setting Docker client timeout to {0}".format(timeout))
return timeout


class Engine(BaseEngine):

Expand Down Expand Up @@ -120,7 +138,8 @@ class Engine(BaseEngine):
def client(self):
if not self._client:
try:
self._client = docker.from_env(version='auto')
timeout = get_timeout()
self._client = docker.from_env(version='auto', timeout=timeout)
except DockerException as exc:
if 'Connection refused' in str(exc):
raise exceptions.AnsibleContainerDockerConnectionRefused()
Expand Down Expand Up @@ -509,7 +528,7 @@ def pull_image_by_tag(self, image):
try:
image_id = self.client.images.pull(repo, tag=tag)
except docker_errors.APIError as exc:
raise exceptions.AnsibleContainerException("Failed to pull {}: {}".format(image_name, str(exc)))
raise exceptions.AnsibleContainerException("Failed to pull {}: {}".format(image, str(exc)))
return image_id

@log_runs
Expand Down