[wanda] refactor docker_cmd to be container_cmd#329
[wanda] refactor docker_cmd to be container_cmd#329andrew-anyscale wants to merge 2 commits intomainfrom
Conversation
Refactoring common interface into container_cmd so we can use podman or whatever backends we like. Subsequent PR will add podman_cmd once the interface looks clean Topic: refactor-for-podman Signed-off-by: andrew <andrew@anyscale.com>
Summary of ChangesHello @andrew-anyscale, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant refactoring to abstract the underlying container runtime commands. By creating a generic Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a solid step towards abstracting the container runtime by introducing a ContainerCmd interface and a baseContainerCmd. This will make it easier to add support for other runtimes like Podman in the future. The changes are well-structured, and new tests have been added to cover the new interface.
My review includes a few suggestions to improve the new abstraction:
- I've pointed out a significant code duplication in the
buildmethod betweendockerCmdandbaseContainerCmdthat should be addressed to improve maintainability. - There's an inconsistency in how container command instances are created within the
Buildmethod, which could lead to state issues. - I also noticed some Docker-specific logic in the generic
baseContainerCmdthat should be moved to thedockerCmdimplementation to keep the base class truly generic.
Addressing these points will make the abstraction cleaner and more robust.
| } | ||
|
|
||
| // build overrides baseContainerCmd.build to add --progress=plain for BuildKit. | ||
| func (c *dockerCmd) build(in *buildInput, core *buildInputCore, hints *buildInputHints) error { |
There was a problem hiding this comment.
The build method in dockerCmd is almost a complete copy of the build method in baseContainerCmd. This creates significant code duplication. The main difference is adding the --progress=plain flag.
Consider refactoring to eliminate this duplication. One approach is to make baseContainerCmd.build more extensible. For instance, you could have dockerCmd.build prepare Docker-specific arguments and then call a common, unexported function from baseContainerCmd that contains the shared build logic.
This would make the code more maintainable and align better with the goal of this refactoring.
| if exitErr, ok := err.(*exec.ExitError); ok { | ||
| // Docker returns 1 | ||
| code := exitErr.ExitCode() | ||
| if code == 1 { | ||
| return nil, nil | ||
| } | ||
| } |
There was a problem hiding this comment.
This error handling logic is specific to the Docker CLI, which returns exit code 1 when an image is not found. Placing this in baseContainerCmd leaks implementation details of one container runtime into the generic base class. Other runtimes like Podman might behave differently.
To keep baseContainerCmd generic, this Docker-specific logic should be moved to dockerCmd. One way to do this is for dockerCmd to override inspectImage, run the command itself, and handle the exit code. While this might introduce some duplication, it would correctly encapsulate the runtime-specific behavior.
| var newCmd ContainerCmd | ||
| if f.config.ContainerRuntime == RuntimeDocker { | ||
| // Always use a new dockerCmd so that it can run in its own environment. | ||
| newCmd = f.config.newContainerCmd() | ||
| } else { | ||
| newCmd = f.containerCmd | ||
| } |
There was a problem hiding this comment.
The logic for creating a ContainerCmd instance is inconsistent. For RuntimeDocker, a new command instance is created for each build, but for other runtimes, the existing f.containerCmd instance is reused.
The comment on line 249 suggests creating a new instance is desirable to ensure a clean environment. If that's the case, this should be done for all container runtimes to prevent potential state-related bugs (e.g., from a modified workDir).
I suggest always creating a new command instance for each build, regardless of the runtime.
// Now we can build the image.
// Always use a new containerCmd so that it can run in its own environment.
newCmd := f.config.newContainerCmd()Topic: refactor-for-podman Signed-off-by: andrew <andrew@anyscale.com>
Code Review
|
| Auto-apply | ✅ Code review | Compact |
|
|
|
Was this helpful? React with 👍 / 👎 | This comment will update automatically (Docs)
aslonnie
left a comment
There was a problem hiding this comment.
before we commit to this, could you show a proof of concept that it can build ray wheels and images without docker? on both buildkite or within a ray image?
docker daemon is builtin supported on buildkite AMI, but podman is not.
one concern is that only some more recent versions of podman supports multi-line HEREDOC command syntax, which we uses in ray wheels and image building. I am also not sure about the multi-stage support.
Totally agree! Goal of this PR was to refactor to make room for other potential backends. Be that podman, or another appropriate fit should podman not be it
I'm dogfooding the podman implementation now, and just started running into this for the HEREDOC command syntax. I'm planning to check out other backends as well to see if any fit better |
Refactoring common interface into container_cmd so we can
use podman or whatever backends we like.
Subsequent PR will add podman_cmd once the interface looks
clean
Topic: refactor-for-podman
Signed-off-by: andrew andrew@anyscale.com