X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/925a1526383299a1ade38a18e616564ab8c38da4..f423aff73c1927a74e39c738e08bd6f1100a94c5:/sdk/cwl/arvados_cwl/arvdocker.py diff --git a/sdk/cwl/arvados_cwl/arvdocker.py b/sdk/cwl/arvados_cwl/arvdocker.py index f83add9379..a8f56ad1d4 100644 --- a/sdk/cwl/arvados_cwl/arvdocker.py +++ b/sdk/cwl/arvados_cwl/arvdocker.py @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + import logging import sys import threading @@ -17,6 +21,9 @@ 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 "http://arvados.org/cwl#dockerCollectionPDH" in dockerRequirement: + return dockerRequirement["http://arvados.org/cwl#dockerCollectionPDH"] + if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement: dockerRequirement = copy.deepcopy(dockerRequirement) dockerRequirement["dockerImageId"] = dockerRequirement["dockerPull"] @@ -29,10 +36,10 @@ def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid if dockerRequirement["dockerImageId"] in cached_lookups: return cached_lookups[dockerRequirement["dockerImageId"]] - with SourceLine(dockerRequirement, "dockerImageId", WorkflowException): + with SourceLine(dockerRequirement, "dockerImageId", WorkflowException, logger.isEnabledFor(logging.DEBUG)): sp = dockerRequirement["dockerImageId"].split(":") image_name = sp[0] - image_tag = sp[1] if len(sp) > 1 else None + image_tag = sp[1] if len(sp) > 1 else "latest" images = arvados.commands.keepdocker.list_images_in_arv(api_client, 3, image_name=image_name, @@ -40,19 +47,23 @@ def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid if not images: # Fetch Docker image if necessary. - cwltool.docker.get_image(dockerRequirement, pull_image) + try: + cwltool.docker.DockerCommandLineJob.get_image(dockerRequirement, pull_image) + except OSError as e: + raise WorkflowException("While trying to get Docker image '%s', failed to execute 'docker': %s" % (dockerRequirement["dockerImageId"], e)) # Upload image to Arvados args = [] if project_uuid: args.append("--project-uuid="+project_uuid) args.append(image_name) - if image_tag: - args.append(image_tag) - logger.info("Uploading Docker image %s", ":".join(args[1:])) + args.append(image_tag) + logger.info("Uploading Docker image %s:%s", image_name, image_tag) try: - arvados.commands.keepdocker.main(args, stdout=sys.stderr) + arvados.commands.put.api_client = api_client + arvados.commands.keepdocker.main(args, stdout=sys.stderr, install_sig_handlers=False, api=api_client) except SystemExit as e: + # If e.code is None or zero, then keepdocker exited normally and we can continue if e.code: raise WorkflowException("keepdocker exited with code %s" % e.code) @@ -68,7 +79,7 @@ def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid with cached_lookups_lock: cached_lookups[dockerRequirement["dockerImageId"]] = pdh - return pdh + return pdh def arv_docker_clear_cache(): global cached_lookups