From 87a654032f11e6bb1548fd5ed86fac12c9edc112 Mon Sep 17 00:00:00 2001 From: Farhad Vildanov Date: Fri, 10 Jan 2020 23:20:15 +0300 Subject: [PATCH 1/2] Dockerfile detector will only check files containing "Dockerfile" in the name. Fixes #3484. --- pkg/skaffold/initializer/init.go | 9 ++++++--- pkg/skaffold/initializer/init_test.go | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/skaffold/initializer/init.go b/pkg/skaffold/initializer/init.go index f888a9072a9..9fd3446aca1 100644 --- a/pkg/skaffold/initializer/init.go +++ b/pkg/skaffold/initializer/init.go @@ -288,9 +288,12 @@ func detectBuilders(enableJibInit, enableBuildpackInit bool, path string) ([]Ini } // Check for Dockerfile - if docker.Validate(path) { - results := []InitBuilder{docker.ArtifactConfig{File: path}} - return results, true + base := filepath.Base(path) + if strings.Contains(base, "Dockerfile") { + if docker.Validate(path) { + results := []InitBuilder{docker.ArtifactConfig{File: path}} + return results, true + } } // TODO: Remove backwards compatibility if statement (not entire block) diff --git a/pkg/skaffold/initializer/init_test.go b/pkg/skaffold/initializer/init_test.go index 075a34275eb..2b36e882000 100644 --- a/pkg/skaffold/initializer/init_test.go +++ b/pkg/skaffold/initializer/init_test.go @@ -142,14 +142,16 @@ func TestWalk(t *testing.T) { { description: "should return correct k8 configs and build files (backwards compatibility)", filesWithContents: map[string]string{ - "config/test.yaml": validK8sManifest, - "config/invalid.yaml": emptyFile, - "k8pod.yml": validK8sManifest, - "README": emptyFile, - "deploy/Dockerfile": emptyFile, - "gradle/build.gradle": emptyFile, - "maven/pom.xml": emptyFile, - "Dockerfile": emptyFile, + "config/test.yaml": validK8sManifest, + "config/invalid.yaml": emptyFile, + "k8pod.yml": validK8sManifest, + "README": emptyFile, + "deploy/Dockerfile": emptyFile, + "deploy/Dockerfile.dev": emptyFile, + "deploy/dev.Dockerfile": emptyFile, + "gradle/build.gradle": emptyFile, + "maven/pom.xml": emptyFile, + "Dockerfile": emptyFile, }, force: false, expectedConfigs: []string{ @@ -159,6 +161,8 @@ func TestWalk(t *testing.T) { expectedPaths: []string{ "Dockerfile", "deploy/Dockerfile", + "deploy/Dockerfile.dev", + "deploy/dev.Dockerfile", }, shouldErr: false, }, @@ -342,7 +346,7 @@ deploy: } func fakeValidateDockerfile(path string) bool { - return strings.HasSuffix(path, "Dockerfile") + return strings.Contains(path, "Dockerfile") } func fakeValidateJibConfig(path string) []jib.ArtifactConfig { From bd452f2420ece996b954fef65f20b2fd96cbf786 Mon Sep 17 00:00:00 2001 From: Farhad Vildanov Date: Mon, 13 Jan 2020 21:12:33 +0300 Subject: [PATCH 2/2] Make filename check case-insensitive. --- pkg/skaffold/initializer/init.go | 2 +- pkg/skaffold/initializer/init_test.go | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/skaffold/initializer/init.go b/pkg/skaffold/initializer/init.go index 9fd3446aca1..72c04a2df48 100644 --- a/pkg/skaffold/initializer/init.go +++ b/pkg/skaffold/initializer/init.go @@ -289,7 +289,7 @@ func detectBuilders(enableJibInit, enableBuildpackInit bool, path string) ([]Ini // Check for Dockerfile base := filepath.Base(path) - if strings.Contains(base, "Dockerfile") { + if strings.Contains(strings.ToLower(base), "dockerfile") { if docker.Validate(path) { results := []InitBuilder{docker.ArtifactConfig{File: path}} return results, true diff --git a/pkg/skaffold/initializer/init_test.go b/pkg/skaffold/initializer/init_test.go index 2b36e882000..65d86ade036 100644 --- a/pkg/skaffold/initializer/init_test.go +++ b/pkg/skaffold/initializer/init_test.go @@ -142,16 +142,17 @@ func TestWalk(t *testing.T) { { description: "should return correct k8 configs and build files (backwards compatibility)", filesWithContents: map[string]string{ - "config/test.yaml": validK8sManifest, - "config/invalid.yaml": emptyFile, - "k8pod.yml": validK8sManifest, - "README": emptyFile, - "deploy/Dockerfile": emptyFile, - "deploy/Dockerfile.dev": emptyFile, - "deploy/dev.Dockerfile": emptyFile, - "gradle/build.gradle": emptyFile, - "maven/pom.xml": emptyFile, - "Dockerfile": emptyFile, + "config/test.yaml": validK8sManifest, + "config/invalid.yaml": emptyFile, + "k8pod.yml": validK8sManifest, + "README": emptyFile, + "deploy/Dockerfile": emptyFile, + "deploy/Dockerfile.dev": emptyFile, + "deploy/dev.Dockerfile": emptyFile, + "deploy/test.dockerfile": emptyFile, + "gradle/build.gradle": emptyFile, + "maven/pom.xml": emptyFile, + "Dockerfile": emptyFile, }, force: false, expectedConfigs: []string{ @@ -163,6 +164,7 @@ func TestWalk(t *testing.T) { "deploy/Dockerfile", "deploy/Dockerfile.dev", "deploy/dev.Dockerfile", + "deploy/test.dockerfile", }, shouldErr: false, }, @@ -346,7 +348,7 @@ deploy: } func fakeValidateDockerfile(path string) bool { - return strings.Contains(path, "Dockerfile") + return strings.Contains(strings.ToLower(path), "dockerfile") } func fakeValidateJibConfig(path string) []jib.ArtifactConfig {