-
Notifications
You must be signed in to change notification settings - Fork 241
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
Clean up docker containers by default #3629
Conversation
…move=True` (even if "docker run" fails)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some small complaints, but mostly I'm now suspicious of the whole deferParam
system. I think we need to at least re-document it so it makes sense along with the remove
flag. As is it's not clear what all the combinations are supposed to do.
A much simpler fix for #3505 might be possible: I don't think the documented default deferParam
behavior of RM
has been working, which would account for all the left-behind containers from toil-vg.
Do we have any unit tests for the cleanup here? If not, the first step should really be to add some. Then we can be certain of what the combinations of parameters are meant to do, because they will be tested.
src/toil/lib/docker.py
Outdated
with open(streamfile, 'w') as f: | ||
f.write(line) | ||
for line in container.logs(stdout=stdout, stderr=stderr, stream=True): | ||
f.write(line.decode() if isinstance(line, bytes) else line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to raise an error in Toil if a container happens to be sending non-UTF8 data; we often stream binary files in and out of Docker containers in toil-vg. We ought to just pass the bytes along here in binary mode.
@@ -356,27 +362,29 @@ def dockerKill(container_name, gentleKill=False, timeout=365 * 24 * 60 * 60): | |||
raise create_api_error_from_http_exception(e) | |||
|
|||
|
|||
def dockerStop(container_name): | |||
def dockerStop(container_name: str, remove: bool = True) -> None: | |||
""" | |||
Gracefully kills a container. Equivalent to "docker stop": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be the right way to explain this anymore, since now by default we do more than "docker stop".
Maybe drop the link to the Docker docs and say that this gracefully kills and removes a container?
src/toil/lib/docker.py
Outdated
:param container_name: Name of the container being stopped. | ||
:param client: The docker API client object to call. | ||
:param remove: If True, remove the container after it exits. (default: True). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be a keep
flag everywhere instead of a default-true remove
flag? Having flags that are default-true and having to say they =False
takes up more brain space than the other way around. Plus, when we document them like this, by saying what happens when they're true, then when you actually go to use them (by setting them to false), you have to invert the sense of the documentation to figure out what you are accomplishing by using the flag, which takes more brain space.
def dockerKill(container_name: str, | ||
gentleKill: bool = False, | ||
remove: bool = True, | ||
timeout: int = 365 * 24 * 60 * 60) -> None: | ||
""" | ||
Immediately kills a container. Equivalent to "docker kill": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be the best way to describe this method if it now has a different default behavior than docker kill
.
@w-gao I've added a bunch of complaints here, but I don't think it would make sense to go through and address all of them. I think we want to do one of:
|
Thanks @adamnovak for the review! I'm leaning towards fixing the default As for unit tests, we actually have these here that test the different combinations of options. Although, I don't think they are tested on the CI. I'll look into the tests and see if the default |
It does look like the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely simpler now, and I think it should work. @w-gao Are you still adding tests?
Yeah @adamnovak, I'm trying to make sure all combinations work as intended, so this is not quite ready yet. |
882a489
to
e14e9fd
Compare
@adamnovak This should be ready now! I changed a few things since your last review, so this may need a re-review. For some reason the file permission check doesn't pass on the CI, but works fine locally. I'll take a deeper look into that but that's probably a different issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this.
I think the file permission test fails because we actually are running as root on CI, whereas the test expects us to be running as someone other than root, who it expects to see owning the relevant files. |
Make sure Toil removes the docker containers after they are finished running, so we don't have a bunch of "Exited" Docker containers.
Closes #3505.
Changelog Entry
To be copied to the draft changelog by merger:
remove=False
inapiDockerCall()
to leave the containers untouched and running.Reviewer Checklist
issues/XXXX-fix-the-thing
in the Toil repo, or from an external repo.camelCase
that want to be insnake_case
.docs/running/cliOptions.rst
Merger Checklist