Merge pull request #8684 from erikh/onbuild_case_insensitive

builder: handle cases where onbuild is not uppercase.
This commit is contained in:
Alexandr Morozov 2014-10-21 15:24:15 -07:00
commit a07ee0db62
2 changed files with 37 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"regexp"
"strings"
"github.com/docker/docker/nat"
@ -129,7 +130,7 @@ func onbuild(b *Builder, args []string, attributes map[string]bool, original str
return fmt.Errorf("%s isn't allowed as an ONBUILD trigger", triggerInstruction)
}
original = strings.TrimSpace(strings.TrimLeft(original, "ONBUILD"))
original = regexp.MustCompile(`(?i)^\s*ONBUILD\s*`).ReplaceAllString(original, "")
b.Config.OnBuild = append(b.Config.OnBuild, original)
return b.commit("", b.Config.Cmd, fmt.Sprintf("ONBUILD %s", original))

View file

@ -15,6 +15,41 @@ import (
"github.com/docker/docker/pkg/archive"
)
func TestBuildOnBuildLowercase(t *testing.T) {
name := "testbuildonbuildlowercase"
name2 := "testbuildonbuildlowercase2"
defer deleteImages(name, name2)
_, err := buildImage(name,
`
FROM busybox
onbuild run echo quux
`, true)
if err != nil {
t.Fatal(err)
}
_, out, err := buildImageWithOut(name2, fmt.Sprintf(`
FROM %s
`, name), true)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(out, "quux") {
t.Fatalf("Did not receive the expected echo text, got %s", out)
}
if strings.Contains(out, "ONBUILD ONBUILD") {
t.Fatalf("Got an ONBUILD ONBUILD error with no error: got %s", out)
}
logDone("build - handle case-insensitive onbuild statement")
}
func TestBuildEnvEscapes(t *testing.T) {
name := "testbuildenvescapes"
defer deleteAllContainers()