|
22 | 22 | from uuid import uuid4 |
23 | 23 |
|
24 | 24 | import docker |
| 25 | +from requests.exceptions import ReadTimeout |
25 | 26 |
|
26 | 27 | from renku.core import errors |
27 | 28 | from renku.core.config import get_value |
@@ -77,16 +78,22 @@ def build_image(self, image_descriptor: Path, image_name: str, config: Optional[ |
77 | 78 |
|
78 | 79 | def find_image(self, image_name: str, config: Optional[Dict[str, Any]]) -> bool: |
79 | 80 | """Find the given container image.""" |
80 | | - try: |
81 | | - self.docker_client().images.get(image_name) |
82 | | - except docker.errors.ImageNotFound: |
| 81 | + with communication.busy(msg=f"Checking for image {image_name}"): |
83 | 82 | try: |
84 | | - with communication.busy(msg=f"Pulling image from remote {image_name}"): |
85 | | - self.docker_client().images.pull(image_name) |
86 | | - except docker.errors.NotFound: |
87 | | - return False |
| 83 | + self.docker_client().images.get(image_name) |
| 84 | + except docker.errors.ImageNotFound: |
| 85 | + try: |
| 86 | + self.docker_client().images.get_registry_data(image_name) |
| 87 | + except docker.errors.NotFound: |
| 88 | + return False |
88 | 89 | else: |
89 | 90 | return True |
| 91 | + |
| 92 | + try: |
| 93 | + with communication.busy(msg=f"Pulling image from remote {image_name}"): |
| 94 | + self.docker_client().images.pull(image_name) |
| 95 | + except docker.errors.NotFound: |
| 96 | + return False |
90 | 97 | else: |
91 | 98 | return True |
92 | 99 |
|
@@ -208,8 +215,14 @@ def session_start( |
208 | 215 | message = f"The session for '{image_name}' has been successfully started. It is available at:\n\t" |
209 | 216 | message += "\n\t".join(jupyter_urls) |
210 | 217 | return message |
211 | | - except (docker.errors.APIError, docker.errors.BuildError) as error: |
212 | | - raise errors.DockerError(str(error)) |
| 218 | + except docker.errors.BuildError as error: |
| 219 | + raise errors.DockerError("Couldn't build the image. See inner exception for details.") from error |
| 220 | + except docker.errors.APIError as error: |
| 221 | + raise errors.DockerError("Docker API returned an error. See inner exception for details.") from error |
| 222 | + except ReadTimeout as error: |
| 223 | + raise errors.DockerError( |
| 224 | + "Couldn't reach the Docker API. Is the docker service running and up to date?" |
| 225 | + ) from error |
213 | 226 |
|
214 | 227 | def session_stop(self, project_name: str, session_name: Optional[str], stop_all: bool) -> bool: |
215 | 228 | """Stops all or a given interactive session.""" |
|
0 commit comments