Skip to content

Commit

Permalink
Merge pull request #5 from kaitj/maint/uid-gid-unix
Browse files Browse the repository at this point in the history
Add uid to docker command fix #4
  • Loading branch information
nx10 authored Jul 17, 2024
2 parents e3251b6 + 1de866e commit 649d7bf
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/styxdocker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
output_dir: pathlib.Path,
metadata: Metadata,
container_tag: str,
docker_user_id: str | None,
docker_executable: str,
) -> None:
"""Create DockerExecution."""
Expand All @@ -69,6 +70,7 @@ def __init__(
self.output_dir = output_dir
self.metadata = metadata
self.container_tag = container_tag
self.docker_user_id = docker_user_id
self.docker_executable = docker_executable

def input_file(self, host_file: InputPathType) -> str:
Expand Down Expand Up @@ -118,6 +120,7 @@ def run(self, cargs: list[str]) -> None:
self.docker_executable,
"run",
"--rm",
*(["-u", self.docker_user_id] if self.docker_user_id else []),
"-w",
"/styx_output",
*mounts,
Expand Down Expand Up @@ -165,12 +168,16 @@ def __init__(
self,
image_overrides: dict[str, str] | None = None,
docker_executable: str = "docker",
user_id: int | None = None,
data_dir: InputPathType | None = None,
) -> None:
"""Create a new DockerRunner."""
self.data_dir = pathlib.Path(data_dir or "styx_tmp")
self.uid = os.urandom(8).hex()
self.execution_counter = 0
self.user_id = (
user_id if user_id else (os.getuid() if os.name == "posix" else None)
)
self.docker_executable = docker_executable
self.image_overrides = image_overrides or {}

Expand Down Expand Up @@ -198,5 +205,6 @@ def start_execution(self, metadata: Metadata) -> Execution:
/ f"{self.uid}_{self.execution_counter - 1}_{metadata.name}",
metadata=metadata,
container_tag=container_tag,
docker_user_id=f"{self.user_id}",
docker_executable=self.docker_executable,
)

0 comments on commit 649d7bf

Please sign in to comment.