-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add spinner loading to docker cp command #2708
Add spinner loading to docker cp command #2708
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2708 +/- ##
==========================================
- Coverage 58.42% 57.10% -1.33%
==========================================
Files 295 297 +2
Lines 21201 18690 -2511
==========================================
- Hits 12387 10672 -1715
+ Misses 7906 7153 -753
+ Partials 908 865 -43 |
Hello @maximillianfx, thank you for opening this PR, but can I ask what is the rational behind adding a spinner to this command? I guess the issue is that you don't really know what's going on and the command looks blocked (like if you cp a large file to a remote engine)? |
Hi @silvin-lubecki, how are you? Thanks for the quick help! Yeah, the reason for the spinner is to show to user a little animation/progression about the command, but I understand that this have some UI restrictions. Your idea about a progress bar looks great and achieve the same (or even better) goal. Can I adjust this PR to this new approach? |
cc @thaJeztah any thoughts? |
Chatted with @silvin-lubecki and I agree that printing the amount of data that we copied would be more informative than just a spinner. We weren't sure if it's possible to know up-front how much data will be copied (in case you're copying a directory structure, the API will probably not return the total size?), so if we don't know the total, a progress-bar won't make much sense; in that case, only printing the amount to data that was copied ( |
Yes, I understand, the directory scenario shows exactly the problem when displaying the amount of data that will be copied. Therefore, displaying a simple message after the copying process seems more effective. I will make these changes to this PR and we can return to the discussion soon. |
Hey guys. I was working in this item yesterday, and I faced the func getCopySize(data io.ReadCloser) (int, io.Reader) {
content, err := ioutil.ReadAll(data.Body)
if err != nil {
fmt.Println(err)
}
return len(content), bytes.NewReader(content)
} In my tests, the file size is 6 bytes, but |
I made a mistake, the file is transformed to a Tar file. So, I'll made the size evaluation before this transformation. |
Alright @silvin-lubecki @thaJeztah ! Can you run these changes and give me some feedback? |
Hello @maximillianfx, thanks for the update! But I think there's an issue with your last rebase, the PR now includes all the last commits from master, so it's pretty hard to follow which are your commits/modifications 😅 Could you rebase properly your commits? 🙏 |
Yes, I'll update this. |
@silvin-lubecki the current rebase is wrong? Because, I made the rebase to put my commits in front of the last commits of master, this is wrong? Can you help with the correct rebase? |
Ok I reviewed the code using master...maximillianfx:2564-add-spinner-loading |
Thanks for reviewing. I don't know, because the |
I guess that if you are targeting a remote daemon the |
Yes, this scenario could occur. I'll investigate. |
Hi @silvin-lubecki how are you? The behavior of these dynamically copying should be implemented on the engine project itself, WDYT? Because, looking into the |
Removing myself as a reviewer because completion is not touched by this PR. |
Hello @maximillianfx, I think that if you replace the |
Could be a solution, but this will affect only the copy from container and not to container, isn't it? |
@silvin-lubecki did you manage to check my last question? |
Sorry @maximillianfx I missed your question, thank you for the ping 😅 |
Yeah, this looks great @silvin-lubecki. I'll read more about this, and make the changes 😄 |
Codecov Report
@@ Coverage Diff @@
## master #2708 +/- ##
==========================================
- Coverage 58.42% 57.10% -1.33%
==========================================
Files 295 297 +2
Lines 21201 18690 -2511
==========================================
- Hits 12387 10672 -1715
+ Misses 7906 7153 -753
+ Partials 908 865 -43 |
Codecov Report
@@ Coverage Diff @@
## master #2708 +/- ##
==========================================
- Coverage 58.42% 57.15% -1.28%
==========================================
Files 295 297 +2
Lines 21201 18721 -2480
==========================================
- Hits 12387 10700 -1687
+ Misses 7906 7157 -749
+ Partials 908 864 -44 |
Codecov Report
@@ Coverage Diff @@
## master #2708 +/- ##
==========================================
- Coverage 58.42% 56.89% -1.54%
==========================================
Files 295 295
Lines 21201 18534 -2667
==========================================
- Hits 12387 10544 -1843
+ Misses 7906 7129 -777
+ Partials 908 861 -47 |
I have made some changes. Added a little progress bar to indicate the copy process. Both copies, from and into container, are working. I have made this because only displaying the amount of bytes transfered could be unreadable 😕. WDYT @silvin-lubecki ? |
I opened maximillianfx#1 on your fork 👍 |
Thanks @thaJeztah ! Your comments are very hepful and necessary. Your PR is welcome 😄 |
You're welcome! Be sure to check my changes with the control-codes, because I'm horrible at those 😂 |
Of course, thanks! |
@thaJeztah Some problems arose, I'll made more tests. |
I think that's ok now, PTAL @thaJeztah 😄 |
Hi @thaJeztah , how are you? Could you review again? |
Ah, welp.. this one slipped off my radar again 😬. Let me have another look. Before merging, we should squash the commits (let me have a quick look at doing a rebase and squash) |
I rebased (will push in a minute); and found some last small things, which I added in an extra commit (but will squash);
Here's a before/after: before.movafter.mov |
Co-authored-by: Sebastiaan van Stijn <[email protected]> Signed-off-by: Maximillian Fan Xavier <[email protected]>
b4ade48
to
12370ad
Compare
Codecov Report
@@ Coverage Diff @@
## master #2708 +/- ##
==========================================
- Coverage 57.08% 56.83% -0.25%
==========================================
Files 299 295 -4
Lines 18689 18544 -145
==========================================
- Hits 10668 10540 -128
+ Misses 7155 7145 -10
+ Partials 866 859 -7 |
Pushed the squashed and rebased version; also squashed my last changes; diff below for posterity; From c5e7af600e90b1793c789219773cdbf6ed1948a1 Mon Sep 17 00:00:00 2001
From: Sebastiaan van Stijn <[email protected]>
Date: Sat, 24 Apr 2021 13:14:13 +0200
Subject: [PATCH] Some small fix-ups / improvements
1. Remove the "progress" line after copy is complete
After copying, the "progress" line was kept:
docker cp foo:/usr/share/nginx bla
Preparing to copy...
docker cp foo:/usr/share/nginx bla
Copying from container - 512B
docker cp foo:/usr/share/nginx bla
Copying from container - 4.608kB
Successfully copied 4.608kB to /go/src/github.com/docker/cli/bla
The "Copying from container" line is a bit redundant after it's completed, so
removing the line afterwards:
docker cp foo:/usr/share/nginx bla
Preparing to copy...
docker cp foo:/usr/share/nginx bla
Copying from container - 512B
docker cp foo:/usr/share/nginx bla
Successfully copied 4.608kB to /go/src/github.com/docker/cli/bla
2. Print progress lines with a trailing newline
Without a newline, the cursor would be visible at the end of the progress
line, which was a bit distracting, as it would be jumping if the progress
line was not the same width for each refresh.
3. Swapped `fmt.Fprint` for `fmt.Fprintln` in some places
Same result, just prevents having to add `\n` in the strings, and it automatically
joins arguments with a space in between, so a slight bit cleaner.
Signed-off-by: Sebastiaan van Stijn <[email protected]>
---
cli/command/container/cp.go | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/cli/command/container/cp.go b/cli/command/container/cp.go
index 071becf94b..01940d5616 100644
--- a/cli/command/container/cp.go
+++ b/cli/command/container/cp.go
@@ -61,9 +61,9 @@ func (pt *copyProgressPrinter) Read(p []byte) (int, error) {
fmt.Fprint(pt.writer, aec.Restore)
fmt.Fprint(pt.writer, aec.EraseLine(aec.EraseModes.All))
if pt.toContainer {
- fmt.Fprint(pt.writer, "Copying to container - "+units.HumanSize(*pt.total))
+ fmt.Fprintln(pt.writer, "Copying to container - "+units.HumanSize(*pt.total))
} else {
- fmt.Fprint(pt.writer, "Copying from container - "+units.HumanSize(*pt.total))
+ fmt.Fprintln(pt.writer, "Copying from container - "+units.HumanSize(*pt.total))
}
}
@@ -229,10 +229,11 @@ func copyFromContainer(ctx context.Context, dockerCli command.Cli, copyConfig cp
}
fmt.Fprint(dockerCli.Err(), aec.Save)
- fmt.Fprint(dockerCli.Err(), "Preparing to copy...\n")
+ fmt.Fprintln(dockerCli.Err(), "Preparing to copy...")
res := archive.CopyTo(preArchive, srcInfo, dstPath)
- fmt.Fprint(dockerCli.Err(), "\n")
- fmt.Fprint(dockerCli.Err(), "Successfully copied ", units.HumanSize(copiedSize), " to ", dstPath, "\n")
+ fmt.Fprint(dockerCli.Err(), aec.Restore)
+ fmt.Fprint(dockerCli.Err(), aec.EraseLine(aec.EraseModes.All))
+ fmt.Fprintln(dockerCli.Err(), "Successfully copied", units.HumanSize(copiedSize), "to", dstPath)
return res
}
@@ -351,10 +352,11 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
}
fmt.Fprint(dockerCli.Err(), aec.Save)
- fmt.Fprint(dockerCli.Err(), "Preparing to copy...\n")
+ fmt.Fprintln(dockerCli.Err(), "Preparing to copy...")
res := client.CopyToContainer(ctx, copyConfig.container, resolvedDstPath, content, options)
- fmt.Fprint(dockerCli.Err(), "\n")
- fmt.Fprint(dockerCli.Err(), "Successfully copied ", units.HumanSize(copiedSize), " to ", copyConfig.container, ":", dstInfo.Path, "\n")
+ fmt.Fprint(dockerCli.Err(), aec.Restore)
+ fmt.Fprint(dockerCli.Err(), aec.EraseLine(aec.EraseModes.All))
+ fmt.Fprintln(dockerCli.Err(), "Successfully copied", units.HumanSize(copiedSize), "to", copyConfig.container+":"+dstInfo.Path)
return res
} |
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.
LGTM, thanks!!!
@silvin-lubecki @cpuguy83 PTAL |
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.
LGTM
Thanks a lot @maximillianfx for this awesome work 👍 |
Thank you guys! |
`container cp` docker/cli#2708 `container create/run` docker/cli#3377
`container cp` docker/cli#2708 `container create/run` docker/cli#3377
May I ask what the rationale behind suddenly adding output to a previously silent command is? This didn't really break anything for me, but it's instead just very annoying, because What's obviously not shown in the screenshot are the thousands of other lines that the command now prints. Therefore, why not just add this kind of behaviour through a Edit: Phrasing. |
This seems very annoying and doesn't appear to be expected behavior. |
- What I did
When a user executes
docker cp
command, aCopying
message is showed on terminal and a spinner is printed out together, with a small animation.- How I did it
Add animation using a channel and an array of characters to simulate a spinner in cp.go.
- How to verify it
Run the environment container with
make -f docker.Makefile shell
, then run the command./build/docker-linux-amd64 cp file container:path
to see.- Description for the changelog
Addition of animated spinner when copying files using the docker cp command
- A picture of a cute animal (not mandatory but encouraged)
closes #2564
closes #1281