Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): check for image in registry before pulling and improve error messages #3265

Merged
merged 1 commit into from Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 22 additions & 9 deletions renku/core/session/docker.py
Expand Up @@ -22,6 +22,7 @@
from uuid import uuid4

import docker
from requests.exceptions import ReadTimeout

from renku.core import errors
from renku.core.config import get_value
Expand Down Expand Up @@ -77,16 +78,22 @@ def build_image(self, image_descriptor: Path, image_name: str, config: Optional[

def find_image(self, image_name: str, config: Optional[Dict[str, Any]]) -> bool:
"""Find the given container image."""
try:
self.docker_client().images.get(image_name)
except docker.errors.ImageNotFound:
with communication.busy(msg=f"Checking for image {image_name}"):
try:
with communication.busy(msg=f"Pulling image from remote {image_name}"):
self.docker_client().images.pull(image_name)
except docker.errors.NotFound:
return False
self.docker_client().images.get(image_name)
except docker.errors.ImageNotFound:
try:
self.docker_client().images.get_registry_data(image_name)
except docker.errors.NotFound:
return False
else:
return True

try:
with communication.busy(msg=f"Pulling image from remote {image_name}"):
self.docker_client().images.pull(image_name)
except docker.errors.NotFound:
return False
else:
return True

Expand Down Expand Up @@ -208,8 +215,14 @@ def session_start(
message = f"The session for '{image_name}' has been successfully started. It is available at:\n\t"
message += "\n\t".join(jupyter_urls)
return message
except (docker.errors.APIError, docker.errors.BuildError) as error:
raise errors.DockerError(str(error))
except docker.errors.BuildError as error:
raise errors.DockerError("Couldn't build the image. See inner exception for details.") from error
except docker.errors.APIError as error:
raise errors.DockerError("Docker API returned an error. See inner exception for details.") from error
except ReadTimeout as error:
raise errors.DockerError(
"Couldn't reach the Docker API. Is the docker service running and up to date?"
) from error

def session_stop(self, project_name: str, session_name: Optional[str], stop_all: bool) -> bool:
"""Stops all or a given interactive session."""
Expand Down