From b881e3b23f0fb4ccec5ade0fdcca57edf75bcd02 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 14:01:24 +0200 Subject: [PATCH 1/4] fix attaching to non docker-ros containers --- .../src/docker_run/plugins/docker_ros.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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..dc65ab6 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 @@ -33,9 +33,11 @@ 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: + is_dockeruser = False + docker_uid = runCommand(f"docker exec {args['name']} printenv DOCKER_UID || true")[0][:-1] + if len(runCommand(f"docker exec {args['name']} id -u {docker_uid} || true")[0][:-1]) > 0: + is_dockeruser = (int(runCommand(f"docker exec {args['name']} id -u {docker_uid} || true")[0][:-1]) > 0) + if not args["no_user"] and is_dockeruser: flags += cls.userExecFlags() return flags From fac0aa959afc388d643c24d14c047f47713109ef Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 14:11:09 +0200 Subject: [PATCH 2/4] update docker-run-docker-ros version --- docker-run-cli/pyproject.toml | 2 +- docker-run-docker-ros/pyproject.toml | 2 +- docker-run-docker-ros/src/docker_run/plugins/docker_ros.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 dc65ab6..628270b 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): From 6375b343cc6ceb10d4a4305721522150ea3bba35 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 15:50:04 +0200 Subject: [PATCH 3/4] pass DOCKER_UID to user exec flag --- .../src/docker_run/plugins/docker_ros.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 628270b..1ff16bd 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 @@ -35,10 +35,10 @@ def getExecFlags(cls, args: Dict[str, Any], unknown_args: List[str]) -> List[str flags = [] is_dockeruser = False docker_uid = runCommand(f"docker exec {args['name']} printenv DOCKER_UID || true")[0][:-1] - if len(runCommand(f"docker exec {args['name']} id -u {docker_uid} || true")[0][:-1]) > 0: - is_dockeruser = (int(runCommand(f"docker exec {args['name']} id -u {docker_uid} || true")[0][:-1]) > 0) - if not args["no_user"] and is_dockeruser: - flags += cls.userExecFlags() + 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 @@ -46,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]: From 6d4f43f2fa6010e40f294a884f689b61667b36f5 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 18:53:59 +0200 Subject: [PATCH 4/4] fix typo --- docker-run-docker-ros/src/docker_run/plugins/docker_ros.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1ff16bd..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 @@ -33,7 +33,7 @@ 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_dockeruser = False + 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)