Skip to content

Commit

Permalink
:fix :(docs): changed env PODMAN_BIN to CONTAINER_TOOL (konveyor#305)
Browse files Browse the repository at this point in the history
* :fix :(docs): changed env PODMAN_BIN to CONTAINER_TOOL

Signed-off-by: soham4abc <[email protected]>

* :fix :(bug): added backward compatibility for the env PODMAN_BIN

Signed-off-by: soham4abc <[email protected]>

* :fix :(env) : formatting changes

Signed-off-by: soham4abc <[email protected]>

* :fix: :(bug): removed default path for CONTAINER_TOOL

Signed-off-by: soham4abc <[email protected]>

* :bug :(env): changed default path for CONTAINER_TOOL

Signed-off-by: soham4abc <[email protected]>

* :bug :(env): changed default path for PODMAN_BIN

Signed-off-by: soham4abc <[email protected]>

* :bug :(env): updated the config struct and set CONTAINER_TOOL as priority

Signed-off-by: soham4abc <[email protected]>

---------

Signed-off-by: soham4abc <[email protected]>
  • Loading branch information
soham4abc authored Aug 12, 2024
1 parent 766454b commit 9da4a1f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Kantra is a CLI that unifies analysis and transformation capabilities of Konveyo

_Podman 4+_ is required to run kantra. By default, it is configured to use the podman executable available on the host.

Although kantra is primarily tested with podman, _Docker Engine 24+_ or _Docker Desktop 4+_ can be used as an alternative. To use docker, set the environment variable `PODMAN_BIN` pointing to the docker executable's path:
Although kantra is primarily tested with podman, _Docker Engine 24+_ or _Docker Desktop 4+_ can be used as an alternative. To use docker, set the environment variable `CONTAINER_TOOL` pointing to the docker executable's path:

```sh
export PODMAN_BIN=/usr/bin/docker
export CONTAINER_TOOL=/usr/bin/docker
```

## Installation
Expand All @@ -46,7 +46,7 @@ e.g., `kantra_version=v0.4.0`.
Run:

```sh
${PODMAN_BIN:-podman} cp $(${PODMAN_BIN:-podman} create --name kantra-download quay.io/konveyor/kantra:${kantra_version:-latest}):/usr/local/bin/kantra . && ${PODMAN_BIN:-podman} rm kantra-download
${CONTAINER_TOOL:-podman} cp $(${CONTAINER_TOOL:-podman} create --name kantra-download quay.io/konveyor/kantra:${kantra_version:-latest}):/usr/local/bin/kantra . && ${CONTAINER_TOOL:-podman} rm kantra-download
```

#### Mac
Expand All @@ -57,7 +57,7 @@ you need to start a podman machine prior to running any podman commands (see [Se
Once a machine is started, run:

```sh
${PODMAN_BIN:-podman} cp $(${PODMAN_BIN:-podman} create --name kantra-download quay.io/konveyor/kantra:${kantra_version:-latest}):/usr/local/bin/darwin-kantra . && ${PODMAN_BIN:-podman} rm kantra-download
${CONTAINER_TOOL:-podman} cp $(${CONTAINER_TOOL:-podman} create --name kantra-download quay.io/konveyor/kantra:${kantra_version:-latest}):/usr/local/bin/darwin-kantra . && ${CONTAINER_TOOL:-podman} rm kantra-download
```

#### Windows
Expand All @@ -68,7 +68,7 @@ you need to start a podman machine prior to running any podman commands (see [Se
Once a machine is started, run:

```sh
${PODMAN_BIN:-podman} cp $(${PODMAN_BIN:-podman} create --name kantra-download quay.io/konveyor/kantra:${kantra_version:-latest}):/usr/local/bin/windows-kantra . && ${PODMAN_BIN:-podman} rm kantra-download
${CONTAINER_TOOL:-podman} cp $(${CONTAINER_TOOL:-podman} create --name kantra-download quay.io/konveyor/kantra:${kantra_version:-latest}):/usr/local/bin/windows-kantra . && ${CONTAINER_TOOL:-podman} rm kantra-download
```

> Ensure that you add the executable to the `PATH`.
Expand Down
40 changes: 20 additions & 20 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (a *analyzeCommand) fetchProviders(ctx context.Context, out io.Writer) erro
container.WithLog(a.log.V(1)),
container.WithEnv(runMode, runModeContainer),
container.WithEntrypointBin(fmt.Sprintf("/usr/local/bin/%s", Settings.RootCommandName)),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(args...),
container.WithStdout(out),
container.WithCleanup(a.cleanup),
Expand Down Expand Up @@ -689,7 +689,7 @@ func (a *analyzeCommand) fetchLabels(ctx context.Context, listSources, listTarge
container.WithEnv(runMode, runModeContainer),
container.WithVolumes(volumes),
container.WithEntrypointBin(fmt.Sprintf("/usr/local/bin/%s", Settings.RootCommandName)),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(args...),
container.WithStdout(out),
container.WithCleanup(a.cleanup),
Expand Down Expand Up @@ -1123,7 +1123,7 @@ func (a *analyzeCommand) createContainerNetwork() (string, error) {
networkName,
}

cmd := exec.Command(Settings.PodmanBinary, args...)
cmd := exec.Command(Settings.ContainerBinary, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
Expand Down Expand Up @@ -1172,7 +1172,7 @@ func (a *analyzeCommand) createContainerVolume() (string, error) {
"o=bind",
volName,
}
cmd := exec.Command(Settings.PodmanBinary, args...)
cmd := exec.Command(Settings.ContainerBinary, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
Expand Down Expand Up @@ -1224,7 +1224,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v
container.WithImage(init.image),
container.WithLog(a.log.V(1)),
container.WithVolumes(volumes),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(args...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
Expand All @@ -1248,7 +1248,7 @@ func (a *analyzeCommand) RunProviders(ctx context.Context, networkName string, v
container.WithImage(init.image),
container.WithLog(a.log.V(1)),
container.WithVolumes(volumes),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(args...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
Expand Down Expand Up @@ -1351,7 +1351,7 @@ func (a *analyzeCommand) RunAnalysisOverrideProviderSettings(ctx context.Context
container.WithEntrypointArgs(args...),
container.WithEntrypointBin("/usr/local/bin/konveyor-analyzer"),
container.WithNetwork("host"),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithCleanup(a.cleanup),
)
if err != nil {
Expand Down Expand Up @@ -1473,7 +1473,7 @@ func (a *analyzeCommand) RunAnalysis(ctx context.Context, xmlOutputDir string, v
container.WithEntrypointArgs(args...),
container.WithEntrypointBin("/usr/local/bin/konveyor-analyzer"),
container.WithNetwork(networkName),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithCleanup(a.cleanup),
)
if err != nil {
Expand Down Expand Up @@ -1620,7 +1620,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.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs(staticReportCmd...),
container.WithVolumes(volumes),
container.WithcFlag(true),
Expand Down Expand Up @@ -1816,7 +1816,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.WithContainerToolBin(Settings.ContainerBinary),
container.WithCleanup(a.cleanup),
)
if err != nil {
Expand Down Expand Up @@ -1982,7 +1982,7 @@ func (a *analyzeCommand) RmNetwork(ctx context.Context) error {
}
cmd := exec.CommandContext(
ctx,
Settings.PodmanBinary,
Settings.ContainerBinary,
"network",
"rm", a.networkName)
a.log.V(1).Info("removing container network",
Expand All @@ -1996,7 +1996,7 @@ func (a *analyzeCommand) RmVolumes(ctx context.Context) error {
}
cmd := exec.CommandContext(
ctx,
Settings.PodmanBinary,
Settings.ContainerBinary,
"volume",
"rm", a.volumeName)
a.log.V(1).Info("removing created volume",
Expand All @@ -2011,7 +2011,7 @@ func (a *analyzeCommand) RmProviderContainers(ctx context.Context) error {
// it will immediately be removed after it stops
cmd := exec.CommandContext(
ctx,
Settings.PodmanBinary,
Settings.ContainerBinary,
"stop", con)
a.log.V(1).Info("stopping container", "container", con)
err := cmd.Run()
Expand Down Expand Up @@ -2041,7 +2041,7 @@ func (a *analyzeCommand) getProviderLogs(ctx context.Context) error {

cmd := exec.CommandContext(
ctx,
Settings.PodmanBinary,
Settings.ContainerBinary,
"logs",
a.providerContainerNames[i])

Expand Down Expand Up @@ -2079,7 +2079,7 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
Network []string `json:"network"`
} `json:"plugins"`
}
cmd := exec.Command(Settings.PodmanBinary, []string{"system", "info", "--format=json"}...)
cmd := exec.Command(Settings.ContainerBinary, []string{"system", "info", "--format=json"}...)
out, err := cmd.Output()
if err != nil {
return err
Expand All @@ -2096,7 +2096,7 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {

// Create network
networkName := container.RandomName()
cmd = exec.Command(Settings.PodmanBinary, []string{"network", "create", "-d", "nat", networkName}...)
cmd = exec.Command(Settings.ContainerBinary, []string{"network", "create", "-d", "nat", networkName}...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
Expand Down Expand Up @@ -2139,7 +2139,7 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
container.WithVolumes(map[string]string{
input: "C:" + filepath.FromSlash(SourceMountPath),
}),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointArgs([]string{fmt.Sprintf("--port=%v", port)}...),
container.WithDetachedMode(true),
container.WithCleanup(a.cleanup),
Expand Down Expand Up @@ -2264,7 +2264,7 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
container.WithEntrypointArgs(args...),
container.WithEntrypointBin(`C:\app\konveyor-analyzer.exe`),
container.WithNetwork(networkName),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithCleanup(a.cleanup),
)
if err != nil {
Expand Down Expand Up @@ -2292,7 +2292,7 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
ctx,
container.WithImage(Settings.RunnerImage),
container.WithLog(a.log.V(1)),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointBin("powershell"),
container.WithEntrypointArgs("Copy-Item", `C:\app\static-report\`, "-Recurse", filepath.FromSlash(OutputPath)),
container.WithVolumes(volumes),
Expand All @@ -2314,7 +2314,7 @@ func (a *analyzeCommand) analyzeDotnetFramework(ctx context.Context) error {
ctx,
container.WithImage(Settings.RunnerImage),
container.WithLog(a.log.V(1)),
container.WithContainerToolBin(Settings.PodmanBinary),
container.WithContainerToolBin(Settings.ContainerBinary),
container.WithEntrypointBin(`C:\app\js-bundle-generator`),
container.WithEntrypointArgs(staticReportArgs...),
container.WithVolumes(volumes),
Expand Down
2 changes: 1 addition & 1 deletion cmd/openrewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +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.WithContainerToolBin(Settings.ContainerBinary),
container.WithVolumes(volumes),
container.WithWorkDir("/tmp/source-app/input"),
container.WithCleanup(o.cleanup),
Expand Down
11 changes: 7 additions & 4 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (

type Config struct {
RootCommandName string `env:"CMD_NAME" default:"kantra"`
PodmanBinary string `env:"PODMAN_BIN" default:"/usr/bin/podman"`
ContainerBinary string `env:"CONTAINER_TOOL" default:"/usr/bin/podman"`
RunnerImage string `env:"RUNNER_IMG" default:"quay.io/konveyor/kantra"`
RunLocal bool `env:"RUN_LOCAL"`
JavaProviderImage string `env:"JAVA_PROVIDER_IMG" default:"quay.io/konveyor/java-external-provider:latest"`
Expand Down Expand Up @@ -53,7 +53,10 @@ func (c *Config) Load() error {
}

func (c *Config) loadDefaultPodmanBin() error {
// Respect existing PODMAN_BIN setting.
// Respect existing CONTAINER_TOOL setting.
if os.Getenv("CONTAINER_TOOL") != "" {
return nil
}
if os.Getenv("PODMAN_BIN") != "" {
return nil
}
Expand All @@ -77,8 +80,8 @@ func (c *Config) trySetDefaultPodmanBin(file string) (found bool, err error) {
return false, err
}
// If file was found in PATH and it's not already going to be used, specify it in the env var.
if path != "" && path != c.PodmanBinary {
os.Setenv("PODMAN_BIN", path)
if path != "" && path != c.ContainerBinary {
os.Setenv("CONTAINER_TOOL", path)
return true, nil
}
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/shimconvert.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +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.WithContainerToolBin(Settings.ContainerBinary),
container.WithCleanup(w.cleanup),
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewTestCommand(log logr.Logger) *cobra.Command {
results, err := testing.NewRunner().Run(tests, testing.TestOptions{
RunLocal: Settings.RunLocal,
ContainerImage: Settings.RunnerImage,
ContainerToolBin: Settings.PodmanBinary,
ContainerToolBin: Settings.ContainerBinary,
ProgressPrinter: testing.PrintProgress,
Log: log.V(3),
})
Expand Down
6 changes: 3 additions & 3 deletions docs/developer.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
### Running kantra

Two environment variables control the container runtime and the kantra image: `PODMAN_BIN` and `RUNNER_IMG`:
- `PODMAN_BIN`: path to your container runtime (podman or docker)
Two environment variables control the container runtime and the kantra image: `CONTAINER_TOOL` and `RUNNER_IMG`:
- `CONTAINER_TOOL`: path to your container runtime (podman or docker)
- `RUNNER_IMG`: the tag of the kantra image to invoke

#### example:

`podman build -f Dockerfile -t kantra:dev`

`RUNNER_IMG=kantra:dev PODMAN_BIN=/usr/local/bin/podman go run main.go analyze --input=<path-to-src-application> --output=./output`
`RUNNER_IMG=kantra:dev CONTAINER_TOOL=/usr/local/bin/podman go run main.go analyze --input=<path-to-src-application> --output=./output`

#### Helpful flags:

Expand Down
1 change: 1 addition & 0 deletions env.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
# copy this file to `env.local` and source it in your bash session to use CLI

PODMAN_BIN=
CONTAINER_TOOL=
RUNNER_IMG=

0 comments on commit 9da4a1f

Please sign in to comment.