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

Do not mount file for Java binaries & fix Go dep provider path #231

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
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
33 changes: 21 additions & 12 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,14 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
return err
}
foundProviders := []string{}
for _, c := range components {
log.Info("Got component", "component language", c.Languages, "path", c.Path)
for _, l := range c.Languages {
foundProviders = append(foundProviders, strings.ToLower(l.Name))
if analyzeCmd.isFileInput {
foundProviders = append(foundProviders, javaProvider)
} else {
for _, c := range components {
log.Info("Got component", "component language", c.Languages, "path", c.Path)
for _, l := range c.Languages {
foundProviders = append(foundProviders, strings.ToLower(l.Name))
}
}
}
containerNetworkName, err := analyzeCmd.createContainerNetwork()
Expand All @@ -162,7 +166,7 @@ func NewAnalyzeCmd(log logr.Logger) *cobra.Command {
return err
}
// share source app with provider and engine containers
containerVolName, err := analyzeCmd.createContainerVolume(analyzeCmd.input)
containerVolName, err := analyzeCmd.createContainerVolume()
if err != nil {
log.Error(err, "failed to create container volume")
return err
Expand Down Expand Up @@ -263,8 +267,6 @@ func (a *analyzeCommand) Validate() error {
if err != nil {
return fmt.Errorf("%w failed to get absolute path for input file %s", err, a.input)
}
// make sure we mount a file and not a dir
SourceMountPath = path.Join(SourceMountPath, filepath.Base(a.input))
a.isFileInput = true
}
if a.mode != string(provider.FullAnalysisMode) &&
Expand Down Expand Up @@ -475,7 +477,7 @@ func (a *analyzeCommand) getConfigVolumes(providers []string, ports map[string]i
// only java provider can work with binaries, all others
// continue pointing to the directory instead of file
if a.isFileInput {
otherProvsMountPath = path.Dir(otherProvsMountPath)
SourceMountPath = path.Join(SourceMountPath, filepath.Base(a.input))
}

javaConfig := provider.Config{
Expand Down Expand Up @@ -515,7 +517,7 @@ func (a *analyzeCommand) getConfigVolumes(providers []string, ports map[string]i
ProviderSpecificConfig: map[string]interface{}{
"lspServerName": "generic",
"workspaceFolders": []string{fmt.Sprintf("file://%s", otherProvsMountPath)},
"dependencyProviderPath": "/usr/local/bin/go-dependency-provider",
"dependencyProviderPath": "/usr/local/bin/golang-dependency-provider",
provider.LspServerPathConfigKey: "/root/go/bin/gopls",
},
},
Expand Down Expand Up @@ -745,23 +747,30 @@ func (a *analyzeCommand) createContainerNetwork() (string, error) {
}

// TODO: create for each source input once accepting multiple apps is completed
func (a *analyzeCommand) createContainerVolume(sourceInput string) (string, error) {
func (a *analyzeCommand) createContainerVolume() (string, error) {
volName := container.RandomName()
input, err := filepath.Abs(a.input)
if err != nil {
return "", err
}
if a.isFileInput {
input = filepath.Dir(input)
}
args := []string{
"volume",
"create",
"--opt",
"type=none",
"--opt",
fmt.Sprintf("device=%v", sourceInput),
fmt.Sprintf("device=%v", input),
"--opt",
"o=bind",
volName,
}
cmd := exec.Command(Settings.PodmanBinary, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
err = cmd.Run()
if err != nil {
return "", err
}
Expand Down
Loading