copy: Add text-based progress output for non-TTY environments#1
Open
copy: Add text-based progress output for non-TTY environments#1
Conversation
7c68cfa to
89c1f7b
Compare
When copying images in non-TTY environments (CI/CD pipelines, redirected
output, piped commands), the visual mpb progress bars are discarded,
leaving users with no visibility into transfer progress. This makes it
difficult to detect stalled transfers or monitor long-running copies.
This change adds a nonTTYProgressWriter that consumes progress events
from the existing Progress channel and prints periodic aggregate progress
lines suitable for log output:
Progress: 13.1 MiB / 52.3 MiB
Progress: 26.2 MiB / 52.3 MiB
Progress: 52.3 MiB / 52.3 MiB
The feature is enabled when, output is not a TTY, we check if option.Progress is set,
otherwise create a new buffered channel for progress events.
Note: Unbuffered channels are replaced with buffered ones to prevent
blocking during parallel blob downloads. Callers who need custom
consumption should provide a properly buffered channel.
Relates-to: containers/skopeo#658
Signed-off-by: Oleksandr Shestopal <ar.shestopal-oshegithub@gmail.com>
89c1f7b to
00a1e73
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates-to: containers/skopeo#658
Problem
When copying images in non-TTY environments (CI/CD pipelines, redirected output, piped commands), the visual mpb progress bars are discarded via
io.Discard, leaving users with no visibility into transfer progress. This makes it difficult to:Currently, only a single "Copying blob..." message is printed via
printCopyInfo()when non-TTY, with no subsequent progress updates.Solution
This change automatically enables text-based progress output for non-TTY environments by leveraging the existing
Options.Progresschannel mechanism.Design decisions
Automatic for non-TTY: When output is not a TTY and the caller hasn't already provided a buffered Progress channel, we automatically set up text-based progress output. No opt-in flag needed.
Aggregate progress instead of per-blob: Rather than printing a line for each blob (which would be verbose for multi-layer images), we track total bytes across all blobs and print a single aggregate progress line. This keeps CI logs clean while still providing visibility.
Reuse existing Progress channel: The
progressReaderinblob.goalready sendsProgressEventNewArtifact,ProgressEventRead, andProgressEventDoneevents. We simply consume these events and format them as text output.Buffered channel: We create a buffered channel to prevent blocking senders during parallel blob downloads. Callers who need custom consumption should provide a properly buffered channel.
Sensible interval defaults: If
ProgressIntervalis not set, we default to 500ms. If the caller sets a larger interval, we respect that. The interval is clamped to a minimum of 500ms to prevent log spam.Output example
Files changed
copy/progress_nontty.go- New file withnonTTYProgressWriterimplementationcopy/copy.go- Initialize text progress writer in non-TTY modeTesting
Build and unit tests:
Manual testing with skopeo (pipe to cat to force non-TTY):
Output may be shorter, if ProgressInterval is set longer.
Signed-off-by: Oleksandr Shestopal ar.shestopal@gmail.com