Skip to content

Commit 14df541

Browse files
author
Kathryn Baldauf
committed
Add a new flag to images pull for printing out the pulled image's chainID
Signed-off-by: Kathryn Baldauf <[email protected]>
1 parent 23315f8 commit 14df541

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

cmd/ctr/commands/images/pull.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/containerd/containerd/images"
2626
"github.com/containerd/containerd/log"
2727
"github.com/containerd/containerd/platforms"
28+
"github.com/opencontainers/image-spec/identity"
2829
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2930
"github.com/pkg/errors"
3031
"github.com/urfave/cli"
@@ -57,6 +58,10 @@ command. As part of this process, we do the following:
5758
Name: "all-metadata",
5859
Usage: "Pull metadata for all platforms",
5960
},
61+
cli.BoolFlag{
62+
Name: "print-chainid",
63+
Usage: "Print the resulting image's chain ID",
64+
},
6065
),
6166
Action: func(context *cli.Context) error {
6267
var (
@@ -118,6 +123,14 @@ command. As part of this process, we do the following:
118123
if err != nil {
119124
return err
120125
}
126+
if context.Bool("print-chainid") {
127+
diffIDs, err := i.RootFS(ctx)
128+
if err != nil {
129+
return err
130+
}
131+
chainID := identity.ChainID(diffIDs).String()
132+
fmt.Printf("image chain ID: %s\n", chainID)
133+
}
121134
}
122135

123136
fmt.Println("done")

cmd/ctr/commands/snapshots/snapshots.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ var prepareCommand = cli.Command{
280280
Name: "target, t",
281281
Usage: "mount target path, will print mount, if provided",
282282
},
283+
cli.BoolFlag{
284+
Name: "mounts",
285+
Usage: "Print out snapshot mounts as JSON",
286+
},
283287
},
284288
Action: func(context *cli.Context) error {
285289
if narg := context.NArg(); narg < 1 || narg > 2 {
@@ -310,6 +314,10 @@ var prepareCommand = cli.Command{
310314
printMounts(target, mounts)
311315
}
312316

317+
if context.Bool("mounts") {
318+
commands.PrintAsJSON(mounts)
319+
}
320+
313321
return nil
314322
},
315323
}
@@ -323,6 +331,10 @@ var viewCommand = cli.Command{
323331
Name: "target, t",
324332
Usage: "mount target path, will print mount, if provided",
325333
},
334+
cli.BoolFlag{
335+
Name: "mounts",
336+
Usage: "Print out snapshot mounts as JSON",
337+
},
326338
},
327339
Action: func(context *cli.Context) error {
328340
if narg := context.NArg(); narg < 1 || narg > 2 {
@@ -349,6 +361,10 @@ var viewCommand = cli.Command{
349361
printMounts(target, mounts)
350362
}
351363

364+
if context.Bool("mounts") {
365+
commands.PrintAsJSON(mounts)
366+
}
367+
352368
return nil
353369
},
354370
}

0 commit comments

Comments
 (0)