mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Merge pull request #8809 from erikh/builder_cmd_sh_fix
builder: Restore /bin/sh handling in CMD when entrypoint is specified with JSON
This commit is contained in:
		
						commit
						55702ae3d6
					
				
					 2 changed files with 35 additions and 1 deletions
				
			
		| 
						 | 
					@ -234,7 +234,7 @@ func run(b *Builder, args []string, attributes map[string]bool, original string)
 | 
				
			||||||
func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
 | 
					func cmd(b *Builder, args []string, attributes map[string]bool, original string) error {
 | 
				
			||||||
	b.Config.Cmd = handleJsonArgs(args, attributes)
 | 
						b.Config.Cmd = handleJsonArgs(args, attributes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !attributes["json"] && len(b.Config.Entrypoint) == 0 {
 | 
						if !attributes["json"] {
 | 
				
			||||||
		b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
 | 
							b.Config.Cmd = append([]string{"/bin/sh", "-c"}, b.Config.Cmd...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,40 @@ import (
 | 
				
			||||||
	"github.com/docker/docker/pkg/archive"
 | 
						"github.com/docker/docker/pkg/archive"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBuildShCmdJSONEntrypoint(t *testing.T) {
 | 
				
			||||||
 | 
						name := "testbuildshcmdjsonentrypoint"
 | 
				
			||||||
 | 
						defer deleteImages(name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := buildImage(
 | 
				
			||||||
 | 
							name,
 | 
				
			||||||
 | 
							`
 | 
				
			||||||
 | 
					    FROM busybox
 | 
				
			||||||
 | 
					    ENTRYPOINT ["/bin/echo"]
 | 
				
			||||||
 | 
					    CMD echo test
 | 
				
			||||||
 | 
					    `,
 | 
				
			||||||
 | 
							true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						out, _, err := runCommandWithOutput(
 | 
				
			||||||
 | 
							exec.Command(
 | 
				
			||||||
 | 
								dockerBinary,
 | 
				
			||||||
 | 
								"run",
 | 
				
			||||||
 | 
								name))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.TrimSpace(out) != "/bin/sh -c echo test" {
 | 
				
			||||||
 | 
							t.Fatal("CMD did not contain /bin/sh -c")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						logDone("build - CMD should always contain /bin/sh -c when specified without JSON")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestBuildEnvironmentReplacementUser(t *testing.T) {
 | 
					func TestBuildEnvironmentReplacementUser(t *testing.T) {
 | 
				
			||||||
	name := "testbuildenvironmentreplacement"
 | 
						name := "testbuildenvironmentreplacement"
 | 
				
			||||||
	defer deleteImages(name)
 | 
						defer deleteImages(name)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue