Skip to content

Commit

Permalink
feat(core): pass docker run args to session start
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad-alisafaee committed May 29, 2023
1 parent 5730ce5 commit a7e4e49
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
93 changes: 91 additions & 2 deletions renku/core/session/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,91 @@ def get_start_parameters(self) -> List["ProviderParameter"]:
return [
ProviderParameter("port", help="Local port to use (random if not specified).", type=int),
ProviderParameter("force-build", help="Always build image and don't check if it exists.", is_flag=True),
ProviderParameter(
"blkio-weight", help="Block IO (relative weight), between 10 and 1000, or 0 to disable.", type=int
),
ProviderParameter("cap-add", help="Add Linux capabilities.", multiple=True),
ProviderParameter("cap-drop", help="Drop Linux capabilities.", multiple=True),
ProviderParameter("cgroup-parent", help="Override the default parent cgroup.", type=str),
ProviderParameter("cpu-count", help="Number of usable CPUs.", type=int),
ProviderParameter("cpu-percent", help="Usable percentage of the available CPUs.", type=int),
ProviderParameter("cpu-period", help="The length of a CPU period in microseconds.", type=int),
ProviderParameter(
"cpu-quota", help="Microseconds of CPU time that the container can get in a CPU period.", type=int
),
ProviderParameter("cpu-rt-period", help="Limit CPU real-time period in microseconds.", type=int),
ProviderParameter("cpu-rt-runtime", help="Limit CPU real-time runtime in microseconds.", type=int),
ProviderParameter("cpu-shares", help="CPU shares (relative weight).", type=int),
ProviderParameter("cpuset-cpus", help="CPUs in which to allow execution ('0-3', '0,1').", type=str),
ProviderParameter(
"cpuset-mems", help="Memory nodes (MEMs) in which to allow execution ('0-3', '0,1').", type=str
),
ProviderParameter(
"device-cgroup-rules",
help="A list of cgroup rules to apply to the container.",
multiple=True,
flags=["device-cgroup-rule"],
),
ProviderParameter("devices", help="Expose host devices to the container.", multiple=True, flags=["device"]),
ProviderParameter("dns", help="Set custom DNS servers.", multiple=True),
ProviderParameter(
"dns-opt",
help="Additional options to be added to the container's ``resolv.conf`` file.",
type=str,
flags=["dns-opt", "dns-option"],
),
ProviderParameter("dns-search", help="DNS search domains.", multiple=True),
ProviderParameter("domainname", help="Container NIS domain name.", type=str),
ProviderParameter("entrypoint", help="The entrypoint for the container.", type=str),
ProviderParameter(
"environment",
help="Environment variables to set inside the container, in the format 'VAR=VAL'",
multiple=True,
flags=["e", "env"],
),
ProviderParameter(
"group-add",
help="List of additional group names and/or IDs that the container process will run as.",
multiple=True,
),
ProviderParameter("hostname", help="Optional hostname for the container.", type=str),
ProviderParameter(
"init", help="Run an init inside the container that forwards signals and reaps processes", is_flag=True
),
ProviderParameter("isolation", help="Isolation technology to use.", type=str),
ProviderParameter("kernel-memory", help="Kernel memory limit (bytes).", type=int),
ProviderParameter("mac-address", help="MAC address to assign to the container.", type=str),
ProviderParameter("mem-reservation", help="Memory soft limit.", type=int, flags=["memory-reservation"]),
ProviderParameter(
"mem-swappiness",
help="Tune container memory swappiness (0 to 100).",
type=int,
flags=["memory-swappiness"],
),
ProviderParameter("memswap-limit", help="Swap limit equal to memory plus swap.", flags=["memory-swap"]),
ProviderParameter("name", help="The name for this container.", type=str),
ProviderParameter("network", help="Connect a container to a network.", type=str),
ProviderParameter("oom-kill-disable", help="Disable OOM Killer.", is_flag=True),
ProviderParameter("oom-score-adj", help="Tune host's OOM preferences (-1000 to 1000).", type=int),
ProviderParameter("pids-limit", help="Tune a container's pids limit.", type=int),
ProviderParameter("platform", help="Set platform if server is multi-platform capable.", type=str),
ProviderParameter("privileged", help="Give extended privileges to this container.", is_flag=True),
ProviderParameter(
"publish-all-ports", help="Publish all ports to the host.", is_flag=True, flags=["publish-all"]
),
ProviderParameter("read-only", help="Mount the container's root filesystem as read-only", is_flag=True),
ProviderParameter("remove", help="Automatically remove the container when it exits.", flags=["rm"]),
ProviderParameter("runtime", help="Runtime to use with this container.", type=str),
ProviderParameter("security-opt", help="Security Options.", multiple=True),
ProviderParameter("shm-size", help="Size of /dev/shm (bytes).", type=int),
ProviderParameter(
"stdin-open", help="Keep STDIN open even if not attached.", is_flag=True, flags=["interactive"]
),
ProviderParameter("stop-signal", help="Signal to stop the container.", type=str),
ProviderParameter("tty", help="Allocate a pseudo-TTY.", is_flag=True),
ProviderParameter("user", help="Username or UID", type=str),
ProviderParameter("volume-driver", help="The name of a volume driver/plugin.", type=str),
ProviderParameter("volumes-from", help="Mount volumes from the specified container(s)", multiple=True),
]

