Use the new kwargs_from_env so that we can test with boot2docker and fix the issue with the .history call.
This commit is contained in:
parent
716d7a737b
commit
b2a0e58756
1 changed files with 15 additions and 6 deletions
|
@ -13,6 +13,7 @@ import shutil
|
|||
import tarfile
|
||||
|
||||
from docker import Client
|
||||
from docker.utils import kwargs_from_env
|
||||
from docker.errors import APIError
|
||||
from tempfile import TemporaryFile, mkdtemp
|
||||
from zipfile import ZipFile
|
||||
|
@ -38,7 +39,12 @@ TIMEOUT_PERIOD_MINUTES = 20
|
|||
CACHE_EXPIRATION_PERIOD_HOURS = 24
|
||||
NO_TAGS = ['<none>:<none>']
|
||||
RESERVATION_TIME = (TIMEOUT_PERIOD_MINUTES + 5) * 60
|
||||
DOCKER_BASE_URL = os.environ.get('DOCKER_HOST', None)
|
||||
|
||||
def build_docker_args():
|
||||
args = kwargs_from_env()
|
||||
if 'tls' in args and os.environ.get('IGNORE_TLS_ISSUES', False):
|
||||
args['tls'].verify = False
|
||||
return args
|
||||
|
||||
|
||||
def matches_system_error(status_str):
|
||||
|
@ -130,8 +136,8 @@ class DockerfileBuildContext(object):
|
|||
# Note: We have two different clients here because we (potentially) login
|
||||
# with both, but with different credentials that we do not want shared between
|
||||
# the build and push operations.
|
||||
self._push_cl = StreamingDockerClient(timeout=1200, base_url=DOCKER_BASE_URL)
|
||||
self._build_cl = StreamingDockerClient(timeout=1200, base_url=DOCKER_BASE_URL)
|
||||
self._push_cl = StreamingDockerClient(timeout=1200, **build_docker_args())
|
||||
self._build_cl = StreamingDockerClient(timeout=1200, **build_docker_args())
|
||||
|
||||
dockerfile_path = os.path.join(self._build_dir, dockerfile_subdir,
|
||||
'Dockerfile')
|
||||
|
@ -337,7 +343,7 @@ class DockerfileBuildContext(object):
|
|||
logger.debug('Tagging image %s as %s:%s', built_image, self._repo, tag)
|
||||
self._push_cl.tag(built_image, self._repo, tag)
|
||||
|
||||
history = json.loads(self._push_cl.history(built_image))
|
||||
history = self._push_cl.history(built_image)
|
||||
num_images = len(history)
|
||||
|
||||
logger.debug('Pushing to repo %s', self._repo)
|
||||
|
@ -480,7 +486,7 @@ class DockerfileBuildWorker(Worker):
|
|||
def watchdog(self):
|
||||
logger.debug('Running build watchdog code.')
|
||||
try:
|
||||
docker_cl = Client(base_url=DOCKER_BASE_URL)
|
||||
docker_cl = Client(**build_docker_args())
|
||||
|
||||
# Iterate the running containers and kill ones that have been running more than 20 minutes
|
||||
for container in docker_cl.containers():
|
||||
|
@ -493,6 +499,7 @@ class DockerfileBuildWorker(Worker):
|
|||
self._timeout.set()
|
||||
|
||||
except ConnectionError as exc:
|
||||
logger.exception('Watchdog exception')
|
||||
raise WorkerUnhealthyException(exc.message)
|
||||
|
||||
def process_queue_item(self, job_details):
|
||||
|
@ -525,9 +532,10 @@ class DockerfileBuildWorker(Worker):
|
|||
|
||||
# Lookup and save the version of docker being used.
|
||||
try:
|
||||
docker_cl = Client(base_url=DOCKER_BASE_URL)
|
||||
docker_cl = Client(**build_docker_args())
|
||||
docker_version = docker_cl.version().get('Version', '')
|
||||
except ConnectionError as exc:
|
||||
logger.exception('Initial connection exception')
|
||||
raise WorkerUnhealthyException(exc.message)
|
||||
|
||||
dash = docker_version.find('-')
|
||||
|
@ -664,6 +672,7 @@ class DockerfileBuildWorker(Worker):
|
|||
except ConnectionError as exc:
|
||||
# A connection exception means the worker has become unhealthy (Docker is down)
|
||||
# so we re-raise as that exception.
|
||||
logger.exception('Build connection exception')
|
||||
log_appender('Docker daemon has gone away. Will retry shortly.', build_logs.ERROR)
|
||||
raise WorkerUnhealthyException(exc.message)
|
||||
|
||||
|
|
Reference in a new issue