aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/commit.go
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-12-15 16:14:52 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-20 10:08:17 +0000
commit26a6e0de46f6fcc6c80a20068d0019b45465a28d (patch)
treebca94ecf461f0fedce13d0ebe4b26f76d7f8f6fb /cmd/podman/commit.go
parent5da9fd4953ae4c0806fab2fbcee5767fe7b57467 (diff)
downloadpodman-26a6e0de46f6fcc6c80a20068d0019b45465a28d.tar.gz
podman-26a6e0de46f6fcc6c80a20068d0019b45465a28d.tar.bz2
podman-26a6e0de46f6fcc6c80a20068d0019b45465a28d.zip
Add podman commit command
podman commit allows the user to commit containers as images with options of tagging th image, setting a commit message, setting the auther, and making changes to the instructions. Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #143 Approved by: rhatdan
Diffstat (limited to 'cmd/podman/commit.go')
-rw-r--r--cmd/podman/commit.go93
1 files changed, 93 insertions, 0 deletions
diff --git a/cmd/podman/commit.go b/cmd/podman/commit.go
new file mode 100644
index 000000000..5d37458ea
--- /dev/null
+++ b/cmd/podman/commit.go
@@ -0,0 +1,93 @@
+package main
+
+import (
+ "github.com/opencontainers/image-spec/specs-go/v1"
+ "github.com/pkg/errors"
+ "github.com/projectatomic/libpod/libpod"
+ "github.com/urfave/cli"
+)
+
+var (
+ commitFlags = []cli.Flag{
+ cli.StringSliceFlag{
+ Name: "change, c",
+ Usage: "Apply the following possible instructions to the created image (default []): CMD | ENTRYPOINT | ENV | EXPOSE | LABEL | STOPSIGNAL | USER | VOLUME | WORKDIR",
+ },
+ cli.StringFlag{
+ Name: "message, m",
+ Usage: "Set commit message for imported image",
+ },
+ cli.StringFlag{
+ Name: "author, a",
+ Usage: "Set the author for the image comitted",
+ },
+ cli.BoolTFlag{
+ Name: "pause, p",
+ Usage: "Pause container during commit",
+ },
+ }
+ commitDescription = `Create an image from a container's changes.
+ Optionally tag the image created, set the author with the --author flag,
+ set the commit message with the --message flag,
+ and make changes to the instructions with the --change flag.`
+ commitCommand = cli.Command{
+ Name: "commit",
+ Usage: "Create new image based on the changed container",
+ Description: commitDescription,
+ Flags: commitFlags,
+ Action: commitCmd,
+ ArgsUsage: "CONTAINER [REPOSITORY[:TAG]]",
+ }
+)
+
+func commitCmd(c *cli.Context) error {
+ if err := validateFlags(c, commitFlags); err != nil {
+ return err
+ }
+
+ runtime, err := getRuntime(c)
+ if err != nil {
+ return errors.Wrapf(err, "could not get runtime")
+ }
+ defer runtime.Shutdown(false)
+
+ var opts libpod.CopyOptions
+ var container string
+ args := c.Args()
+ switch len(args) {
+ case 0:
+ return errors.Errorf("need to give container name or id")
+ case 1:
+ container = args[0]
+ case 2:
+ container = args[0]
+ opts.Reference = args[1]
+ default:
+ return errors.Errorf("too many arguments. Usage CONTAINER [REFERENCE]")
+ }
+
+ changes := v1.ImageConfig{}
+ if c.IsSet("change") {
+ changes, err = getImageConfig(c.StringSlice("change"))
+ if err != nil {
+ return errors.Wrapf(err, "error adding config changes to image %q", container)
+ }
+ }
+
+ history := []v1.History{
+ {Comment: c.String("message")},
+ }
+
+ config := v1.Image{
+ Config: changes,
+ History: history,
+ Author: c.String("author"),
+ }
+ opts.ImageConfig = config
+
+ ctr, err := runtime.LookupContainer(container)
+ if err != nil {
+ return errors.Wrapf(err, "error looking up container %q", container)
+ }
+ return ctr.Commit(c.BoolT("pause"), opts)
+}