diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/commit.go | 93 | ||||
-rw-r--r-- | cmd/podman/import.go | 2 | ||||
-rw-r--r-- | cmd/podman/load.go | 2 | ||||
-rw-r--r-- | cmd/podman/main.go | 1 |
4 files changed, 96 insertions, 2 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) +} diff --git a/cmd/podman/import.go b/cmd/podman/import.go index 2e8702c3d..7b380b500 100644 --- a/cmd/podman/import.go +++ b/cmd/podman/import.go @@ -28,7 +28,7 @@ var ( } importDescription = `Create a container image from the contents of the specified tarball (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz). Note remote tar balls can be specified, via web address. - Optionally tag the image. You can specify the Dockerfile instructions using the --change option. + Optionally tag the image. You can specify the instructions using the --change option. ` importCommand = cli.Command{ Name: "import", diff --git a/cmd/podman/load.go b/cmd/podman/load.go index 2f3d9c56d..ee8a79756 100644 --- a/cmd/podman/load.go +++ b/cmd/podman/load.go @@ -73,8 +73,8 @@ func loadCmd(c *cli.Context) error { if err != nil { return errors.Errorf("error creating file %v", err) } - defer outFile.Close() defer os.Remove(outFile.Name()) + defer outFile.Close() inFile, err := os.OpenFile(input, 0, 0666) if err != nil { diff --git a/cmd/podman/main.go b/cmd/podman/main.go index cc6d26992..d3cb86798 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -35,6 +35,7 @@ func main() { app.Commands = []cli.Command{ attachCommand, + commitCommand, createCommand, diffCommand, execCommand, |