зеркало из https://github.com/microsoft/docker.git
Cleanup Cmd on ENTRYPOINT instruction
Fixes #5147 Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
This commit is contained in:
Родитель
7dba5024e8
Коммит
1b6546b840
|
@ -70,6 +70,9 @@ type buildFile struct {
|
|||
// Deprecated, original writer used for ImagePull. To be removed.
|
||||
outOld io.Writer
|
||||
sf *utils.StreamFormatter
|
||||
|
||||
// cmdSet indicates is CMD was setted in current Dockerfile
|
||||
cmdSet bool
|
||||
}
|
||||
|
||||
func (b *buildFile) clearTmp(containers map[string]struct{}) {
|
||||
|
@ -306,12 +309,17 @@ func (b *buildFile) CmdCmd(args string) error {
|
|||
if err := b.commit("", b.config.Cmd, fmt.Sprintf("CMD %v", cmd)); err != nil {
|
||||
return err
|
||||
}
|
||||
b.cmdSet = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *buildFile) CmdEntrypoint(args string) error {
|
||||
entrypoint := b.buildCmdFromJson(args)
|
||||
b.config.Entrypoint = entrypoint
|
||||
// if there is no cmd in current Dockerfile - cleanup cmd
|
||||
if !b.cmdSet {
|
||||
b.config.Cmd = nil
|
||||
}
|
||||
if err := b.commit("", b.config.Cmd, fmt.Sprintf("ENTRYPOINT %v", entrypoint)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1310,8 +1310,8 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Cmd inherited from busybox, maybe will be fixed in #5147
|
||||
if expected := "[/bin/sh]"; res != expected {
|
||||
// Cmd must be cleaned up
|
||||
if expected := "<no value>"; res != expected {
|
||||
t.Fatalf("Cmd %s, expected %s", res, expected)
|
||||
}
|
||||
logDone("build - cleanup cmd after RUN")
|
||||
|
@ -1875,3 +1875,36 @@ func TestBuildFromGIT(t *testing.T) {
|
|||
}
|
||||
logDone("build - build from GIT")
|
||||
}
|
||||
|
||||
func TestBuildCleanupCmdOnEntrypoint(t *testing.T) {
|
||||
name := "testbuildcmdcleanuponentrypoint"
|
||||
defer deleteImages(name)
|
||||
if _, err := buildImage(name,
|
||||
`FROM scratch
|
||||
CMD ["test"]
|
||||
ENTRYPOINT ["echo"]`,
|
||||
true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := buildImage(name,
|
||||
fmt.Sprintf(`FROM %s
|
||||
ENTRYPOINT ["cat"]`, name),
|
||||
true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, err := inspectField(name, "Config.Cmd")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "<no value>"; res != expected {
|
||||
t.Fatalf("Cmd %s, expected %s", res, expected)
|
||||
}
|
||||
res, err = inspectField(name, "Config.Entrypoint")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if expected := "[cat]"; res != expected {
|
||||
t.Fatalf("Entrypoint %s, expected %s", res, expected)
|
||||
}
|
||||
logDone("build - cleanup cmd on ENTRYPOINT")
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче