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

Try/catch for Docker client #2513

Merged
merged 9 commits into from
Mar 18, 2024

Conversation

christianversloot
Copy link
Contributor

@christianversloot christianversloot commented Mar 12, 2024

Describe changes

When your Docker daemon is not running in a Docker based stack, users get somewhat obscure errors like DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).

This PR wraps all DockerClient.from_env() calls where no try/catch construct is present with one, raising a more user-friendly error as to what is wrong and could be done to help resolve the issue.

Pre-requisites

Please ensure you have done the following:

  • I have read the CONTRIBUTING.md document.
  • If my change requires a change to docs, I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have based my new branch on develop and the open PR is targeting develop. If your branch wasn't based on develop read Contribution guide on rebasing branch to develop.
  • If my changes require changes to the dashboard, these changes are communicated/requested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (add details above)

Summary by CodeRabbit

  • New Features
    • Not applicable.
  • Bug Fixes
    • Improved error handling across various components when creating a Docker client fails, providing clearer error messages to help diagnose issues with the Docker environment.
  • Documentation
    • Not applicable.
  • Refactor
    • Enhanced exception handling for Docker client creation to ensure consistent error reporting.
  • Style
    • Not applicable.
  • Tests
    • Not applicable.
  • Chores
    • Not applicable.
  • Revert
    • Not applicable.

Copy link
Contributor

coderabbitai bot commented Mar 12, 2024

Important

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The changes across various files in the ZenML codebase focus on improving error handling when creating a Docker client from the environment. Specifically, if the process of initializing a Docker client fails due to a DockerException, a RuntimeError is now raised with a descriptive message. This enhancement ensures that users are promptly informed about issues related to Docker daemon connectivity, streamlining troubleshooting and enhancing the robustness of Docker-related operations within ZenML.

Changes

Files Change Summary
src/zenml/.../base_container_registry.py
src/zenml/.../local_image_builder.py
src/zenml/.../local_docker_orchestrator.py
src/zenml/.../docker_service_connector.py
Introduced error handling for Docker client creation from the environment, raising RuntimeError on failure.
src/zenml/.../container/container_service.py
src/zenml/utils/docker_utils.py
Added handling for DockerException when creating a Docker client; refactored environment config path setting.

🐇✨
In the realm of code where dockers sail,
A rabbit hopped, leaving a trail.
"Handle the errors," it whispered with glee,
"For smoother sailing in the Docker sea."
🚢🔧💻

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@strickvl
Copy link
Contributor

@coderabbitai review

@strickvl strickvl added the enhancement New feature or request label Mar 12, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 03f34e5 and d26b367.
Files selected for processing (6)
  • src/zenml/container_registries/base_container_registry.py (2 hunks)
  • src/zenml/image_builders/local_image_builder.py (2 hunks)
  • src/zenml/orchestrators/local_docker/local_docker_orchestrator.py (1 hunks)
  • src/zenml/service_connectors/docker_service_connector.py (1 hunks)
  • src/zenml/services/container/container_service.py (3 hunks)
  • src/zenml/utils/docker_utils.py (6 hunks)
Additional comments: 11
src/zenml/image_builders/local_image_builder.py (1)
  • 110-115: The addition of a try/catch block around DockerClient.from_env() improves error handling by providing a more informative error message when the Docker daemon is not running. This aligns with the PR's objective to enhance user experience by addressing common issues encountered with Docker-based stacks. The implementation correctly catches DockerException and raises a RuntimeError with a clear and actionable error message. This change is a significant improvement in terms of usability and error clarity.
src/zenml/container_registries/base_container_registry.py (1)
  • 146-151: The addition of a try/catch block around DockerClient.from_env() in the docker_client property is well-implemented. It enhances error handling by providing a user-friendly error message when the Docker daemon is not running. This change is consistent with the PR's goal to improve user experience by making error messages more informative and actionable. The implementation correctly catches DockerException and raises a RuntimeError with a clear error message, which is a good practice for error handling in this context.
src/zenml/orchestrators/local_docker/local_docker_orchestrator.py (1)
  • 123-128: The implementation of the try/catch block around DockerClient.from_env() in the prepare_or_run_pipeline function is appropriate and enhances error handling by providing a more informative error message when the Docker daemon is not running. This change aligns with the PR's objective to improve the user experience by making error messages clearer and more actionable. Catching DockerException and raising a RuntimeError with a specific message is a good practice and improves the clarity of errors related to Docker daemon connectivity issues.
