Skip to content

Commit

Permalink
Do not mount file for Java binaries & fix Go dep provider path (#231)
Browse files Browse the repository at this point in the history
do not mount file for java binaries

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan authored May 10, 2024
1 parent 7410aa9 commit 10d5a7d
Showing 1 changed file with 21 additions and 12 deletions.
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

0 comments on commit 10d5a7d

Please sign in to comment.