mirror of
https://github.com/containers/podman.git
synced 2025-06-23 18:59:30 +08:00
Merge pull request #2895 from mheon/commit_no_default_include_volumes
Add --include-volumes flag to 'podman commit'
This commit is contained in:
@ -88,12 +88,13 @@ type CheckpointValues struct {
|
|||||||
|
|
||||||
type CommitValues struct {
|
type CommitValues struct {
|
||||||
PodmanCommand
|
PodmanCommand
|
||||||
Change []string
|
Change []string
|
||||||
Format string
|
Format string
|
||||||
Message string
|
Message string
|
||||||
Author string
|
Author string
|
||||||
Pause bool
|
Pause bool
|
||||||
Quiet bool
|
Quiet bool
|
||||||
|
IncludeVolumes bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContainersPrune struct {
|
type ContainersPrune struct {
|
||||||
|
@ -2,19 +2,19 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/buildah"
|
"github.com/containers/buildah"
|
||||||
"github.com/containers/image/manifest"
|
"github.com/containers/image/manifest"
|
||||||
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/libpod/image"
|
"github.com/containers/libpod/libpod/image"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -47,7 +47,7 @@ func init() {
|
|||||||
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")
|
||||||
flags.BoolVarP(&commitCommand.Quiet, "quiet", "q", false, "Suppress output")
|
flags.BoolVarP(&commitCommand.Quiet, "quiet", "q", false, "Suppress output")
|
||||||
|
flags.BoolVar(&commitCommand.IncludeVolumes, "include-volumes", false, "Include container volumes as image volumes")
|
||||||
}
|
}
|
||||||
|
|
||||||
func commitCmd(c *cliconfig.CommitValues) error {
|
func commitCmd(c *cliconfig.CommitValues) error {
|
||||||
@ -109,11 +109,12 @@ func commitCmd(c *cliconfig.CommitValues) error {
|
|||||||
PreferredManifestType: mimeType,
|
PreferredManifestType: mimeType,
|
||||||
}
|
}
|
||||||
options := libpod.ContainerCommitOptions{
|
options := libpod.ContainerCommitOptions{
|
||||||
CommitOptions: coptions,
|
CommitOptions: coptions,
|
||||||
Pause: c.Pause,
|
Pause: c.Pause,
|
||||||
Message: c.Message,
|
IncludeVolumes: c.IncludeVolumes,
|
||||||
Changes: c.Change,
|
Message: c.Message,
|
||||||
Author: c.Author,
|
Changes: c.Change,
|
||||||
|
Author: c.Author,
|
||||||
}
|
}
|
||||||
newImage, err := ctr.Commit(getContext(), reference, options)
|
newImage, err := ctr.Commit(getContext(), reference, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -39,6 +39,10 @@ not specifically set, the default format used is _oci_.
|
|||||||
|
|
||||||
Write the image ID to the file.
|
Write the image ID to the file.
|
||||||
|
|
||||||
|
**--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.
|
||||||
|
|
||||||
**--message, -m**
|
**--message, -m**
|
||||||
|
|
||||||
Set commit message for committed image. The message field is not supported in _oci_ format.
|
Set commit message for committed image. The message field is not supported in _oci_ format.
|
||||||
|
@ -20,10 +20,11 @@ import (
|
|||||||
//libpod
|
//libpod
|
||||||
type ContainerCommitOptions struct {
|
type ContainerCommitOptions struct {
|
||||||
buildah.CommitOptions
|
buildah.CommitOptions
|
||||||
Pause bool
|
Pause bool
|
||||||
Author string
|
IncludeVolumes bool
|
||||||
Message string
|
Author string
|
||||||
Changes []string
|
Message string
|
||||||
|
Changes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChangeCmds is the list of valid Changes commands to passed to the Commit call
|
// ChangeCmds is the list of valid Changes commands to passed to the Commit call
|
||||||
@ -113,9 +114,11 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
|
|||||||
// User
|
// User
|
||||||
importBuilder.SetUser(c.User())
|
importBuilder.SetUser(c.User())
|
||||||
// Volumes
|
// Volumes
|
||||||
for _, v := range c.config.UserVolumes {
|
if options.IncludeVolumes {
|
||||||
if v != "" {
|
for _, v := range c.config.UserVolumes {
|
||||||
importBuilder.AddVolume(v)
|
if v != "" {
|
||||||
|
importBuilder.AddVolume(v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Workdir
|
// Workdir
|
||||||
|
@ -131,7 +131,7 @@ var _ = Describe("Podman commit", func() {
|
|||||||
Expect(check.ExitCode()).To(Equal(0))
|
Expect(check.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("podman commit with volume mounts", func() {
|
It("podman commit with volumes mounts and no include-volumes", func() {
|
||||||
s := podmanTest.Podman([]string{"run", "--name", "test1", "-v", "/tmp:/foo", "alpine", "date"})
|
s := podmanTest.Podman([]string{"run", "--name", "test1", "-v", "/tmp:/foo", "alpine", "date"})
|
||||||
s.WaitWithDefaultTimeout()
|
s.WaitWithDefaultTimeout()
|
||||||
Expect(s.ExitCode()).To(Equal(0))
|
Expect(s.ExitCode()).To(Equal(0))
|
||||||
@ -140,6 +140,23 @@ var _ = Describe("Podman commit", func() {
|
|||||||
c.WaitWithDefaultTimeout()
|
c.WaitWithDefaultTimeout()
|
||||||
Expect(c.ExitCode()).To(Equal(0))
|
Expect(c.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
inspect := podmanTest.Podman([]string{"inspect", "newimage"})
|
||||||
|
inspect.WaitWithDefaultTimeout()
|
||||||
|
Expect(inspect.ExitCode()).To(Equal(0))
|
||||||
|
image := inspect.InspectImageJSON()
|
||||||
|
_, ok := image[0].Config.Volumes["/foo"]
|
||||||
|
Expect(ok).To(BeFalse())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman commit with volume mounts and --include-volumes", func() {
|
||||||
|
s := podmanTest.Podman([]string{"run", "--name", "test1", "-v", "/tmp:/foo", "alpine", "date"})
|
||||||
|
s.WaitWithDefaultTimeout()
|
||||||
|
Expect(s.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
c := podmanTest.Podman([]string{"commit", "--include-volumes", "test1", "newimage"})
|
||||||
|
c.WaitWithDefaultTimeout()
|
||||||
|
Expect(c.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
inspect := podmanTest.Podman([]string{"inspect", "newimage"})
|
inspect := podmanTest.Podman([]string{"inspect", "newimage"})
|
||||||
inspect.WaitWithDefaultTimeout()
|
inspect.WaitWithDefaultTimeout()
|
||||||
Expect(inspect.ExitCode()).To(Equal(0))
|
Expect(inspect.ExitCode()).To(Equal(0))
|
||||||
|
Reference in New Issue
Block a user