Skip to content

Commit

Permalink
Fix Java binary mount path (konveyor#426)
Browse files Browse the repository at this point in the history
fix java binary mount path

Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Feb 10, 2025
1 parent d97d984 commit d7de9e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
25 changes: 21 additions & 4 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"path"
"runtime"

"gopkg.in/yaml.v2"

"path/filepath"
"slices"
"strings"
Expand All @@ -28,7 +30,6 @@ import (
"github.com/konveyor/analyzer-lsp/provider"
"github.com/phayes/freeport"
"go.lsp.dev/uri"
"gopkg.in/yaml.v2"

"github.com/spf13/cobra"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -1158,7 +1159,23 @@ func (a *analyzeCommand) createContainerVolume() (string, error) {
return "", err
}
if a.isFileInput {
input = filepath.Dir(input)
//create temp dir and move bin file to mount
file := filepath.Base(input)
tempDir, err := os.MkdirTemp("", "java-bin-")
if err != nil {
a.log.V(1).Error(err, "failed creating temp dir", "dir", tempDir)
return "", err
}
a.log.V(1).Info("created temp directory for Java input file", "dir", tempDir)
// for cleanup
a.tempDirs = append(a.tempDirs, tempDir)

err = CopyFileContents(input, filepath.Join(tempDir, file))
if err != nil {
a.log.V(1).Error(err, "failed copying binary file")
return "", err
}
input = tempDir
}
if runtime.GOOS == "windows" {
// TODO(djzager): Thank ChatGPT
Expand Down Expand Up @@ -1249,7 +1266,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(args...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
container.WithCleanup(false),
container.WithName(fmt.Sprintf("provider-%v", container.RandomName())),
container.WithNetwork(networkName),
)
Expand All @@ -1274,7 +1291,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(args...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
container.WithCleanup(false),
container.WithName(fmt.Sprintf("provider-%v", container.RandomName())),
container.WithNetwork(fmt.Sprintf("container:%v", a.providerContainerNames[0])),
)
Expand Down
11 changes: 11 additions & 0 deletions cmd/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func (a *analyzeCommand) RmProviderContainers(ctx context.Context) error {
"container", con)
continue
}
cmd = exec.CommandContext(
ctx,
Settings.ContainerBinary,
"rm", con)
a.log.V(1).Info("removing provider container", "container", con)
err = cmd.Run()
if err != nil {
a.log.V(1).Error(err, "failed to remove container",
"container", con)
continue
}
}
return nil
}
Expand Down

0 comments on commit d7de9e5

Please sign in to comment.