Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXPERIMENT] Add runDocker mode to rqd #1541

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ six==1.16.0

# Optional requirements
# Sentry support for rqd
sentry-sdk==2.11.0
sentry-sdk==2.11.0

docker==7.1.0
12 changes: 12 additions & 0 deletions rqd/rqd.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@ SYSTEMDRIVE
MAYA_MODULE_PATH
MAYA_SCRIPT_PATH
PIXAR_LICENSE_FILE

[docker.config]
DOCKER_IMAGE=""
RUN_ON_DOCKER=False

[docker.mounts]
MCP="type=bind,source=/mcp,target=/mcp,bind-propagation=slave"
NET="type=bind,source=/net,target=/net,bind-propagation=slave"
TMP="type=bind,source=/tmp,target=/tmp,bind-propagation=slave"
SCRATCH="type=bind,source=/scratch,target=/scratch,bind-propagation=slave"
LIMITS="type=bind,source=/etc/security/limits.d/,target=/etc/security/limits.d/,bind-propagation=slave"
FUSE="type=bind,source=/dev/fuse,target=/dev/fuse,bind-propagation=shared"
41 changes: 41 additions & 0 deletions rqd/rqd/rqconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@

SP_OS = platform.system()

# Docker mode config
RUN_ON_DOCKER = False
DOCKER_IMAGE = "Invalid"
DOCKER_MOUNTS = []

try:
if os.path.isfile(CONFIG_FILE):
# Hostname can come from here: rqutil.getHostname()
__override_section = "Override"
__host_env_var_section = "UseHostEnvVar"
__docker_mounts = "docker.mounts"
__docker_config = "docker.config"
import six
from six.moves import configparser
if six.PY2:
Expand Down Expand Up @@ -230,6 +237,40 @@
if config.has_section(__host_env_var_section):
RQD_HOST_ENV_VARS = config.options(__host_env_var_section)

if config.has_section(__docker_config):
RUN_ON_DOCKER = config.getboolean(__docker_config, "RUN_ON_DOCKER")
if RUN_ON_DOCKER:
import docker
import docker.models
import docker.types

def parse_mount(mount_str):
"""
Parse mount definitions similar to a docker run command into a docker
mount obj

Format: type=bind,source=/tmp,target=/tmp,bind-propagation=slave
"""
mount_dict = {}
# bind-propagation defaults to None as only type=bind accepts it
mount_dict["bind-propagation"] = None
for item in mount_str.split(","):
key, value = item.split("=")
mount_dic[key.strip()] = value.strip()
return mount_dic

DOCKER_IMAGE = config.get(__docker_config, "DOCKER_IMAGE")
# Parse values under the category docker.mounts into Mount objects
mounts = config.options(__docker_mounts)
for mount_name in mounts:
mount_str = config.get(__docker_mounts, mount_name)
mount_dic = parse_mount(mount_str)
mount = docker.types.Mount(mount_dic["target"],
mount_dic["source"],
type=mount_dic["type"],
propagation=mount_dic["bind-propagation"])
DOCKER_MOUNTS.append(mount)

# pylint: disable=broad-except
except Exception as e:
logging.warning(
Expand Down
Loading
Loading