From 5efa6dae905c65ea8a73565318e5f274c5eb825c Mon Sep 17 00:00:00 2001 From: Sujil02 Date: Thu, 12 Mar 2020 10:46:44 -0400 Subject: Implemented --iidfile for podman commit Added flag to Write the image ID to the file with podman commit command. Fix to issue #5461 Signed-off-by: Sujil02 --- cmd/podman/cliconfig/config.go | 1 + cmd/podman/commit.go | 7 +++++++ 2 files changed, 8 insertions(+) (limited to 'cmd') diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go index 94a7b2091..3428746a9 100644 --- a/cmd/podman/cliconfig/config.go +++ b/cmd/podman/cliconfig/config.go @@ -115,6 +115,7 @@ type CommitValues struct { Pause bool Quiet bool IncludeVolumes bool + ImageIDFile string } type ContainersPrune struct { diff --git a/cmd/podman/commit.go b/cmd/podman/commit.go index 7c35a4832..3ad3bd275 100644 --- a/cmd/podman/commit.go +++ b/cmd/podman/commit.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io/ioutil" "strings" "github.com/containers/libpod/cmd/podman/cliconfig" @@ -41,6 +42,7 @@ func init() { flags := commitCommand.Flags() flags.StringArrayVarP(&commitCommand.Change, "change", "c", []string{}, fmt.Sprintf("Apply the following possible instructions to the created image (default []): %s", strings.Join(ChangeCmds, " | "))) flags.StringVarP(&commitCommand.Format, "format", "f", "oci", "`Format` of the image manifest and metadata") + flags.StringVarP(&commitCommand.ImageIDFile, "iidfile", "", "", "`file` to write the image ID to") flags.StringVarP(&commitCommand.Message, "message", "m", "", "Set commit message for imported image") flags.StringVarP(&commitCommand.Author, "author", "a", "", "Set the author for the image committed") flags.BoolVarP(&commitCommand.Pause, "pause", "p", false, "Pause container during commit") @@ -70,6 +72,11 @@ func commitCmd(c *cliconfig.CommitValues) error { if err != nil { return err } + if c.ImageIDFile != "" { + if err = ioutil.WriteFile(c.ImageIDFile, []byte(iid), 0644); err != nil { + return errors.Wrapf(err, "failed to write image ID to file %q", c.ImageIDFile) + } + } fmt.Println(iid) return nil } -- cgit v1.2.3-54-g00ecf