Add possiblity to pass timeout to Docker client
Now the Docker client is prepared the correct way by allowing to specify the
timeuout via DOCKER_TIMEOUT environment variable.
Default value is 600. This is 10 minutes.
Fixes
-import docker
import logging
import os
import re
@@ -9,12 +8,25 @@ from cekit.errors import CekitError
from docker_squash.squash import Squash
try:
- docker_client = docker.Client(version="1.22")
-except AttributeError:
- docker_client = docker.APIClient(version="1.22")
+ from docker.api.client import APIClient as APIClientClass
+except ImportError:
+ from docker.client import Client as APIClientClass
logger = logging.getLogger('cekit')
+# Default timeout 10 minutes
+try:
+ timeout = int(os.getenv('DOCKER_TIMEOUT', 600))
+except ValueError as e:
+ raise CekitError("Provided timeout value: %s cannot be parsed as integer, exiting." %
+ os.getenv('DOCKER_TIMEOUT'))
+
+if not timeout > 0:
+ raise CekitError(
+ "Provided timeout value needs to be greater than zero, currently: %s, exiting." % timeout)
+
+docker_client = APIClientClass(version="1.22", timeout=timeout)
+
ANSI_ESCAPE = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
@@ -106,5 +118,7 @@ class DockerBuilder(Builder):
def squash_image(self, layer_id):
logger.info("Squashing image %s..." % (layer_id))
# XXX: currently, cleanup throws a 409 error from the docker daemon. this needs to be investigated in docker_squash
- squash = Squash(docker=docker_client, log=logger, from_layer=self._base, image=layer_id, tag=self._tags[0], cleanup=False)
+ squash = Squash(docker=docker_client, log=logger, from_layer=self._base, image=layer_id,
+ tag=self._tags[0],
+ cleanup=False)
squash.run()