src/zenml/service_connectors/docker_service_connector.py (1)
  • 262-267: The addition of a try/catch block around DockerClient.from_env() in the _connect_to_resource method is a positive change that enhances error handling by providing a clearer error message when the Docker daemon is not running. This change is consistent with the PR's goal to improve user experience by making error messages more informative and actionable. The implementation correctly catches DockerException and raises a RuntimeError with a specific message, which is a good practice for error handling in this context.
src/zenml/utils/docker_utils.py (5)
  • 231-236: The addition of try/catch blocks around DockerClient.from_env() calls in the build_image function enhances error handling by providing a more informative error message when the Docker daemon is not running. This change aligns with the PR's objective to improve user experience by making error messages clearer and more actionable. The implementation correctly catches DockerException and raises a RuntimeError with a specific message, which is a good practice for error handling in this context.
  • 268-273: The addition of a try/catch block around DockerClient.from_env() in the push_image function is correctly implemented and enhances error handling by providing a clearer error message when the Docker daemon is not running. This change is consistent with the PR's goal to improve user experience by making error messages more informative and actionable. Catching DockerException and raising a RuntimeError with a specific message is a good practice and improves the clarity of errors related to Docker daemon connectivity issues.
  • 298-303: The implementation of the try/catch block around DockerClient.from_env() in the tag_image function is appropriate and enhances error handling by providing a more informative error message when the Docker daemon is not running. This change aligns with the PR's objective to improve the user experience by making error messages clearer and more actionable. Catching DockerException and raising a RuntimeError with a specific message is a good practice and improves the clarity of errors related to Docker daemon connectivity issues.
  • 318-323: The addition of a try/catch block around DockerClient.from_env() in the get_image_digest function is well-implemented. It enhances error handling by providing a user-friendly error message when the Docker daemon is not running. This change is consistent with the PR's goal to improve user experience by making error messages more informative and actionable. The implementation correctly catches DockerException and raises a RuntimeError with a clear error message, which is a good practice for error handling in this context.
  • 347-352: The implementation of the try/catch block around DockerClient.from_env() in the is_local_image function is appropriate and enhances error handling by providing a more informative error message when the Docker daemon is not running. This change aligns with the PR's objective to improve the user experience by making error messages clearer and more actionable. Catching DockerException and raising a RuntimeError with a specific message is a good practice and improves the clarity of errors related to Docker daemon connectivity issues.
src/zenml/services/container/container_service.py (2)
  • 26-26: The import of DockerException is correctly placed and follows Python's convention of grouping imports from the same library together. This is a good practice as it keeps the import statements organized and readable.
  • 314-316: Refactoring the setting of ENV_ZENML_CONFIG_PATH is done correctly and maintains the readability and maintainability of the code. This change does not directly relate to the handling of DockerException, but it's a good practice to keep environment variable settings clear and concise. No further action is needed here.

src/zenml/services/container/container_service.py Outdated Show resolved Hide resolved
Copy link
Contributor

@avishniakov avishniakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for contributing! I left one suggestion. Also the docstring are impacted now - my suggestion will also simplify resolution for this issue.

src/zenml/utils/docker_utils.py Outdated Show resolved Hide resolved
Copy link
Contributor

@avishniakov avishniakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go, once CI passes

@strickvl strickvl changed the title Feature/trycatchdocker Try/catch for Docker client Mar 18, 2024
@strickvl strickvl merged commit 48799e9 into zenml-io:develop Mar 18, 2024
58 of 59 checks passed
@christianversloot christianversloot deleted the feature/trycatchdocker branch March 18, 2024 16:19
@christianversloot
Copy link
Contributor Author

christianversloot commented Mar 18, 2024

thanks for merging @strickvl & reviews @avishniakov !

adtygan pushed a commit to adtygan/zenml that referenced this pull request Mar 21, 2024
* update TOC (zenml-io#2406)

* Add try/except to DockerClient from env

* Move generation of Docker client from environment to separate utility function

---------

Co-authored-by: Alex Strick van Linschoten <strickvl@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request run-slow-ci
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants