5 from cwltool.errors import WorkflowException
6 import arvados.commands.keepdocker
9 logger = logging.getLogger('arvados.cwl-runner')
11 def arv_docker_get_image(api_client, dockerRequirement, pull_image, project_uuid):
12 """Check if a Docker image is available in Keep, if not, upload it using arv-keepdocker."""
14 if "dockerImageId" not in dockerRequirement and "dockerPull" in dockerRequirement:
15 dockerRequirement["dockerImageId"] = dockerRequirement["dockerPull"]
17 sp = dockerRequirement["dockerImageId"].split(":")
19 image_tag = sp[1] if len(sp) > 1 else None
21 images = arvados.commands.keepdocker.list_images_in_arv(api_client, 3,
22 image_name=image_name,
26 # Fetch Docker image if necessary.
27 cwltool.docker.get_image(dockerRequirement, pull_image)
29 # Upload image to Arvados
30 args = ["--project-uuid="+project_uuid, image_name]
32 args.append(image_tag)
33 logger.info("Uploading Docker image %s", ":".join(args[1:]))
35 arvados.commands.keepdocker.main(args, stdout=sys.stderr)
37 raise WorkflowException()
39 images = arvados.commands.keepdocker.list_images_in_arv(api_client, 3,
40 image_name=image_name,
44 raise WorkflowException("Could not find Docker image %s:%s" % (image_name, image_tag))
46 pdh = api_client.collections().get(uuid=images[0][0]).execute()["portable_data_hash"]