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

:fix :(docs): changed env PODMAN_BIN to CONTAINER_TOOL #305

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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
9 changes: 7 additions & 2 deletions cmd/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (

type Config struct {
RootCommandName string `env:"CMD_NAME" default:"kantra"`
ContainerBinary string `env:"CONTAINER_TOOL" default:"/usr/bin/podman"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is failing because this field will need to also be updated where it is being accessed in the rest of the project. This will be where the different commands run. Please let me know if you have any questions on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, Any particular directory this should be pointing to as default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of the latest changes I removed the default path.

PodmanBinary string `env:"PODMAN_BIN" default:"/usr/bin/podman"`
RunnerImage string `env:"RUNNER_IMG" default:"quay.io/konveyor/kantra"`
RunLocal bool `env:"RUN_LOCAL"`
Expand Down Expand Up @@ -53,8 +54,8 @@ func (c *Config) Load() error {
}

func (c *Config) loadDefaultPodmanBin() error {
// Respect existing PODMAN_BIN setting.
if os.Getenv("PODMAN_BIN") != "" {
// Respect existing CONTAINER_TOOL setting.
if os.Getenv("CONTAINER_TOOL") != "" || os.Getenv("PODMAN_BIN") != "" {
Copy link
Collaborator

@eemcmullan eemcmullan Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check should first look for CONTAINER_TOOL, and then PODMAN_BIN after, only if the former is empty, so CONTAINER_TOOL takes priority.

For the Config struct, we do not need PodmanBinary any longer - just ContainerBinary. This field is used throughout the rest of the project to start the different commands, as the commands run in containers. For example, an analyze command will look something like /usr/bin/podman run --entrypoint <analyzer_bin>.... <image>... where /usr/bin/podman is set from this config struct. You can see an example of this here: https://github.com/konveyor/kantra/blob/main/cmd/analyze.go#L1476

Once these commands are updated with the new struct field name, they should be able to run, and the CI testing should pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the review @eemcmullan. I have pushed the recent changes!

return nil
}
// Try to use podman. If it's not found, try to use docker.
Expand All @@ -77,6 +78,10 @@ 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.ContainerBinary {
os.Setenv("CONTAINER_TOOL", path)
return true, nil
}
if path != "" && path != c.PodmanBinary {
os.Setenv("PODMAN_BIN", path)
return true, nil
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: container tool not container runtime.

Container Runtimes are actually different things https://kubernetes.io/docs/setup/production-environment/container-runtimes/ and in this case we don't work with most container runtimes we work with a container tool which is IMO something different.

We can fix this on a follow up though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @shawn-hurley!

@eemcmullan do let me know if this PR needs any more changes

- `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=
Loading