Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile detector will only check files containing "Dockerfile" in the name #3499

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/skaffold/initializer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I've also seen a lot of *.dockerfile out there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, it would be better to make it case insensitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made it case insensitive and updated test to cover this case.

if docker.Validate(path) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also check in docker.Validate(path) if there is some python-ish code after from ... (like import <name>).

WDYT @dgageot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that Dockerfile validator should be aware of python-ish code constructs.
It's responsibility to validate Dockerfile and it does that by validating commands. Validating arguments would be too much overhead IMO.

results := []InitBuilder{docker.ArtifactConfig{File: path}}
return results, true
}
}

// TODO: Remove backwards compatibility if statement (not entire block)
Expand Down
22 changes: 13 additions & 9 deletions pkg/skaffold/initializer/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -159,6 +161,8 @@ func TestWalk(t *testing.T) {
expectedPaths: []string{
"Dockerfile",
"deploy/Dockerfile",
"deploy/Dockerfile.dev",
"deploy/dev.Dockerfile",
},
shouldErr: false,
},
Expand Down Expand Up @@ -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 {
Expand Down