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 <fuweid89@gmail.com>
This commit is contained in:
		@@ -63,16 +63,19 @@ var pushCommand = cli.Command{
 | 
				
			|||||||
		var (
 | 
							var (
 | 
				
			||||||
			ref   = context.Args().First()
 | 
								ref   = context.Args().First()
 | 
				
			||||||
			local = context.Args().Get(1)
 | 
								local = context.Args().Get(1)
 | 
				
			||||||
 | 
								debug = context.GlobalBool("debug")
 | 
				
			||||||
			desc  ocispec.Descriptor
 | 
								desc  ocispec.Descriptor
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
		if ref == "" {
 | 
							if ref == "" {
 | 
				
			||||||
			return errors.New("please provide a remote image reference to push")
 | 
								return errors.New("please provide a remote image reference to push")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		client, ctx, cancel, err := commands.NewClient(context)
 | 
							client, ctx, cancel, err := commands.NewClient(context)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		defer cancel()
 | 
							defer cancel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if manifest := context.String("manifest"); manifest != "" {
 | 
							if manifest := context.String("manifest"); manifest != "" {
 | 
				
			||||||
			desc.Digest, err = digest.Parse(manifest)
 | 
								desc.Digest, err = digest.Parse(manifest)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
@@ -98,7 +101,12 @@ var pushCommand = cli.Command{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		eg, ctx := errgroup.WithContext(ctx)
 | 
							eg, ctx := errgroup.WithContext(ctx)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// used to notify the progress writer
 | 
				
			||||||
 | 
							doneCh := make(chan struct{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		eg.Go(func() error {
 | 
							eg.Go(func() error {
 | 
				
			||||||
 | 
								defer close(doneCh)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
 | 
								log.G(ctx).WithField("image", ref).WithField("digest", desc.Digest).Debug("pushing")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
 | 
								jobHandler := images.HandlerFunc(func(ctx gocontext.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
 | 
				
			||||||
@@ -112,18 +120,16 @@ var pushCommand = cli.Command{
 | 
				
			|||||||
			)
 | 
								)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		errs := make(chan error)
 | 
							// don't show progress if debug mode is set
 | 
				
			||||||
		go func() {
 | 
							if !debug {
 | 
				
			||||||
			defer close(errs)
 | 
								eg.Go(func() error {
 | 
				
			||||||
			errs <- eg.Wait()
 | 
					 | 
				
			||||||
		}()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				var (
 | 
									var (
 | 
				
			||||||
					ticker = time.NewTicker(100 * time.Millisecond)
 | 
										ticker = time.NewTicker(100 * time.Millisecond)
 | 
				
			||||||
					fw     = progress.NewWriter(os.Stdout)
 | 
										fw     = progress.NewWriter(os.Stdout)
 | 
				
			||||||
					start  = time.Now()
 | 
										start  = time.Now()
 | 
				
			||||||
					done   bool
 | 
										done   bool
 | 
				
			||||||
				)
 | 
									)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				defer ticker.Stop()
 | 
									defer ticker.Stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				for {
 | 
									for {
 | 
				
			||||||
@@ -140,15 +146,15 @@ var pushCommand = cli.Command{
 | 
				
			|||||||
							fw.Flush()
 | 
												fw.Flush()
 | 
				
			||||||
							return nil
 | 
												return nil
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
			case err := <-errs:
 | 
										case <-doneCh:
 | 
				
			||||||
				if err != nil {
 | 
					 | 
				
			||||||
					return err
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
						done = true
 | 
											done = true
 | 
				
			||||||
					case <-ctx.Done():
 | 
										case <-ctx.Done():
 | 
				
			||||||
						done = true // allow ui to update once more
 | 
											done = true // allow ui to update once more
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return eg.Wait()
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user