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

special character < is escaped #836

Open
gpongelli opened this issue Jul 9, 2024 · 4 comments
Open

special character < is escaped #836

gpongelli opened this issue Jul 9, 2024 · 4 comments
Labels

Comments

@gpongelli
Copy link

Current Behavior

Hi,
I'm trying to run hadolint tool within nox session in following way, as per their docs:

    session.run(
            "podman",
            "run",
            "--rm",
            "-i",
            "ghcr.io/hadolint/hadolint",
            "<",
            "Dockerfile",
            external=True,
        )

when the session is executed, on terminal log I get exit code 127 due to < charater escaped:

nox > podman run --rm ghcr.io/hadolint/hadolint '<' Dockerfile
Error: preparing container eb84b95424e737867600007dcc40c53d6e653b36dd8b54b5b36461f99da22c5c for attach: crun: executable file `<` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found
nox > Command podman run --rm ghcr.io/hadolint/hadolint '<' Dockerfile failed with exit code 127
nox > Session container failed.

Expected Behavior

I would be able to execute that command passing the Dockerfile to docker container as it expects.

Steps To Reproduce

No response

Environment

- OS: windows 11
- Python: 3.12
- Nox: 2024.4.15

Anything else?

on activated venv, I can manually launch the same command and it works due to < not escaped:

(....-py3.12) PS C:\...\PyCharmProjects\...> cat .\Dockerfile | podman run --rm -i hadolint/hadolint      
-:10 DL4000 error: MAINTAINER is deprecated
-:13 DL3042 warning: Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
-:13 DL3013 warning: Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>`
-:16 DL3027 warning: Do not use apt as it is meant to be a end-user tool, use apt-get or apt-cache instead
-:31 DL3042 warning: Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
-:31 DL3013 warning: Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>`
-:37 DL3042 warning: Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`
@gpongelli gpongelli added the bug label Jul 9, 2024
@gpongelli
Copy link
Author

I found a workaround passing the Dockerfile as volume, so removing the need to use < character:

    session.run(
        "podman",
        "run",
        "--rm",
        "-it",
        "-v",
        "Dockerfile:/Dockerfile",
        "-v",
        "hadolint.yaml:/hadolint.yaml",
        "ghcr.io/hadolint/hadolint",
        "hadolint",
        "--config",
        "/hadolint.yaml",
        "/Dockerfile",
        external=True,
    )

hope this could help other people too.

@cjolowicz
Copy link
Collaborator

Alternatively, you could wrap the command in a shell. See https://nox.thea.codes/en/stable/config.html#nox.sessions.Session.run . The < character is shell syntax for redirecting standard input. (The session.run function does not wrap commands in a shell, and it does not currently offer a way to redirect standard input.)

@gpongelli
Copy link
Author

Hi @cjolowicz ,
what do you mean with "wrap the command in a shell" ? something like bash -c podman ... (I'm not aware of windows eqivalent) ?
I'm already doing session.run command to invoke podman.

Thanks

@ember91
Copy link
Contributor

ember91 commented Aug 3, 2024

In short, session.run doesn't run in a shell and input redirection, i.e. <, is a feature of the shell.

I don't think this is a bug with nox.

A common way to fix that is to run it in a shell. For example with bash as the shell:

session.run("bash", "-c", "podman run ...")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants