Skip to content

Commit

Permalink
Docker exec directly into container.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohinb2 committed Sep 9, 2024
1 parent e2c24d5 commit fb2aef8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions runhouse/resources/hardware/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def is_shared(self) -> bool:

return f"{self._creds.name}/" in ssh_creds.get("ssh_private_key", "")

def _command_runner(self, node: Optional[str] = None) -> "CommandRunner":
def _command_runner(
self, node: Optional[str] = None, use_docker_exec: Optional[bool] = False
) -> "CommandRunner":
from runhouse.resources.hardware.sky_command_runner import (
SkyKubernetesRunner,
SkySSHRunner,
Expand Down Expand Up @@ -473,7 +475,8 @@ def _command_runner(self, node: Optional[str] = None) -> "CommandRunner":
ssh_private_key=ssh_credentials.get("ssh_private_key"),
ssh_proxy_command=ssh_credentials.get("ssh_proxy_command"),
ssh_control_name=ssh_control_name,
docker_user=self.docker_user,
docker_user=self.docker_user if not use_docker_exec else None,
use_docker_exec=use_docker_exec,
)

return runner
Expand Down Expand Up @@ -1519,7 +1522,9 @@ def _run_commands_with_runner(
ssh_credentials.pop("private_key", None)
ssh_credentials.pop("public_key", None)

runner = self._command_runner(node=node)
runner = self._command_runner(
node=node, use_docker_exec=self.docker_user is not None
)

env_var_prefix = (
" ".join(f"{key}={val}" for key, val in env_vars.items())
Expand Down
6 changes: 4 additions & 2 deletions runhouse/resources/hardware/sky_command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
docker_user: Optional[str] = None,
disable_control_master: Optional[bool] = False,
local_bind_port: Optional[int] = None,
use_docker_exec: Optional[bool] = False,
):
super().__init__(
node,
Expand All @@ -81,6 +82,7 @@ def __init__(
self.docker_user = docker_user
self.local_bind_port = local_bind_port
self.remote_bind_port = None
self.use_docker_exec = use_docker_exec

def _ssh_base_command(
self,
Expand Down Expand Up @@ -176,9 +178,9 @@ def run(
if quiet_ssh: # RH MODIFIED
base_ssh_command.append("-q")

if self.docker_user: # RH MODIFIED
if self.use_docker_exec: # RH MODIFIED
cmd = " ".join(cmd) if isinstance(cmd, list) else cmd
cmd = f"conda deactivate && {cmd}"
cmd = f"sudo docker exec {DEFAULT_DOCKER_CONTAINER_NAME} bash -c {shlex.quote(cmd)}"

command_str = self._get_command_to_run(
cmd,
Expand Down

0 comments on commit fb2aef8

Please sign in to comment.