From 36c9cb86c82e7ae13352018d969f787ce0ead3a1 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 30 Nov 2018 15:41:38 +0100 Subject: [PATCH 1/2] Add tests from `FROM scratch` and `FROM SCRATCH` Signed-off-by: David Gageot --- pkg/skaffold/docker/parse_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/skaffold/docker/parse_test.go b/pkg/skaffold/docker/parse_test.go index b31f25efa27..1741cd79e42 100644 --- a/pkg/skaffold/docker/parse_test.go +++ b/pkg/skaffold/docker/parse_test.go @@ -174,6 +174,16 @@ FROM nginx COPY . / ` +const fromScratch = ` +FROM scratch +ADD ./file /etc/file +` + +const fromScratchUppercase = ` +FROM SCRATCH +ADD ./file /etc/file +` + type fakeImageFetcher struct { fetched []string } @@ -437,6 +447,20 @@ func TestGetDependencies(t *testing.T) { expected: []string{"Dockerfile"}, fetched: []string{"ubuntu:14.04"}, }, + { + description: "from scratch", + dockerfile: fromScratch, + workspace: ".", + expected: []string{"Dockerfile", "file"}, + fetched: nil, + }, + { + description: "from scratch, ignoring case", + dockerfile: fromScratchUppercase, + workspace: ".", + expected: []string{"Dockerfile", "file"}, + fetched: nil, + }, } for _, test := range tests { From 9e31867ca14635b1eaea7679d14d2b4a0fd4f9de Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 30 Nov 2018 15:43:37 +0100 Subject: [PATCH 2/2] Image name are case sensitive Fix #1185 --- pkg/skaffold/docker/parse.go | 13 +++++++++---- pkg/skaffold/docker/parse_test.go | 14 +++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/skaffold/docker/parse.go b/pkg/skaffold/docker/parse.go index c1b75291fbf..1436df06571 100644 --- a/pkg/skaffold/docker/parse.go +++ b/pkg/skaffold/docker/parse.go @@ -119,7 +119,7 @@ func fromInstruction(node *parser.Node) from { } return from{ - image: strings.ToLower(node.Next.Value), + image: node.Next.Value, as: strings.ToLower(as), } } @@ -129,17 +129,22 @@ func onbuildInstructions(nodes []*parser.Node) ([]*parser.Node, error) { stages := map[string]bool{} for _, from := range fromInstructions(nodes) { - stages[from.as] = true + // Stage names are case insensitive + stages[strings.ToLower(from.as)] = true - if from.image == "scratch" { + // `scratch` is case insensitive + if strings.ToLower(from.image) == "scratch" { continue } - if _, found := stages[from.image]; found { + // Stage names are case insensitive + if _, found := stages[strings.ToLower(from.image)]; found { continue } logrus.Debugf("Checking base image %s for ONBUILD triggers.", from.image) + + // Image names are case SENSITIVE img, err := RetrieveImage(from.image) if err != nil { logrus.Warnf("Error processing base image for ONBUILD triggers: %s. Dependencies may be incomplete.", err) diff --git a/pkg/skaffold/docker/parse_test.go b/pkg/skaffold/docker/parse_test.go index 1741cd79e42..bc8cd8ef35d 100644 --- a/pkg/skaffold/docker/parse_test.go +++ b/pkg/skaffold/docker/parse_test.go @@ -184,6 +184,11 @@ FROM SCRATCH ADD ./file /etc/file ` +const fromImageCaseSensitive = ` +FROM jboss/wildfly:14.0.1.Final +ADD ./file /etc/file +` + type fakeImageFetcher struct { fetched []string } @@ -192,7 +197,7 @@ func (f *fakeImageFetcher) fetch(image string) (*v1.ConfigFile, error) { f.fetched = append(f.fetched, image) switch image { - case "ubuntu:14.04", "busybox", "nginx", "golang:1.9.2": + case "ubuntu:14.04", "busybox", "nginx", "golang:1.9.2", "jboss/wildfly:14.0.1.Final": return &v1.ConfigFile{}, nil case "golang:onbuild": return &v1.ConfigFile{ @@ -461,6 +466,13 @@ func TestGetDependencies(t *testing.T) { expected: []string{"Dockerfile", "file"}, fetched: nil, }, + { + description: "case sensitive", + dockerfile: fromImageCaseSensitive, + workspace: ".", + expected: []string{"Dockerfile", "file"}, + fetched: []string{"jboss/wildfly:14.0.1.Final"}, + }, } for _, test := range tests {