-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Set initial timestamp to the time the image was created #73
Conversation
Thanks so much for contributing! I'll take a look soon. A small tip: I see you have a small lint error. If you have Toast installed, you can run |
Previously, when docuum first starts, it would set the timestamp of every image to the time docuum started, meaning old images would be removed at random. Now, we use the time the image was created as the initial timestamp (which is of course updated when that image is used like normal).
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 looking really good. I left some minor comments. The most important feedback is to avoid unwrap
as much as possible, unless we can be absolutely sure that it's safe (with justification provided in comments). If there is even the remotest possibility that an unwrap
will panic
, we should return an error instead so the caller can decide what to do.
toast.yml
Outdated
@@ -94,7 +94,7 @@ tasks: | |||
. $HOME/.cargo/env | |||
cargo clippy --all-targets --all-features -- \ | |||
--deny warnings --deny clippy::all --deny clippy::pedantic | |||
cargo fmt --all -- --check | |||
cargo fmt --all -- --check || echo "ERROR: Please correct the formatting errors above" |
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.
Is this because it was difficult to understand the output? I wonder if we should do this for all the lint checks (or none of them).
Either way, a few minor suggestions:
echo
to standard error rather than standard out (e.g.,echo '...' 1>&2
)- Punctuate the sentence.
- Use single quotes unless we need the interpolation capability of double quotes. I know this is nitpicky, but I find that this practice avoids mistakes in which Bash interprets some part of the string that you didn't intend it to (though here I think it's inconsequential).
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.
Yes, when cargo fmt
fails, it just prints adiff
and I didn't know why or even what command was triggering that.
Whereas clippy
has some explanation like error: unneeded return statement
, so I knew how to address that.
This is probably the highest quality code review I've ever received, thanks @stepchowfun! I'll get started on addressing these comments |
Still trying to find time to pick another fight with the Rust compiler to address these changes. If it turns out #75 is done and ready to be merged before this PR, just letting you know I'd be okay with fixing the resulting merge conflicts if need-be 👍 |
I resolved the comments I think I've addressed, feel free to re-comment since everything's shifted around now. Mainly did the following:
|
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 looking good to me. Would you mind rebasing now that the other PR has been merged? (Thanks for offering to do that.)
So @stepchowfun do you have a preference on what to do with this PR now that #75 was reverted? If there's a quick path to getting Bollard back in, we could just leave this PR until that point. |
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.
@mac-chaffee If I understand the situation correctly, I don't think we'll be able to bring back Bollard any time soon. If it's a bug in Docker, I guess we just need to wait for all the affected Docker versions (which includes the latest current version) to fall out of use?
I left some comments on the current version of the PR, but unfortunately I think we'll have to go back to the old way (parsing the output of the Docker CLI) so my comments might be pointless. I'm sorry you had to rebase your PR only to find out that we have to revert back to the old strategy after all. That's a big bummer!
Let me know if you are able to recover your old commits to restore the PR to how it was before the rebasing. I think it was essentially ready to ship, or at least close to it.
src/run.rs
Outdated
@@ -36,7 +36,7 @@ pub async fn image_id(docker: &Docker, image: &str) -> io::Result<String> { | |||
} | |||
|
|||
// Ask Docker for the IDs of all the images. | |||
pub async fn image_ids(docker: &Docker) -> io::Result<HashSet<String>> { | |||
pub async fn image_ids(docker: &Docker) -> io::Result<HashMap<String, Duration>> { |
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.
What do you think about renaming this function to image_ids_and_creation_timestamps
? It's kind of verbose, but the current name feels incomplete now.
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.
(If this suggestion resonates with you, we can also rename the image_ids
variable defined on line 169 accordingly.)
src/run.rs
Outdated
Ok(output.into_iter().map(|image| image.id).collect()) | ||
for image in output { | ||
match image.created.try_into() { | ||
Ok(unsigned) => images.insert(image.id, Duration::from_secs(unsigned)), |
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 totally subjective, but I think the unsigned
variable could have a better name. Maybe created
to match the name of where it comes from? (I'm not super fond of created
, but consistency is more important than my personal preferences.)
src/run.rs
Outdated
for image in output { | ||
match image.created.try_into() { | ||
Ok(unsigned) => images.insert(image.id, Duration::from_secs(unsigned)), | ||
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)) |
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.
Elsewhere in this file we use the name error
rather than e
when pattern matching on an Err
. Can we do that here too? (Alternatively we could change all the other ones. I don't feel strongly about it, as long as we're consistent.)
We shouldn't need to wait that long. The docker team changed the documentation to match the current behavior so we just need Bollard to pick that up. |
@mdonoughe Oh so there is no behavior change on Docker's side? That's kind of unfortunate, because the behavior is weirdly inconsistent (integer vs. timestamp string) depending on whether BuildKit is enabled, right? Should Bollard have to deal with that? |
When you're using BuildKit there's an extra section specifically about BuildKit cache data and that's where the problem is. |
Ah, that makes sense. Thank you for clarifying! In that case, I think this can go either way: wait for the Bollard upstream fix (do they know about the issue?), bring back @mdonoughe's change, and then land this PR, or alternatively restore this PR to how it was before Bollard, land it, and then land the Bollard change separately when the time is right. Either way is fine with me, but I imagine it could be faster to update this PR and land it rather than waiting on Bollard. Fortunately, neither of these changes has any timeline requirement on my end, so it's up to y'all to decide how you'd like to proceed. |
I created fussybeaver/bollard#89 earlier today. |
Did some (surprisingly easy) |
Nice! Looks good. |
Previously, when docuum first starts, it would set the timestamp of every image to the time docuum started, meaning old images would be removed at random. Now, we use the time the image was created as the initial timestamp (which is of course updated when that image is used like normal).
Example running locally (with comments added to show the original CreatedAt dates):
Also this is my first foray into Rust, so please let me know if there are any best-practices I should be following, particularly around error handling 👍
Status: Ready
Fixes: #71