Skip to content

Commit

Permalink
fix java binary mount path
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Feb 6, 2025
1 parent 23bce00 commit b7259ca
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"gopkg.in/yaml.v2"
"io"
"io/fs"
"os"
Expand All @@ -15,6 +14,8 @@ import (
"path"
"runtime"

"gopkg.in/yaml.v2"

"path/filepath"
"slices"
"strings"
Expand Down Expand Up @@ -872,7 +873,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 @@ -897,7 +898,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 (c *AnalyzeCommandContext) RmProviderContainers(ctx context.Context) error
"container", con)
continue
}
cmd = exec.CommandContext(
ctx,
Settings.ContainerBinary,
"rm", con)
c.log.V(1).Info("removing provider container", "container", con)
err = cmd.Run()
if err != nil {
c.log.V(1).Error(err, "failed to remove container",
"container", con)
continue
}
}
return nil
}
Expand Down
30 changes: 24 additions & 6 deletions cmd/command-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package cmd

import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/devfile/alizer/pkg/apis/model"
"github.com/go-logr/logr"
"github.com/konveyor-ecosystem/kantra/pkg/container"
"github.com/konveyor/analyzer-lsp/engine"
"github.com/phayes/freeport"
"gopkg.in/yaml.v2"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)

type AnalyzeCommandContext struct {
Expand Down Expand Up @@ -189,8 +190,25 @@ func (c *AnalyzeCommandContext) createContainerVolume(inputPath string) (string,
if err != nil {
return "", err
}

if c.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 {
c.log.V(1).Error(err, "failed creating temp dir", "dir", tempDir)
return "", err
}
c.log.V(1).Info("created temp directory for Java input file", "dir", tempDir)
// for cleanup
c.tempDirs = append(c.tempDirs, tempDir)

err = CopyFileContents(input, filepath.Join(tempDir, file))
if err != nil {
c.log.V(1).Error(err, "failed copying binary file")
return "", err
}
input = tempDir
}
if runtime.GOOS == "windows" {
// TODO(djzager): Thank ChatGPT
Expand Down

0 comments on commit b7259ca

Please sign in to comment.