Skip to content

Commit

Permalink
build: support --quiet
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Sep 30, 2021
1 parent bc8fea3 commit 77d602e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions cmd/nerdctl/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ var buildCommand = &cli.Command{
Name: "ssh",
Usage: "SSH agent socket or keys to expose to the build (format: default|<id>[=<socket>|<key>[,<key>]])",
},
&cli.BoolFlag{
Name: "quiet",
Aliases: []string{"q"},
Usage: "Suppress the build output and print image ID on success",
},
},
}

Expand All @@ -98,6 +103,8 @@ func buildAction(clicontext *cli.Context) error {
return err
}

quiet := clicontext.Bool("quiet")

logrus.Debugf("running %s %v", buildctlBinary, buildctlArgs)
buildctlCmd := exec.Command(buildctlBinary, buildctlArgs...)
buildctlCmd.Env = os.Environ()
Expand All @@ -111,14 +118,17 @@ func buildAction(clicontext *cli.Context) error {
} else {
buildctlCmd.Stdout = clicontext.App.Writer
}
buildctlCmd.Stderr = clicontext.App.ErrWriter

if !quiet {
buildctlCmd.Stderr = clicontext.App.ErrWriter
}

if err := buildctlCmd.Start(); err != nil {
return err
}

if needsLoading {
if err = loadImage(buildctlStdout, clicontext); err != nil {
if err = loadImage(buildctlStdout, clicontext, quiet); err != nil {
return err
}
}
Expand Down
14 changes: 10 additions & 4 deletions cmd/nerdctl/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func loadAction(clicontext *cli.Context) error {
defer f.Close()
in = f
}
return loadImage(in, clicontext)
return loadImage(in, clicontext, false)
}

func loadImage(in io.Reader, clicontext *cli.Context) error {
func loadImage(in io.Reader, clicontext *cli.Context, quiet bool) error {
client, ctx, cancel, err := newClient(clicontext, containerd.WithDefaultPlatform(platforms.DefaultStrict()))
if err != nil {
return err
Expand All @@ -74,12 +74,18 @@ func loadImage(in io.Reader, clicontext *cli.Context) error {
image := containerd.NewImage(client, img)

// TODO: Show unpack status
fmt.Fprintf(clicontext.App.Writer, "unpacking %s (%s)...", img.Name, img.Target.Digest)
if !quiet {
fmt.Fprintf(clicontext.App.Writer, "unpacking %s (%s)...", img.Name, img.Target.Digest)
}
err = image.Unpack(ctx, sn)
if err != nil {
return err
}
fmt.Fprintf(clicontext.App.Writer, "done\n")
if quiet {
fmt.Fprintln(clicontext.App.Writer, img.Target.Digest)
} else {
fmt.Fprintf(clicontext.App.Writer, "done\n")
}
}

return nil
Expand Down

0 comments on commit 77d602e

Please sign in to comment.