mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00
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 <sushah@redhat.com>
This commit is contained in:
@ -115,6 +115,7 @@ type CommitValues struct {
|
|||||||
Pause bool
|
Pause bool
|
||||||
Quiet bool
|
Quiet bool
|
||||||
IncludeVolumes bool
|
IncludeVolumes bool
|
||||||
|
ImageIDFile string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContainersPrune struct {
|
type ContainersPrune struct {
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
@ -41,6 +42,7 @@ func init() {
|
|||||||
flags := commitCommand.Flags()
|
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.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.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.Message, "message", "m", "", "Set commit message for imported image")
|
||||||
flags.StringVarP(&commitCommand.Author, "author", "a", "", "Set the author for the image committed")
|
flags.StringVarP(&commitCommand.Author, "author", "a", "", "Set the author for the image committed")
|
||||||
flags.BoolVarP(&commitCommand.Pause, "pause", "p", false, "Pause container during commit")
|
flags.BoolVarP(&commitCommand.Pause, "pause", "p", false, "Pause container during commit")
|
||||||
@ -70,6 +72,11 @@ func commitCmd(c *cliconfig.CommitValues) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
fmt.Println(iid)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1247,6 +1247,7 @@ _podman_commit() {
|
|||||||
-c
|
-c
|
||||||
--message
|
--message
|
||||||
-m
|
-m
|
||||||
|
--iidfile
|
||||||
"
|
"
|
||||||
local boolean_options="
|
local boolean_options="
|
||||||
--help
|
--help
|
||||||
|
@ -38,6 +38,10 @@ Can be set multiple times
|
|||||||
Set the format of the image manifest and metadata. The currently supported formats are _oci_ and _docker_. If
|
Set the format of the image manifest and metadata. The currently supported formats are _oci_ and _docker_. If
|
||||||
not specifically set, the default format used is _oci_.
|
not specifically set, the default format used is _oci_.
|
||||||
|
|
||||||
|
**--iidfile**=*ImageIDfile*
|
||||||
|
|
||||||
|
Write the image ID to the file.
|
||||||
|
|
||||||
**--include-volumes**
|
**--include-volumes**
|
||||||
|
|
||||||
Include in the committed image any volumes added to the container by the `--volume` or `--mount` options to the `podman create` and `podman run` commands.
|
Include in the committed image any volumes added to the container by the `--volume` or `--mount` options to the `podman create` and `podman run` commands.
|
||||||
|
@ -152,4 +152,27 @@ var _ = Describe("Podman build", func() {
|
|||||||
Expect(strings.Fields(session.OutputToString())).
|
Expect(strings.Fields(session.OutputToString())).
|
||||||
To(ContainElement("scratch"))
|
To(ContainElement("scratch"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman build basic alpine and print id to external file", func() {
|
||||||
|
|
||||||
|
// Switch to temp dir and restore it afterwards
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(os.Chdir(os.TempDir())).To(BeNil())
|
||||||
|
defer Expect(os.Chdir(cwd)).To(BeNil())
|
||||||
|
|
||||||
|
targetPath := filepath.Join(os.TempDir(), "dir")
|
||||||
|
targetFile := filepath.Join(targetPath, "idFile")
|
||||||
|
|
||||||
|
session := podmanTest.PodmanNoCache([]string{"build", "build/basicalpine", "--iidfile", targetFile})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
id, _ := ioutil.ReadFile(targetFile)
|
||||||
|
|
||||||
|
// Verify that id is correct
|
||||||
|
inspect := podmanTest.PodmanNoCache([]string{"inspect", string(id)})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
data := inspect.InspectImageJSON()
|
||||||
|
Expect(data[0].ID).To(Equal(string(id)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/containers/libpod/test/utils"
|
. "github.com/containers/libpod/test/utils"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
@ -234,4 +236,30 @@ var _ = Describe("Podman commit", func() {
|
|||||||
}
|
}
|
||||||
Expect(envMap["TEST=1=1-01=9.01"]).To(BeTrue())
|
Expect(envMap["TEST=1=1-01=9.01"]).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman commit container and print id to external file", func() {
|
||||||
|
// Switch to temp dir and restore it afterwards
|
||||||
|
cwd, err := os.Getwd()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(os.Chdir(os.TempDir())).To(BeNil())
|
||||||
|
targetPath := filepath.Join(os.TempDir(), "dir")
|
||||||
|
Expect(os.MkdirAll(targetPath, 0755)).To(BeNil())
|
||||||
|
targetFile := filepath.Join(targetPath, "idFile")
|
||||||
|
defer Expect(os.RemoveAll(targetFile)).To(BeNil())
|
||||||
|
defer Expect(os.Chdir(cwd)).To(BeNil())
|
||||||
|
|
||||||
|
_, ec, _ := podmanTest.RunLsContainer("test1")
|
||||||
|
Expect(ec).To(Equal(0))
|
||||||
|
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
|
||||||
|
|
||||||
|
session := podmanTest.Podman([]string{"commit", "test1", "foobar.com/test1-image:latest", "--iidfile", targetFile})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
id, _ := ioutil.ReadFile(targetFile)
|
||||||
|
check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"})
|
||||||
|
check.WaitWithDefaultTimeout()
|
||||||
|
data := check.InspectImageJSON()
|
||||||
|
Expect(data[0].ID).To(Equal(string(id)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user