def get_open_parameters(self) -> List["ProviderParameter"]:
Expand Down Expand Up @@ -239,11 +324,14 @@ def session_start_helper(consider_disk_request: bool):
)
show_non_standard_user_warning = False

additional_options["user"] = "root"
additional_options["user"] = kwargs.pop("user", "root")
environment["NB_UID"] = str(os.getuid())
environment["CHOWN_HOME"] = "yes"
environment["CHOWN_HOME_OPTS"] = "-R"

user_env = kwargs.pop("environment", {})
user_env.update(environment)

container = self.docker_client().containers.run(
image_name,
'jupyter notebook --NotebookApp.ip="0.0.0.0"'
Expand All @@ -262,11 +350,12 @@ def session_start_helper(consider_disk_request: bool):
},
ports={f"{DockerSessionProvider.JUPYTER_PORT}/tcp": kwargs.get("port")},
remove=True,
environment=environment,
environment=user_env,
volumes=volumes,
working_dir=str(work_dir),
**resource_requests,
**additional_options,
**kwargs,
)

if not container.ports:
Expand Down
14 changes: 10 additions & 4 deletions renku/ui/cli/session.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#
# Copyright 2018-2023 - Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Copyright Swiss Data Science Center (SDSC). A partnership between
# École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -277,13 +276,20 @@ def session_start_provider_options(*param_decls, **attrs):
@click.option("--image", type=click.STRING, metavar="<image_name>", help="Docker image to use for the session.")
@click.option("--cpu", type=click.FLOAT, metavar="<cpu quota>", help="CPUs quota for the session.")
@click.option("--disk", type=click.STRING, metavar="<disk size>", help="Amount of disk space required for the session.")
@click.option("--gpu", type=click.STRING, metavar="<GPU quota>", help="GPU quota for the session.")
@click.option(
"--gpu",
type=click.STRING,
metavar="<GPU quota>",
help="Number of GPU devices to add to the container ('all' to pass all GPUs).",
)
@click.option("--memory", type=click.STRING, metavar="<memory size>", help="Amount of memory required for the session.")
@session_start_provider_options()
def start(provider, config, image, cpu, disk, gpu, memory, **kwargs):
"""Start an interactive session."""
from renku.command.session import session_start_command

kwargs = {k: v for k, v in kwargs.items() if v is not None}

communicator = ClickCallback()
session_start_command().with_communicator(communicator).build().execute(
provider=provider,
Expand Down
2 changes: 1 addition & 1 deletion renku/ui/cli/utils/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def wrapper(f):
param_help = f"\b\n{param.help}\n " if j == 0 else param.help # NOTE: add newline after a group

args = (
[f"-{a}" if len(a) == 1 else f"--{a}" for a in param.flags if a] + [param.name]
[f"-{a}" if len(a) == 1 else f"--{a}" for a in param.flags if a] + [param.name.replace("-", "_")]
if param.flags
else [f"--{param.name}"]
)
Expand Down

0 comments on commit a7e4e49

Please sign in to comment.