Skip to content

Commit 6424a36

Browse files
committed
ctr/commands/images/push: don't show progress if it is debug mode
If user sets debug mode, the command push should only show the debug log information. If the stdout is with flush by the progress status, it is hard to see the debug log. Signed-off-by: Wei Fu <[email protected]>
1 parent 5840ecc commit 6424a36

1 file changed

Lines changed: 41 additions & 35 deletions

File tree

cmd/ctr/commands/images/push.go

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ var pushCommand = cli.Command{
6363
var (
6464
ref = context.Args().First()
6565
local = context.Args().Get(1)
66+
debug = context.GlobalBool("debug")
6667
desc ocispec.Descriptor
6768
)
6869
if ref == "" {
6970
return errors.New("please provide a remote image reference to push")
7071
}
72+
7173
client, ctx, cancel, err := commands.NewClient(context)
7274
if err != nil {
7375
return err
7476
}
7577
defer cancel()
78+
7679
if manifest := context.String("manifest"); manifest != "" {
7780
desc.Digest, err = digest.Parse(manifest)
7881
if err != nil {
@@ -98,7 +101,12 @@ var pushCommand = cli.Command{
98101

99102
eg, ctx := errgroup.WithContext(ctx)
100103

104+
// used to notify the progress writer
105+
doneCh := make(chan struct{})
106+
101107
eg.Go(func() error {
108+
defer close(doneCh)
109+
102110
log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
103111

104112
jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
@@ -112,43 +120,41 @@ var pushCommand = cli.Command{
112120
)
113121
})
114122

115-
errs := make(chan error)
116-
go func() {
117-
defer close(errs)
118-
errs <- eg.Wait()
119-
}()
120-
121-
var (
122-
ticker = time.NewTicker(100 * time.Millisecond)
123-
fw = progress.NewWriter(os.Stdout)
124-
start = time.Now()
125-
done bool
126-
)
127-
defer ticker.Stop()
128-
129-
for {
130-
select {
131-
case <-ticker.C:
132-
fw.Flush()
133-
134-
tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0)
135-
136-
content.Display(tw, ongoing.status(), start)
137-
tw.Flush()
138-
139-
if done {
140-
fw.Flush()
141-
return nil
123+
// don't show progress if debug mode is set
124+
if !debug {
125+
eg.Go(func() error {
126+
var (
127+
ticker = time.NewTicker(100 * time.Millisecond)
128+
fw = progress.NewWriter(os.Stdout)
129+
start = time.Now()
130+
done bool
131+
)
132+
133+
defer ticker.Stop()
134+
135+
for {
136+
select {
137+
case <-ticker.C:
138+
fw.Flush()
139+
140+
tw := tabwriter.NewWriter(fw, 1, 8, 1, ' ', 0)
141+
142+
content.Display(tw, ongoing.status(), start)
143+
tw.Flush()
144+
145+
if done {
146+
fw.Flush()
147+
return nil
148+
}
149+
case <-doneCh:
150+
done = true
151+
case <-ctx.Done():
152+
done = true // allow ui to update once more
153+
}
142154
}
143-
case err := <-errs:
144-
if err != nil {
145-
return err
146-
}
147-
done = true
148-
case <-ctx.Done():
149-
done = true // allow ui to update once more
150-
}
155+
})
151156
}
157+
return eg.Wait()
152158
},
153159
}
154160

0 commit comments

Comments
 (0)