Skip to content

Commit

Permalink
Merge pull request #4 from ika-rwth-aachen/fix/attach
Browse files Browse the repository at this point in the history
Fix attaching to non docker-ros containers
  • Loading branch information
lreiher authored Jun 13, 2023
2 parents 0350476 + 6d4f43f commit 0047b25
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docker-run-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]"]

Expand Down
2 changes: 1 addition & 1 deletion docker-run-docker-ros/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 9 additions & 7 deletions docker-run-docker-ros/src/docker_run/plugins/docker_ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from docker_run.plugins.plugin import Plugin


__version__ = "1.0.2"
__version__ = "1.0.3"


class DockerRosPlugin(Plugin):
Expand All @@ -33,19 +33,21 @@ 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
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]:
Expand Down

0 comments on commit 0047b25

Please sign in to comment.