Skip to content

skaffold init and buildpacks: skip dependencies #3758

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

Merged
merged 2 commits into from
Feb 28, 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
21 changes: 19 additions & 2 deletions pkg/skaffold/build/buildpacks/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package buildpacks

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
)
Expand Down Expand Up @@ -69,7 +71,22 @@ func (c ArtifactConfig) Path() string {

// validate checks if a file is a valid Buildpack configuration.
func validate(path string) bool {
name := filepath.Base(path)
switch filepath.Base(path) {
case "package.json":
return !hasParent(path, "node_modules")
Copy link
Contributor

Choose a reason for hiding this comment

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

how about using filepath.Match instead?

case "go.mod":
return !hasParent(path, "vendor")
default:
return false
}
}

func hasParent(path, parent string) bool {
for _, p := range strings.Split(path, string(os.PathSeparator)) {
if p == parent {
return true
}
}

return name == "package.json" || name == "go.mod"
return false
}
16 changes: 13 additions & 3 deletions pkg/skaffold/build/buildpacks/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,27 @@ func TestValidate(t *testing.T) {
}{
{
description: "NodeJS",
path: "path/to/package.json",
path: filepath.Join("path", "to", "package.json"),
Copy link
Contributor

Choose a reason for hiding this comment

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

just for completeness add corner test cases for
go.mod, package.json -> i.e. no filepath.Base = empty string
and somedir/vendor/go.mod -> i.e vendor not first parent.

expectedValid: true,
},
{
description: "NodeJS (ignored)",
path: filepath.Join("node_modules", "package.json"),
expectedValid: false,
},
{
description: "Go",
path: "path/to/go.mod",
path: filepath.Join("path", "to", "go.mod"),
expectedValid: true,
},
{
description: "Go (ignored)",
path: filepath.Join("vendor", "go.mod"),
expectedValid: false,
},
{
description: "Unknown language",
path: "path/to/something.txt",
path: filepath.Join("path", "to", "something.txt"),
expectedValid: false,
},
}
Expand Down