diff --git a/docker-run-cli/pyproject.toml b/docker-run-cli/pyproject.toml index f086878..74c0a84 100644 --- a/docker-run-cli/pyproject.toml +++ b/docker-run-cli/pyproject.toml @@ -28,7 +28,7 @@ requires-python = ">=3.7" [project.optional-dependencies] dev = ["build", "twine"] -docker-ros = ["docker-run-docker-ros>=1.0.1"] +docker-ros = ["docker-run-docker-ros>=1.0.3"] plugins = ["docker-run-cli[docker-ros]"] all = ["docker-run-cli[plugins]", "docker-run-cli[dev]"] diff --git a/docker-run-docker-ros/pyproject.toml b/docker-run-docker-ros/pyproject.toml index 8678337..df51309 100644 --- a/docker-run-docker-ros/pyproject.toml +++ b/docker-run-docker-ros/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "docker-run-docker-ros" -version = "1.0.2" +version = "1.0.3" description = "docker-run plugin for Docker images built by docker-ros" license = {file = "LICENSE"} readme = "README.md" diff --git a/docker-run-docker-ros/src/docker_run/plugins/docker_ros.py b/docker-run-docker-ros/src/docker_run/plugins/docker_ros.py index 63f920d..93f176a 100644 --- a/docker-run-docker-ros/src/docker_run/plugins/docker_ros.py +++ b/docker-run-docker-ros/src/docker_run/plugins/docker_ros.py @@ -6,7 +6,7 @@ from docker_run.plugins.plugin import Plugin -__version__ = "1.0.2" +__version__ = "1.0.3" class DockerRosPlugin(Plugin): @@ -33,10 +33,12 @@ def getRunFlags(cls, args: Dict[str, Any], unknown_args: List[str]) -> List[str] @classmethod def getExecFlags(cls, args: Dict[str, Any], unknown_args: List[str]) -> List[str]: flags = [] - is_docker_ros = (runCommand(f"docker exec {args['name']} printenv DOCKER_ROS")[0][:-1] == "1") - is_non_root = (len(runCommand(f"docker exec {args['name']} printenv DOCKER_UID")[0][:-1]) > 0) - if not args["no_user"] and is_docker_ros and is_non_root: - flags += cls.userExecFlags() + is_docker_user = False + docker_uid = runCommand(f"docker exec {args['name']} printenv DOCKER_UID || true")[0][:-1] + if len(docker_uid) > 0: + is_docker_user = (len(runCommand(f"docker exec {args['name']} id -u {docker_uid} || true")[0][:-1]) > 0) + if not args["no_user"] and is_docker_user: + flags += cls.userExecFlags(docker_uid) return flags @classmethod @@ -44,8 +46,8 @@ def userFlags(cls) -> List[str]: return [f"--env DOCKER_UID={os.getuid()}", f"--env DOCKER_GID={os.getgid()}"] @classmethod - def userExecFlags(cls) -> List[str]: - return [f"--user {os.getuid()}"] + def userExecFlags(cls, user: str) -> List[str]: + return [f"--user {user}"] @classmethod def currentDirMountWorkspaceFlags(cls) -> List[str]: