Repository: ClickHouse/ClickHouse
File: ci/praktika/runner.py (Python)

Code before:
                elif Utils.is_amd():
                    docker_tag += "_amd"
                else:
                    raise RuntimeError("Unsupported CPU architecture")

            docker = docker or f"{docker_name}:{docker_tag}"
            current_dir = os.getcwd()
            workdir = f"--workdir={current_dir}"
            for setting in settings:
                if setting.startswith("--volume"):
                    volume = setting.removeprefix("--volume=").split(":")[0]
                    if not Path(volume).exists():
                        print(
                            "WARNING: Create mount dir point in advance to have the same owner"
                        )
                        Shell.check(f"mkdir -p {volume}", verbose=True, strict=True)
                elif setting.startswith("--workdir"):
                    print(
                        f"NOTE: Job [{job.name}] use custom workdir - praktika won't control workdir"
                    )
                    workdir = ""
            if not Shell.check(
                "if docker ps -a --format '{{.Names}}' | grep -q praktika; then docker rm -f praktika; fi",
                verbose=True,
                strict=True,
            ):
                raise RuntimeError("Failed to remove existing docker container 'praktika'")
            if job.enable_gh_auth:
                # pass gh auth seamlessly into the docker container
                gh_mount = "--volume ~/.config/gh:/ghconfig -e GH_CONFIG_DIR=/ghconfig"
            else:
                gh_mount = ""
            # enable tty mode & interactive for docker if we have real tty
            tty = ""
            if preserve_stdio:
                tty = "-it"

            # mount extra paths provided via --path_X  if they are outside current directory
            extra_mounts = ""
            for p_ in [path, path_1]:
                if p_ and Path(p_).exists() and p_.startswith("/"):
                    extra_mounts += f" --volume {p_}:{p_}"
            cmd = f"docker run {tty} --rm --name praktika {'--user $(id -u):$(id -g)' if not from_root else ''} -e PYTHONUNBUFFERED=1 -e PYTHONPATH='.:./ci' --volume ./:{current_dir} {extra_mounts} {gh_mount} {workdir} {' '.join(settings)} {docker} {job.command}"
        else:
            cmd = job.command
            python_path = os.getenv("PYTHONPATH", ":")
            os.environ["PYTHONPATH"] = f".:{python_path}"

        if param:
            print(f"Custom --param [{param}] will be passed to job's script")
            cmd += f" --param {param}"

Review comment (bug):
`Shell.check(..., strict=True)` will raise on failure rather than returning `False`, so the surrounding `if not Shell.check(...): raise RuntimeError(...)` is effectively unreachable. Also, `grep -q praktika` can match other container names (e.g. `praktika_old`) and then `docker rm -f praktika` will fail and raise due to `strict=True`. Use an exact match (e.g. `grep -qx 'praktika'`) or a `docker inspect praktika` existence check, and either rely on `strict=True` without an extra `if`, or set `strict=False` and keep the explicit error handling.

Code after:
                elif Utils.is_amd():
                    docker_tag += "_amd"
                else:
                    raise RuntimeError("Unsupported CPU architecture")

            docker = docker or f"{docker_name}:{docker_tag}"
            current_dir = os.getcwd()
            workdir = f"--workdir={current_dir}"
            for setting in settings:
                if setting.startswith("--volume"):
                    volume = setting.removeprefix("--volume=").split(":")[0]
                    if not Path(volume).exists():
                        print(
                            "WARNING: Create mount dir point in advance to have the same owner"
                        )
                        Shell.check(f"mkdir -p {volume}", verbose=True, strict=True)
                elif setting.startswith("--workdir"):
                    print(
                        f"NOTE: Job [{job.name}] use custom workdir - praktika won't control workdir"
                    )
                    workdir = ""
            if not Shell.check(
                "if docker ps -a --format '{{.Names}}' | grep -qx praktika; then docker rm -f praktika; fi",
                verbose=True,
            ):
                raise RuntimeError("Failed to remove existing docker container 'praktika'")
            if job.enable_gh_auth:
                # pass gh auth seamlessly into the docker container
                gh_mount = "--volume ~/.config/gh:/ghconfig -e GH_CONFIG_DIR=/ghconfig"
            else:
                gh_mount = ""
            # enable tty mode & interactive for docker if we have real tty
            tty = ""
            if preserve_stdio:
                tty = "-it"

            # mount extra paths provided via --path_X  if they are outside current directory
            extra_mounts = ""
            for p_ in [path, path_1]:
                if p_ and Path(p_).exists() and p_.startswith("/"):
                    extra_mounts += f" --volume {p_}:{p_}"
            cmd = f"docker run {tty} --rm --name praktika {'--user $(id -u):$(id -g)' if not from_root else ''} -e PYTHONUNBUFFERED=1 -e PYTHONPATH='.:./ci' --volume ./:{current_dir} {extra_mounts} {gh_mount} {workdir} {' '.join(settings)} {docker} {job.command}"
        else:
            cmd = job.command
            python_path = os.getenv("PYTHONPATH", ":")
            os.environ["PYTHONPATH"] = f".:{python_path}"

        if param:
            print(f"Custom --param [{param}] will be passed to job's script")
            cmd += f" --param {param}"
        if test: