summaryrefslogtreecommitdiff
path: root/libpod/container_commit.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-04-16 06:26:47 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2019-04-17 15:44:50 -0400
commit6b3d4abb07bd15f6ca2c2f1dc007c325b9cc0dc4 (patch)
tree3de71a729e637b94a4dc2e802b7f84f3692afc99 /libpod/container_commit.go
parentbf5ffdafb40f32fac891a8cd5fc64cfd5b77674f (diff)
downloadpodman-6b3d4abb07bd15f6ca2c2f1dc007c325b9cc0dc4.tar.gz
podman-6b3d4abb07bd15f6ca2c2f1dc007c325b9cc0dc4.tar.bz2
podman-6b3d4abb07bd15f6ca2c2f1dc007c325b9cc0dc4.zip
Fix podman command --change CMD
Currently in Docker if you commit with --change 'CMD a b c' The command that gets added is [/bin/sh -c "a b c"] If you commit --change 'CMD ["a","b","c"]' You get [a b c] This patch set makes podman match this behaviour. Similar change required for Entrypoint. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/container_commit.go')
-rw-r--r--libpod/container_commit.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/libpod/container_commit.go b/libpod/container_commit.go
index 3cc4b2c92..ae04f67bb 100644
--- a/libpod/container_commit.go
+++ b/libpod/container_commit.go
@@ -125,23 +125,48 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
// Workdir
importBuilder.SetWorkDir(c.Spec().Process.Cwd)
+ genCmd := func(cmd string) []string {
+ trim := func(cmd []string) []string {
+ if len(cmd) == 0 {
+ return cmd
+ }
+
+ retCmd := []string{}
+ for _, c := range cmd {
+ if len(c) >= 2 {
+ if c[0] == '"' && c[len(c)-1] == '"' {
+ retCmd = append(retCmd, c[1:len(c)-1])
+ continue
+ }
+ }
+ retCmd = append(retCmd, c)
+ }
+ return retCmd
+ }
+ if strings.HasPrefix(cmd, "[") {
+ cmd = strings.TrimPrefix(cmd, "[")
+ cmd = strings.TrimSuffix(cmd, "]")
+ return trim(strings.Split(cmd, ","))
+ }
+ return []string{"/bin/sh", "-c", cmd}
+ }
// Process user changes
for _, change := range options.Changes {
- splitChange := strings.SplitN(change, " ", 2)
+ splitChange := strings.SplitN(change, "=", 2)
if len(splitChange) != 2 {
- splitChange = strings.SplitN(change, "=", 2)
+ splitChange = strings.SplitN(change, " ", 2)
if len(splitChange) < 2 {
return nil, errors.Errorf("invalid change %s format", change)
}
}
- change := strings.Split(splitChange[1], " ")
switch strings.ToUpper(splitChange[0]) {
case "CMD":
- importBuilder.SetCmd(change)
+ importBuilder.SetCmd(genCmd(splitChange[1]))
case "ENTRYPOINT":
- importBuilder.SetEntrypoint(change)
+ importBuilder.SetEntrypoint(genCmd(splitChange[1]))
case "ENV":
+ change := strings.Split(splitChange[1], " ")
name := change[0]
val := ""
if len(change) < 2 {
@@ -168,6 +193,7 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
}
importBuilder.SetPort(splitChange[1])
case "LABEL":
+ change := strings.Split(splitChange[1], " ")
if len(change) < 2 {
change = strings.Split(change[0], "=")
}