From b053120577d84dd106b3e673d92558e426010d7e Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 15 Jun 2023 11:59:24 +1000 Subject: [PATCH] bug: component detection with context Fixes RHTAPBUGS-418 --- pkg/devfile/detect.go | 8 ++++---- pkg/devfile/devfile.go | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/devfile/detect.go b/pkg/devfile/detect.go index d665d5318..3e8ac095b 100644 --- a/pkg/devfile/detect.go +++ b/pkg/devfile/detect.go @@ -47,7 +47,6 @@ type AlizerClient struct { // Map 3 returns a context to the Dockerfile uri or a matched DockerfileURL from the devfile registry if no Dockerfile is present in the context // Map 4 returns a context to the list of ports that were detected by alizer in the source code, at that given context func search(log logr.Logger, a Alizer, localpath string, devfileRegistryURL string, source appstudiov1alpha1.GitSource) (map[string][]byte, map[string]string, map[string]string, map[string][]int, error) { - devfileMapFromRepo := make(map[string][]byte) devfilesURLMapFromRepo := make(map[string]string) dockerfileContextMapFromRepo := make(map[string]string) @@ -63,7 +62,8 @@ func search(log logr.Logger, a Alizer, localpath string, devfileRegistryURL stri isDevfilePresent := false isDockerfilePresent := false curPath := path.Join(localpath, f.Name()) - context := f.Name() + dirName := f.Name() + context := path.Join(source.Context, f.Name()) files, err := ioutil.ReadDir(curPath) if err != nil { return nil, nil, nil, nil, err @@ -74,7 +74,7 @@ func search(log logr.Logger, a Alizer, localpath string, devfileRegistryURL stri /* #nosec G304 -- false positive, filename is not based on user input*/ devfilePath := path.Join(curPath, f.Name()) // Set the proper devfile URL for the detected devfile - updatedLink, err := UpdateGitLink(source.URL, source.Revision, path.Join(source.Context, path.Join(context, f.Name()))) + updatedLink, err := UpdateGitLink(source.URL, source.Revision, path.Join(source.Context, path.Join(dirName, f.Name()))) if err != nil { return nil, nil, nil, nil, err } @@ -105,7 +105,7 @@ func search(log logr.Logger, a Alizer, localpath string, devfileRegistryURL stri devfilePath := path.Join(hiddenDirPath, f.Name()) // Set the proper devfile URL for the detected devfile - updatedLink, err := UpdateGitLink(source.URL, source.Revision, path.Join(source.Context, path.Join(context, HiddenDevfileDir, f.Name()))) + updatedLink, err := UpdateGitLink(source.URL, source.Revision, path.Join(source.Context, path.Join(dirName, HiddenDevfileDir, f.Name()))) if err != nil { return nil, nil, nil, nil, err } diff --git a/pkg/devfile/devfile.go b/pkg/devfile/devfile.go index 8e56e8160..a0f2365da 100644 --- a/pkg/devfile/devfile.go +++ b/pkg/devfile/devfile.go @@ -851,6 +851,7 @@ func DownloadDevfileAndDockerfile(url string) ([]byte, string, []byte, string) { // Map 3 returns a context to the Dockerfile uri or a matched DockerfileURL from the devfile registry if no Dockerfile/Containerfile is present in the context // Map 4 returns a context to the list of ports that were detected by alizer in the source code, at that given context func ScanRepo(log logr.Logger, a Alizer, localpath string, devfileRegistryURL string, source appstudiov1alpha1.GitSource) (map[string][]byte, map[string]string, map[string]string, map[string][]int, error) { + return search(log, a, localpath, devfileRegistryURL, source) }