diff options
author | umohnani8 <umohnani@redhat.com> | 2017-12-15 16:14:52 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-12-20 10:08:17 +0000 |
commit | 26a6e0de46f6fcc6c80a20068d0019b45465a28d (patch) | |
tree | bca94ecf461f0fedce13d0ebe4b26f76d7f8f6fb /libpod | |
parent | 5da9fd4953ae4c0806fab2fbcee5767fe7b57467 (diff) | |
download | podman-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 'libpod')
-rw-r--r-- | libpod/container.go | 36 | ||||
-rw-r--r-- | libpod/image_inspect.go | 2 |
2 files changed, 35 insertions, 3 deletions
diff --git a/libpod/container.go b/libpod/container.go index 15ad1f49a..dc22c9c61 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -890,6 +890,10 @@ func (c *Container) Export(path string) error { return err } + return c.export(path) +} + +func (c *Container) export(path string) error { mountPoint := c.state.Mountpoint if !c.state.Mounted { mount, err := c.runtime.store.Mount(c.ID(), c.config.MountLabel) @@ -965,8 +969,36 @@ func (c *Container) Inspect(size bool) (*ContainerInspectData, error) { // Commit commits the changes between a container and its image, creating a new // image -func (c *Container) Commit() (*storage.Image, error) { - return nil, ErrNotImplemented +func (c *Container) Commit(pause bool, options CopyOptions) error { + c.lock.Lock() + defer c.lock.Unlock() + + if err := c.syncContainer(); err != nil { + return err + } + + if c.state.State == ContainerStateRunning && pause { + if err := c.runtime.ociRuntime.pauseContainer(c); err != nil { + return errors.Wrapf(err, "error pausing container %q", c.ID()) + } + defer func() { + if err := c.runtime.ociRuntime.unpauseContainer(c); err != nil { + logrus.Errorf("error unpausing container %q: %v", c.ID(), err) + } + }() + } + + tempFile, err := ioutil.TempFile(c.runtime.config.TmpDir, "podman-commit") + if err != nil { + return errors.Wrapf(err, "error creating temp file") + } + defer os.Remove(tempFile.Name()) + defer tempFile.Close() + + if err := c.export(tempFile.Name()); err != nil { + return err + } + return c.runtime.ImportImage(tempFile.Name(), options) } // Wait blocks on a container to exit and returns its exit code diff --git a/libpod/image_inspect.go b/libpod/image_inspect.go index a08665434..3d904e64b 100644 --- a/libpod/image_inspect.go +++ b/libpod/image_inspect.go @@ -47,7 +47,7 @@ func getImageData(img storage.Image, imgRef types.Image, size int64, driver *dri RepoDigests: repoDigests, Comment: ociv1Img.History[0].Comment, Created: ociv1Img.Created, - Author: ociv1Img.History[0].Author, + Author: ociv1Img.Author, Architecture: ociv1Img.Architecture, Os: ociv1Img.OS, Config: &ociv1Img.Config, |