Skip to content

Commit

Permalink
enable finding alternative builders nested under Jib projects
Browse files Browse the repository at this point in the history
  • Loading branch information
balopat committed Feb 10, 2020
1 parent a5f007f commit 2682ad6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pkg/skaffold/initializer/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ func TestAnalyze(t *testing.T) {
"k8pod.yml": validK8sManifest,
"gradle/build.gradle": emptyFile,
"gradle/subproject/build.gradle": emptyFile,
"gradle/subproject/Dockerfile": emptyFile,
"maven/asubproject/pom.xml": emptyFile,
"maven/asubproject/Dockerfile": emptyFile,
"maven/pom.xml": emptyFile,
},
config: initconfig.Config{
Expand All @@ -153,7 +155,9 @@ func TestAnalyze(t *testing.T) {
},
expectedPaths: []string{
"gradle/build.gradle",
"gradle/subproject/Dockerfile",
"maven/pom.xml",
"maven/asubproject/Dockerfile",
},
shouldErr: false,
},
Expand Down
19 changes: 10 additions & 9 deletions pkg/skaffold/initializer/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,24 @@ type builderAnalyzer struct {
buildpacksBuilder string
foundBuilders []InitBuilder

parentDirToStopFindBuilders string
parentDirToStopFindJibSettings string
}

func (a *builderAnalyzer) analyzeFile(filePath string) error {
if a.findBuilders && (a.parentDirToStopFindBuilders == "" || a.parentDirToStopFindBuilders == a.currentDir) {
builderConfigs, continueSearchingBuilders := a.detectBuilders(filePath)
if a.findBuilders {
lookForJib := a.parentDirToStopFindJibSettings == "" || a.parentDirToStopFindJibSettings == a.currentDir
builderConfigs, lookForJib := a.detectBuilders(filePath, lookForJib)
a.foundBuilders = append(a.foundBuilders, builderConfigs...)
if !continueSearchingBuilders {
a.parentDirToStopFindBuilders = a.currentDir
if !lookForJib {
a.parentDirToStopFindJibSettings = a.currentDir
}
}
return nil
}

func (a *builderAnalyzer) exitDir(dir string) {
if a.parentDirToStopFindBuilders == dir {
a.parentDirToStopFindBuilders = ""
if a.parentDirToStopFindJibSettings == dir {
a.parentDirToStopFindJibSettings = ""
}
}

Expand Down Expand Up @@ -102,9 +103,9 @@ func findExactlyOnceMatchingBuilder(builderConfigs []InitBuilder, image string)
// detectBuilders checks if a path is a builder config, and if it is, returns the InitBuilders representing the
// configs. Also returns a boolean marking search completion for subdirectories (true = subdirectories should
// continue to be searched, false = subdirectories should not be searched for more builders)
func (a *builderAnalyzer) detectBuilders(path string) ([]InitBuilder, bool) {
func (a *builderAnalyzer) detectBuilders(path string, detectJib bool) ([]InitBuilder, bool) {
// TODO: Remove backwards compatibility if statement (not entire block)
if a.enableJibInit {
if a.enableJibInit && detectJib {
// Check for jib
if builders := jib.Validate(path); builders != nil {
results := make([]InitBuilder, len(builders))
Expand Down

0 comments on commit 2682ad6

Please sign in to comment.