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

Override container runtime for commands #181

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.WithContainerRuntimeBin(os.Getenv("PODMAN_BIN")),
eemcmullan marked this conversation as resolved.
Show resolved Hide resolved
container.WithEntrypointArgs(args...),
container.WithCleanup(a.cleanup),
)
Expand Down Expand Up @@ -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.WithContainerRuntimeBin(os.Getenv("PODMAN_BIN")),
container.WithCleanup(a.cleanup),
)
if err != nil {
Expand Down Expand Up @@ -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.WithContainerRuntimeBin(os.Getenv("PODMAN_BIN")),
container.WithEntrypointArgs(staticReportCmd...),
container.WithVolumes(volumes),
container.WithcFlag(true),
Expand Down Expand Up @@ -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.WithContainerRuntimeBin(os.Getenv("PODMAN_BIN")),
container.WithCleanup(a.cleanup),
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/openrewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.WithContainerRuntimeBin(os.Getenv("PODMAN_BIN")),
container.WithVolumes(volumes),
container.WithWorkDir("/tmp/source-app/input"),
container.WithCleanup(o.cleanup),
Expand Down
1 change: 1 addition & 0 deletions cmd/shimconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.WithContainerRuntimeBin(os.Getenv("PODMAN_BIN")),
container.WithCleanup(w.cleanup),
)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func WithEntrypointBin(b string) Option {
}
}

func WithContainerRuntimeBin(r string) Option {
return func(c *container) {
c.containerRuntimeBin = r
}
}

func WithEntrypointArgs(args ...string) Option {
return func(c *container) {
c.entrypointArgs = args
Expand Down Expand Up @@ -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 runtime", c.containerRuntimeBin, "cmd", c.entrypointBin, "args", strings.Join(args, " "))
err = cmd.Run()
if err != nil {
c.log.Error(err, "container run error")
Expand Down
Loading