Skip to content

Commit

Permalink
Merge pull request #4848 from katiewasnothere/ctr_image_chainid
Browse files Browse the repository at this point in the history
Add a new flag to ctr "images pull" to print the image's chainID
  • Loading branch information
dmcgowan committed Jan 22, 2021
2 parents 83f8d61 + 14df541 commit 392b285
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/ctr/commands/images/pull.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/platforms"
"github.com/opencontainers/image-spec/identity"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand Down Expand Up @@ -57,6 +58,10 @@ command. As part of this process, we do the following:
Name: "all-metadata",
Usage: "Pull metadata for all platforms",
},
cli.BoolFlag{
Name: "print-chainid",
Usage: "Print the resulting image's chain ID",
},
),
Action: func(context *cli.Context) error {
var (
Expand Down Expand Up @@ -118,6 +123,14 @@ command. As part of this process, we do the following:
if err != nil {
return err
}
if context.Bool("print-chainid") {
diffIDs, err := i.RootFS(ctx)
if err != nil {
return err
}
chainID := identity.ChainID(diffIDs).String()
fmt.Printf("image chain ID: %s\n", chainID)
}
}

fmt.Println("done")
Expand Down
16 changes: 16 additions & 0 deletions cmd/ctr/commands/snapshots/snapshots.go
Expand Up @@ -280,6 +280,10 @@ var prepareCommand = cli.Command{
Name: "target, t",
Usage: "mount target path, will print mount, if provided",
},
cli.BoolFlag{
Name: "mounts",
Usage: "Print out snapshot mounts as JSON",
},
},
Action: func(context *cli.Context) error {
if narg := context.NArg(); narg < 1 || narg > 2 {
Expand Down Expand Up @@ -310,6 +314,10 @@ var prepareCommand = cli.Command{
printMounts(target, mounts)
}

if context.Bool("mounts") {
commands.PrintAsJSON(mounts)
}

return nil
},
}
Expand All @@ -323,6 +331,10 @@ var viewCommand = cli.Command{
Name: "target, t",
Usage: "mount target path, will print mount, if provided",
},
cli.BoolFlag{
Name: "mounts",
Usage: "Print out snapshot mounts as JSON",
},
},
Action: func(context *cli.Context) error {
if narg := context.NArg(); narg < 1 || narg > 2 {
Expand All @@ -349,6 +361,10 @@ var viewCommand = cli.Command{
printMounts(target, mounts)
}

if context.Bool("mounts") {
commands.PrintAsJSON(mounts)
}

return nil
},
}
Expand Down

0 comments on commit 392b285

Please sign in to comment.