Skip to content
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

feat: support progress output for attach, push and copy commands #1138

Merged
merged 127 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
b088f2b
feat: support progressed output in blob push and blob get
qweeah Sep 12, 2023
e773471
add error when --debug is used with terminal output
qweeah Sep 19, 2023
6044594
bug fix
qweeah Sep 19, 2023
b5d89dd
Merge branch 'main' into progress-bar-reader
qweeah Sep 20, 2023
6324b93
add test for console
qweeah Sep 20, 2023
f1077bd
fix lint & pass tty to manager
qweeah Sep 20, 2023
4c362f8
Merge branch 'main' into progress-bar-reader
qweeah Sep 20, 2023
941188f
rename flag to disable tty
qweeah Sep 20, 2023
c72ebe5
add test for blob push
qweeah Sep 21, 2023
5fc75a8
fix render racing
qweeah Sep 21, 2023
a2d3f8c
fix race
qweeah Sep 21, 2023
4a065fe
add test for `blob fetch`
qweeah Sep 21, 2023
00ca2fc
resolve comment
qweeah Sep 22, 2023
c85e809
resolve comment
qweeah Sep 22, 2023
997a63e
resolve comment
qweeah Sep 22, 2023
144e907
fix lint
qweeah Sep 22, 2023
1b1f23c
refactor spinner mark
qweeah Sep 22, 2023
008a61d
refactor: improve manager and status
qweeah Sep 25, 2023
95ad473
add error for manager functions
qweeah Sep 25, 2023
ed84a69
remove unnecessary lock
qweeah Sep 25, 2023
47ef494
update reader naming
qweeah Sep 25, 2023
7e249ed
remove reader.once
qweeah Sep 25, 2023
ca19602
Merge remote-tracking branch 'origin_src/main' into progress-bar-reader
qweeah Sep 25, 2023
a6476d4
ignore returned error of manager
qweeah Sep 25, 2023
8c7458b
code clean
qweeah Sep 25, 2023
1584fd2
resolve comment
qweeah Sep 28, 2023
8fef80b
Merge remote-tracking branch 'origin_src/main' into progress-bar-reader
qweeah Sep 28, 2023
b44e2e8
code clean
qweeah Sep 28, 2023
ea6476f
code clean
qweeah Sep 28, 2023
b06383c
feat: support progress bar for `oras cp`
qweeah Sep 28, 2023
720c6e6
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Sep 28, 2023
ebcc114
Merge remote-tracking branch 'origin_src/main' into progress-bar-reader
qweeah Oct 7, 2023
ad0608d
add test for spinner
qweeah Oct 7, 2023
1aab8bd
add cross-package coverage generation
qweeah Oct 7, 2023
78b0d42
Refactor tests
qweeah Oct 7, 2023
2b13d6a
cover common tests
qweeah Oct 7, 2023
6bf4f3d
add status coverage
qweeah Oct 7, 2023
a7f3f96
code clean
qweeah Oct 7, 2023
cfc7a9b
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 7, 2023
5183dc9
add doc for stdout
qweeah Oct 7, 2023
1f45188
add status tests
qweeah Oct 7, 2023
7133edd
resolve comment
qweeah Oct 7, 2023
3ad8eaa
add doc for stdout
qweeah Oct 7, 2023
243dc37
add status tests
qweeah Oct 7, 2023
5f5a1d9
resolve comment
qweeah Oct 7, 2023
7554534
NIT
qweeah Oct 7, 2023
76de650
align timing and percentage
qweeah Oct 7, 2023
51ab043
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 7, 2023
486a8ed
fix unit test
qweeah Oct 7, 2023
5b24511
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 7, 2023
39b0247
Merge remote-tracking branch 'origin_src/main' into progress-bar-reader
qweeah Oct 7, 2023
4fe990e
increase coverage
qweeah Oct 7, 2023
3a7ed21
fix: won't show complete when aborted
qweeah Oct 8, 2023
e916c17
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 8, 2023
455ca08
fix: won't show complete when aborted
qweeah Oct 8, 2023
ff2c230
code clean
qweeah Oct 8, 2023
9426fac
code clean
qweeah Oct 8, 2023
50c4181
code clean
qweeah Oct 8, 2023
aa5b847
code clean
qweeah Oct 8, 2023
f49bdcb
align units of processed data to total size
qweeah Oct 8, 2023
1b774e0
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 8, 2023
8bc5c37
add instant download speed
qweeah Oct 8, 2023
5ed9251
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 8, 2023
e1486cc
remove unnecessary file
qweeah Oct 8, 2023
3193b48
code clean
qweeah Oct 8, 2023
a46c218
code clean
qweeah Oct 8, 2023
151ad0a
lint
qweeah Oct 8, 2023
7327022
code clean
qweeah Oct 9, 2023
1abda95
change base for sizing
qweeah Oct 9, 2023
636f424
fix speed display
qweeah Oct 9, 2023
2ea395d
add test coverage
qweeah Oct 9, 2023
d7276cb
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 9, 2023
feb73b4
add test for copying
qweeah Oct 9, 2023
4f7ac01
bug fix
qweeah Oct 9, 2023
25c155a
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 9, 2023
cfdfe46
code clean
qweeah Oct 9, 2023
8c71709
feat: support progress output in attach and push
qweeah Oct 9, 2023
b9c5bec
fix nil pointer
qweeah Oct 9, 2023
c47f967
reset render interval to 200ms
qweeah Oct 9, 2023
2489a61
turn humanize into package
qweeah Oct 10, 2023
9e7daec
bug fix
qweeah Oct 10, 2023
c4564fe
rename pts device
qweeah Oct 10, 2023
167adb1
Merge remote-tracking branch 'origin_src/main' into progress-bar-reader
qweeah Oct 10, 2023
6c324d1
reduce buffer size
qweeah Oct 10, 2023
d4298c1
fix typo
qweeah Oct 10, 2023
67574dd
change switch to if-else
qweeah Oct 10, 2023
25d8935
bug fix
qweeah Oct 10, 2023
c76c464
change switch to if-else
qweeah Oct 10, 2023
9403cca
revert rendering
qweeah Oct 10, 2023
8a1f088
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 10, 2023
0741396
reduce buffer size to 1
qweeah Oct 10, 2023
2439121
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 11, 2023
85d8514
Merge branch 'progress-bar-cp' into progress-bar-push-attach
qweeah Oct 11, 2023
8d6c017
fix: enable pipe when output to stdout
qweeah Oct 11, 2023
c5ab1ee
fix: enable pipe when output to stdout
qweeah Oct 11, 2023
360a5ea
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 11, 2023
6611186
fix display bug
qweeah Oct 11, 2023
c4fae1f
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 11, 2023
e858d1a
revert change
qweeah Oct 11, 2023
8692963
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 11, 2023
49818cf
Merge branch 'progress-bar-cp' into progress-bar-push-attach
qweeah Oct 11, 2023
e4d4439
fix bug
qweeah Oct 11, 2023
6f2de09
Merge branch 'progress-bar-reader' into progress-bar-cp
qweeah Oct 11, 2023
b01433d
Merge branch 'progress-bar-cp' into progress-bar-push-attach
qweeah Oct 11, 2023
7c7510f
add skipped status
qweeah Oct 13, 2023
e26cf77
Merge remote-tracking branch 'origin_src/main' into progress-bar-push…
qweeah Oct 13, 2023
eba5761
fix merging
qweeah Oct 13, 2023
6a97757
fix pushing
qweeah Oct 13, 2023
1a4c490
fix cp
qweeah Oct 13, 2023
a4b0379
Merge branch 'main' into progress-bar-push-attach
qweeah Oct 16, 2023
781874f
resolve comment
qweeah Oct 17, 2023
0dd031a
change target to graph target
qweeah Oct 17, 2023
d2c8f16
resolve comment
qweeah Oct 17, 2023
0de9997
remove printStatus output target.Prompt
qweeah Oct 17, 2023
e0f810a
fix attach
qweeah Oct 17, 2023
060940b
refactor target
qweeah Oct 17, 2023
692fd31
resolve comment
qweeah Oct 17, 2023
8a52cc9
doc clean
qweeah Oct 17, 2023
1ccb8d1
Merge remote-tracking branch 'origin_src/main' into progress-bar-push…
qweeah Oct 18, 2023
826872f
resolve comment
qweeah Oct 19, 2023
26cb0b7
resolve comment for push
qweeah Oct 19, 2023
d648b94
resolve comment
qweeah Oct 19, 2023
f6ab85d
remove unnecessary code
qweeah Oct 19, 2023
4841c1c
resolve comments
qweeah Oct 23, 2023
f30a5d5
remove unused code
qweeah Oct 23, 2023
0406738
merge declaration
qweeah Oct 23, 2023
4e8d585
Merge remote-tracking branch 'origin_src/main' into progress-bar-push…
qweeah Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/oras/internal/display/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (

var printLock sync.Mutex

type printFunc func(ocispec.Descriptor) error
// PrintFunc is the function type returned by StatusPrinter.
type PrintFunc func(ocispec.Descriptor) error
qweeah marked this conversation as resolved.
Show resolved Hide resolved

// Print objects to display concurrent-safely
// Print objects to display concurrent-safely.
func Print(a ...any) error {
printLock.Lock()
defer printLock.Unlock()
Expand All @@ -40,7 +41,7 @@ func Print(a ...any) error {
}

// StatusPrinter returns a tracking function for transfer status.
func StatusPrinter(status string, verbose bool) printFunc {
func StatusPrinter(status string, verbose bool) PrintFunc {
return func(desc ocispec.Descriptor) error {
return PrintStatus(desc, status, verbose)
}
Expand All @@ -60,7 +61,7 @@ func PrintStatus(desc ocispec.Descriptor, status string, verbose bool) error {
}

// PrintSuccessorStatus prints transfer status of successors.
func PrintSuccessorStatus(ctx context.Context, desc ocispec.Descriptor, fetcher content.Fetcher, committed *sync.Map, print printFunc) error {
func PrintSuccessorStatus(ctx context.Context, desc ocispec.Descriptor, fetcher content.Fetcher, committed *sync.Map, print PrintFunc) error {
successors, err := content.Successors(ctx, fetcher, desc)
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions cmd/oras/internal/display/track/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package track

import (
"context"
"errors"
"io"
"os"

Expand Down Expand Up @@ -104,10 +103,6 @@ func (t *graphTarget) Close() error {

// Prompt prompts the user with the provided prompt and descriptor.
func (t *graphTarget) Prompt(desc ocispec.Descriptor, prompt string, verbose bool) error {
if t == nil {
// this should not happen
return errors.New("cannot output progress with nil tracked target")
}
status, err := t.manager.Add()
if err != nil {
return err
Expand Down
28 changes: 15 additions & 13 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func runCopy(ctx context.Context, opts copyOptions) error {
}

func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTarget, opts copyOptions) (ocispec.Descriptor, error) {
var tracked track.GraphTarget
var err error
// Prepare copy options
committed := &sync.Map{}
extendedCopyOptions := oras.DefaultExtendedCopyOptions
Expand All @@ -162,15 +160,13 @@ func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTar
return successorPrinter(d)
})
}
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if tracked == nil {
return display.PrintStatus(desc, "Skipped", opts.Verbose)
}
return tracked.Prompt(desc, "Exists ", opts.Verbose)
}

if opts.TTY == nil {
// none TTY output
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return display.PrintStatus(desc, "Exists ", opts.Verbose)
}
extendedCopyOptions.PreCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
return display.PrintStatus(desc, "Copying", opts.Verbose)
}
Expand All @@ -183,18 +179,24 @@ func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTar
}
} else {
// TTY output
successorPrinter = func(desc ocispec.Descriptor) error {
return tracked.Prompt(desc, "Skipped", opts.Verbose)
}
tracked, err = track.NewTarget(dst, "Copying ", "Copied ", opts.TTY)

qweeah marked this conversation as resolved.
Show resolved Hide resolved
tracked, err := track.NewTarget(dst, "Copying ", "Copied ", opts.TTY)
if err != nil {
return ocispec.Descriptor{}, err
}
defer tracked.Close()
dst = tracked
successorPrinter = func(desc ocispec.Descriptor) error {
return tracked.Prompt(desc, "Skipped", opts.Verbose)
}
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return tracked.Prompt(desc, "Exists ", opts.Verbose)
}
}

var desc ocispec.Descriptor
var err error
rOpts := oras.DefaultResolveOptions
rOpts.TargetPlatform = opts.Platform.Platform
if opts.recursive {
Expand Down
35 changes: 19 additions & 16 deletions cmd/oras/root/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,16 @@ func doPush(dst oras.Target, pack packFunc, copy copyFunc) (ocispec.Descriptor,

func updateDisplayOption(opts *oras.CopyGraphOptions, fetcher content.Fetcher, verbose bool, tracked track.GraphTarget) {
committed := &sync.Map{}
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if tracked == nil {
return display.PrintStatus(desc, "Exists ", verbose)
}
return tracked.Prompt(desc, "Exists ", verbose)
}

if tracked == nil {
// non TTY
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if tracked == nil {
return display.PrintStatus(desc, "Exists ", verbose)
}
return tracked.Prompt(desc, "Exists ", verbose)
qweeah marked this conversation as resolved.
Show resolved Hide resolved
}
opts.PreCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
return display.PrintStatus(desc, "Uploading", verbose)
}
Expand All @@ -263,6 +264,10 @@ func updateDisplayOption(opts *oras.CopyGraphOptions, fetcher content.Fetcher, v
return
}
// TTY
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return tracked.Prompt(desc, "Exists ", verbose)
}
opts.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return display.PrintSuccessorStatus(ctx, desc, fetcher, committed, func(d ocispec.Descriptor) error {
Expand All @@ -275,16 +280,14 @@ type packFunc func() (ocispec.Descriptor, error)
type copyFunc func(desc ocispec.Descriptor) error

func getTrackedTarget(gt oras.GraphTarget, tty *os.File) (oras.GraphTarget, track.GraphTarget, error) {
var tracked track.GraphTarget
var err error
if tty != nil {
tracked, err = track.NewTarget(gt, "Uploading", "Uploaded ", tty)
if err != nil {
return nil, nil, err
}
gt = tracked
if tty == nil {
return gt, nil, nil
}
tracked, err := track.NewTarget(gt, "Uploading", "Uploaded ", tty)
if err != nil {
return nil, nil, err
}
return gt, tracked, nil
return tracked, tracked, nil
}

func pushArtifact(dst oras.Target, pack packFunc, copy copyFunc) (ocispec.Descriptor, error) {
Expand Down
Loading