X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/734335da27f27e2177d3b931b1e5e9e8e83a042f..c14246b9a21d038fc6fa850f4032659a98397784:/sdk/cwl/arvados_cwl/arvdocker.py diff --git a/sdk/cwl/arvados_cwl/arvdocker.py b/sdk/cwl/arvados_cwl/arvdocker.py index 244dd3d357..b9691d215c 100644 --- a/sdk/cwl/arvados_cwl/arvdocker.py +++ b/sdk/cwl/arvados_cwl/arvdocker.py @@ -1,19 +1,28 @@ import logging import sys +import threading import cwltool.docker from cwltool.errors import WorkflowException import arvados.commands.keepdocker - logger = logging.getLogger('arvados.cwl-runner') +cached_lookups = {} +cached_lookups_lock = threading.Lock() + def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid): """Check if a Docker image is available in Keep, if not, upload it using arv-keepdocker.""" if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement: dockerRequirement["dockerImageId"] = dockerRequirement["dockerPull"] + global cached_lookups + global cached_lookups_lock + with cached_lookups_lock: + if dockerRequirement["dockerImageId"] in cached_lookups: + return cached_lookups[dockerRequirement["dockerImageId"]] + sp = dockerRequirement["dockerImageId"].split(":") image_name = sp[0] image_tag = sp[1] if len(sp) > 1 else None @@ -33,8 +42,9 @@ def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid logger.info("Uploading Docker image %s", ":".join(args[1:])) try: arvados.commands.keepdocker.main(args, stdout=sys.stderr) - except SystemExit: - raise WorkflowException() + except SystemExit as e: + if e.code: + raise WorkflowException("keepdocker exited with code %s" % e.code) images = arvados.commands.keepdocker.list_images_in_arv(api_client, 3, image_name=image_name, @@ -44,4 +54,14 @@ def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid raise WorkflowException("Could not find Docker image %s:%s" % (image_name, image_tag)) pdh = api_client.collections().get(uuid=images[0][0]).execute()["portable_data_hash"] + + with cached_lookups_lock: + cached_lookups[dockerRequirement["dockerImageId"]] = pdh + return pdh + +def arv_docker_clear_cache(): + global cached_lookups + global cached_lookups_lock + with cached_lookups_lock: + cached_lookups = {}