diff --git a/cmd/analyze.go b/cmd/analyze.go index f3c657c..fdeff2e 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -309,6 +309,7 @@ func (a *analyzeCommand) ListLabels(ctx context.Context) error { container.WithEnv(runMode, runModeContainer), container.WithVolumes(volumes), container.WithEntrypointBin(fmt.Sprintf("/usr/local/bin/%s", Settings.RootCommandName)), + container.WithContainerToolBin(Settings.PodmanBinary), container.WithEntrypointArgs(args...), container.WithCleanup(a.cleanup), ) @@ -753,6 +754,7 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string) e container.WithStderr(analysisLog), container.WithEntrypointArgs(args...), container.WithEntrypointBin("/usr/bin/entrypoint.sh"), + container.WithContainerToolBin(Settings.PodmanBinary), container.WithCleanup(a.cleanup), ) if err != nil { @@ -851,6 +853,7 @@ func (a *analyzeCommand) GenerateStaticReport(ctx context.Context) error { container.WithImage(Settings.RunnerImage), container.WithLog(a.log.V(1)), container.WithEntrypointBin("/bin/sh"), + container.WithContainerToolBin(Settings.PodmanBinary), container.WithEntrypointArgs(staticReportCmd...), container.WithVolumes(volumes), container.WithcFlag(true), @@ -1027,6 +1030,7 @@ func (a *analyzeCommand) ConvertXML(ctx context.Context) (string, error) { container.WithVolumes(volumes), container.WithEntrypointArgs(args...), container.WithEntrypointBin("/usr/local/bin/windup-shim"), + container.WithContainerToolBin(Settings.PodmanBinary), container.WithCleanup(a.cleanup), ) if err != nil { diff --git a/cmd/openrewrite.go b/cmd/openrewrite.go index f0445a9..65c8e14 100644 --- a/cmd/openrewrite.go +++ b/cmd/openrewrite.go @@ -158,6 +158,7 @@ func (o *openRewriteCommand) Run(ctx context.Context) error { container.WithLog(o.log.V(1)), container.WithEntrypointArgs(args...), container.WithEntrypointBin("/usr/bin/openrewrite_entrypoint.sh"), + container.WithContainerToolBin(Settings.PodmanBinary), container.WithVolumes(volumes), container.WithWorkDir("/tmp/source-app/input"), container.WithCleanup(o.cleanup), diff --git a/cmd/shimconvert.go b/cmd/shimconvert.go index 9f10cd8..692cc6d 100644 --- a/cmd/shimconvert.go +++ b/cmd/shimconvert.go @@ -172,6 +172,7 @@ func (w *windupShimCommand) Run(ctx context.Context) error { container.WithStderr(shimLog), container.WithEntrypointArgs(args...), container.WithEntrypointBin("/usr/local/bin/windup-shim"), + container.WithContainerToolBin(Settings.PodmanBinary), container.WithCleanup(w.cleanup), ) if err != nil { diff --git a/pkg/container/container.go b/pkg/container/container.go index 195cc3a..127f45c 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -29,11 +29,11 @@ type container struct { // whether to delete container after run() cleanup bool // map of source -> dest paths to mount - volumes map[string]string - cFlag bool - log logr.Logger - containerRuntimeBin string - reproducerCmd *string + volumes map[string]string + cFlag bool + log logr.Logger + containerToolBin string + reproducerCmd *string } type Option func(c *container) @@ -56,6 +56,12 @@ func WithEntrypointBin(b string) Option { } } +func WithContainerToolBin(r string) Option { + return func(c *container) { + c.containerToolBin = r + } +} + func WithEntrypointArgs(args ...string) Option { return func(c *container) { c.entrypointArgs = args @@ -128,14 +134,14 @@ func randomName() string { func NewContainer() *container { return &container{ - image: "", - containerRuntimeBin: "podman", - entrypointArgs: []string{}, - volumes: make(map[string]string), - stdout: []io.Writer{os.Stdout}, - env: map[string]string{}, - stderr: []io.Writer{os.Stderr}, - name: randomName(), + image: "", + containerToolBin: "podman", + entrypointArgs: []string{}, + volumes: make(map[string]string), + stdout: []io.Writer{os.Stdout}, + env: map[string]string{}, + stderr: []io.Writer{os.Stderr}, + name: randomName(), // by default, remove the container after run() cleanup: true, cFlag: false, @@ -148,8 +154,8 @@ func (c *container) Run(ctx context.Context, opts ...Option) error { for _, opt := range opts { opt(c) } - if c.image == "" || c.containerRuntimeBin == "" { - return fmt.Errorf("image and containerRuntimeBin must be set") + if c.image == "" || c.containerToolBin == "" { + return fmt.Errorf("image and containerToolBin must be set") } args := []string{"run"} os := runtime.GOOS @@ -192,9 +198,9 @@ func (c *container) Run(ctx context.Context, opts ...Option) error { if c.reproducerCmd != nil { reproducer := strings.ReplaceAll(strings.Join(args, " "), " --rm", "") *c.reproducerCmd = fmt.Sprintf("%s %s", - c.containerRuntimeBin, reproducer) + c.containerToolBin, reproducer) } - cmd := exec.CommandContext(ctx, c.containerRuntimeBin, args...) + cmd := exec.CommandContext(ctx, c.containerToolBin, args...) errBytes := &bytes.Buffer{} cmd.Stdout = nil cmd.Stderr = errBytes @@ -205,8 +211,8 @@ func (c *container) Run(ctx context.Context, opts ...Option) error { cmd.Stderr = io.MultiWriter( append(c.stderr, errBytes)...) } - c.log.Info("executing podman command", - "podman", c.containerRuntimeBin, "cmd", c.entrypointBin, "args", strings.Join(args, " ")) + c.log.Info("executing command", + "container tool", c.containerToolBin, "cmd", c.entrypointBin, "args", strings.Join(args, " ")) err = cmd.Run() if err != nil { c.log.Error(err, "container run error") @@ -221,9 +227,9 @@ func (c *container) Run(ctx context.Context, opts ...Option) error { func (c *container) Rm(ctx context.Context) error { cmd := exec.CommandContext( ctx, - c.containerRuntimeBin, + c.containerToolBin, "rm", c.name) c.log.Info("removing container", - "podman", c.containerRuntimeBin, "name", c.name) + "container tool", c.containerToolBin, "name", c.name) return cmd.Run() }