From 00f8d32ef5ae97de239c008327c041b992c40f11 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Mon, 19 Apr 2021 15:09:09 -0500 Subject: [PATCH 1/2] add not found debug out for check cmd; update usage Signed-off-by: Mike Brown --- cmd/ctr/commands/images/images.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/ctr/commands/images/images.go b/cmd/ctr/commands/images/images.go index 05fec7ac0..3ec0492ae 100644 --- a/cmd/ctr/commands/images/images.go +++ b/cmd/ctr/commands/images/images.go @@ -199,9 +199,9 @@ var setLabelsCommand = cli.Command{ var checkCommand = cli.Command{ Name: "check", - Usage: "check that an image has all content available locally", + Usage: "check existing images to ensure all content is available locally", ArgsUsage: "[flags] [, ...]", - Description: "check that an image has all content available locally", + Description: "check existing images to ensure all content is available locally", Flags: commands.SnapshotterFlags, Action: func(context *cli.Context) error { var ( @@ -212,17 +212,21 @@ var checkCommand = cli.Command{ return err } defer cancel() - var ( - contentStore = client.ContentStore() - tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0) - ) - fmt.Fprintln(tw, "REF\tTYPE\tDIGEST\tSTATUS\tSIZE\tUNPACKED\t") + + var contentStore = client.ContentStore() args := []string(context.Args()) imageList, err := client.ListImages(ctx, args...) if err != nil { return errors.Wrap(err, "failed listing images") } + if len(imageList) == 0 { + log.G(ctx).Debugf("no images found") + return exitErr + } + + var tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0) + fmt.Fprintln(tw, "REF\tTYPE\tDIGEST\tSTATUS\tSIZE\tUNPACKED\t") for _, image := range imageList { var ( From 391b123a5e332e8114eaaa9e313ad27e8f0dbd47 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Tue, 20 Apr 2021 09:20:14 -0500 Subject: [PATCH 2/2] adds quiet option for ref Signed-off-by: Mike Brown --- cmd/ctr/commands/images/images.go | 41 ++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/cmd/ctr/commands/images/images.go b/cmd/ctr/commands/images/images.go index 3ec0492ae..077afd8f8 100644 --- a/cmd/ctr/commands/images/images.go +++ b/cmd/ctr/commands/images/images.go @@ -202,10 +202,16 @@ var checkCommand = cli.Command{ Usage: "check existing images to ensure all content is available locally", ArgsUsage: "[flags] [, ...]", Description: "check existing images to ensure all content is available locally", - Flags: commands.SnapshotterFlags, + Flags: append([]cli.Flag{ + cli.BoolFlag{ + Name: "quiet, q", + Usage: "print only the ready image refs (fully downloaded and unpacked)", + }, + }, commands.SnapshotterFlags...), Action: func(context *cli.Context) error { var ( exitErr error + quiet = context.Bool("quiet") ) client, ctx, cancel, err := commands.NewClient(context) if err != nil { @@ -226,7 +232,9 @@ var checkCommand = cli.Command{ } var tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, ' ', 0) - fmt.Fprintln(tw, "REF\tTYPE\tDIGEST\tSTATUS\tSIZE\tUNPACKED\t") + if !quiet { + fmt.Fprintln(tw, "REF\tTYPE\tDIGEST\tSTATUS\tSIZE\tUNPACKED\t") + } for _, image := range imageList { var ( @@ -234,6 +242,7 @@ var checkCommand = cli.Command{ size string requiredSize int64 presentSize int64 + complete bool = true ) available, required, present, missing, err := images.Check(ctx, contentStore, image.Target(), platforms.Default()) @@ -243,6 +252,7 @@ var checkCommand = cli.Command{ } log.G(ctx).WithError(err).Errorf("unable to check %v", image.Name()) status = "error" + complete = false } if status != "error" { @@ -256,6 +266,7 @@ var checkCommand = cli.Command{ if len(missing) > 0 { status = "incomplete" + complete = false } if available { @@ -264,6 +275,7 @@ var checkCommand = cli.Command{ } else { status = fmt.Sprintf("unavailable (%v/?)", len(present)) size = fmt.Sprintf("%v/?", progress.Bytes(presentSize)) + complete = false } } else { size = "-" @@ -277,16 +289,23 @@ var checkCommand = cli.Command{ log.G(ctx).WithError(err).Errorf("unable to check unpack for %v", image.Name()) } - fmt.Fprintf(tw, "%v\t%v\t%v\t%v\t%v\t%t\n", - image.Name(), - image.Target().MediaType, - image.Target().Digest, - status, - size, - unpacked) + if !quiet { + fmt.Fprintf(tw, "%v\t%v\t%v\t%v\t%v\t%t\n", + image.Name(), + image.Target().MediaType, + image.Target().Digest, + status, + size, + unpacked) + } else { + if complete { + fmt.Println(image.Name()) + } + } + } + if !quiet { + tw.Flush() } - tw.Flush() - return exitErr }, }