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

CP #426: Fix Java binary mount path #427

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
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
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