Skip to content

Commit 79f434b

Browse files
[rqd] Refactor runOnDocker and add gpu_mode (#1649)
Docker features were spread between `rqconstants.py` and `rqcore.py` making it difficult to assess the impact of changes on the logic. Both configuring and using the Docker API have been moved to `rqdocker.py`. - Add config attribute DOCKER_GPU_MODE to allow passing "gpu=all" when calling docker run. - Add optional environment variable OVERRIDE_DOCKER_IMAGES - Make docker and sentry python dependencies opt-in --------- Signed-off-by: Diego Tavares <[email protected]> Co-authored-by: Ramon Figueiredo <[email protected]>
1 parent a2825ec commit 79f434b

File tree

7 files changed

+343
-191
lines changed

7 files changed

+343
-191
lines changed

ci/run_python_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ echo "Will run tests using ${python_version}"
1313

1414
pip install --user -r requirements.txt -r requirements_gui.txt
1515

16+
# Some rqd unit tests require docker api
17+
pip install docker==7.1.0
18+
1619
# Protos need to have their Python code generated in order for tests to pass.
1720
python -m grpc_tools.protoc -I=proto/ --python_out=pycue/opencue/compiled_proto --grpc_python_out=pycue/opencue/compiled_proto proto/*.proto
1821
python -m grpc_tools.protoc -I=proto/ --python_out=rqd/rqd/compiled_proto --grpc_python_out=rqd/rqd/compiled_proto proto/*.proto

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pytest==8.3.3;python_version>="3.7"
1919

2020
# Optional requirements
2121
# Sentry support for rqd
22-
sentry-sdk==2.11.0
22+
# sentry-sdk==2.11.0
2323
# Docker support for rqd
24-
docker==5.0.3;python_version<"3.7"
25-
docker==7.1.0;python_version>="3.7"
24+
# docker==5.0.3;python_version<"3.7"
25+
# docker==7.1.0;python_version>="3.7"

rqd/rqd.example.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PIXAR_LICENSE_FILE
3232
# Setting this to True requires all the additional "docker.[]" sections to be filled
3333
RUN_ON_DOCKER=False
3434
DOCKER_SHELL_PATH=/usr/bin/sh
35+
DOCKER_GPU_MODE=False
3536

3637
# This section is only required if RUN_ON_DOCKER=True
3738
# List of volume mounts following docker run's format, but replacing = with :

rqd/rqd/rqconstants.py

Lines changed: 11 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,8 @@
157157
SP_OS = platform.system()
158158

159159
# Docker mode config
160-
RUN_ON_DOCKER = False
161-
DOCKER_IMAGES = {}
162-
DOCKER_MOUNTS = []
163-
DOCKER_SHELL_PATH = "/bin/sh"
160+
DOCKER_AGENT = None
161+
DOCKER_GPU_MODE = False
164162

165163
# Backup running frames cache. Backup cache is turned off if this path is set to
166164
# None or ""
@@ -254,82 +252,23 @@
254252
BACKUP_CACHE_TIME_TO_LIVE_SECONDS = config.getint(
255253
__override_section, "BACKUP_CACHE_TIME_TO_LIVE_SECONDS")
256254

257-
__docker_mounts = "docker.mounts"
258255
__docker_config = "docker.config"
259-
__docker_images = "docker.images"
256+
__docker_gpu_mode = "DOCKER_GPU_MODE"
260257

261258
if config.has_section(__docker_config):
262-
RUN_ON_DOCKER = config.getboolean(__docker_config, "RUN_ON_DOCKER")
263-
if RUN_ON_DOCKER:
264-
import docker
265-
import docker.models
266-
import docker.types
259+
if config.getboolean(__docker_config, "RUN_ON_DOCKER"):
260+
from rqd.rqdocker import RqDocker
267261

262+
# Set config attribute for docker_gpu_mode. Configuration is made available
263+
# from both the config file and an environment variable, the latter takes precedence
264+
if __docker_gpu_mode in os.environ:
265+
config[__docker_config][__docker_gpu_mode] = os.environ[__docker_gpu_mode]
266+
267+
DOCKER_AGENT = RqDocker.fromConfig(config)
268268
# rqd needs to run as root to be able to run docker
269269
RQD_UID = 0
270270
RQD_GID = 0
271271

272-
# Path to the shell to be used in the frame environment
273-
if config.has_option(__docker_config, "DOCKER_SHELL_PATH"):
274-
DOCKER_SHELL_PATH = config.get(
275-
__docker_config,
276-
"DOCKER_SHELL_PATH")
277-
278-
# Every key:value on the config file under docker.images
279-
# is parsed as key=SP_OS and value=image_tag.
280-
# SP_OS is set to a list of all available keys
281-
# For example:
282-
#
283-
# rqd.conf
284-
# [docker.images]
285-
# centos7=centos7.3:latest
286-
# rocky9=rocky9.3:latest
287-
#
288-
# becomes:
289-
# SP_OS=centos7,rocky9
290-
# DOCKER_IMAGES={
291-
# "centos7": "centos7.3:latest",
292-
# "rocky9": "rocky9.3:latest"
293-
# }
294-
keys = config.options(__docker_images)
295-
DOCKER_IMAGES = {}
296-
for key in keys:
297-
DOCKER_IMAGES[key] = config.get(__docker_images, key)
298-
SP_OS = ",".join(keys)
299-
if not DOCKER_IMAGES:
300-
raise RuntimeError("Misconfigured rqd. RUN_ON_DOCKER=True requires at "
301-
"least one image on DOCKER_IMAGES ([docker.images] "
302-
"section of rqd.conf)")
303-
def parse_mount(mount_string):
304-
"""
305-
Parse mount definitions similar to a docker run command into a docker
306-
mount obj
307-
308-
Format: type=bind,source=/tmp,target=/tmp,bind-propagation=slave
309-
"""
310-
parsed_mounts = {}
311-
# bind-propagation defaults to None as only type=bind accepts it
312-
parsed_mounts["bind-propagation"] = None
313-
for item in mount_string.split(","):
314-
name, mount_path = item.split(":")
315-
parsed_mounts[name.strip()] = mount_path.strip()
316-
return parsed_mounts
317-
318-
# Parse values under the category docker.mounts into Mount objects
319-
mounts = config.options(__docker_mounts)
320-
for mount_name in mounts:
321-
mount_str = ""
322-
try:
323-
mount_str = config.get(__docker_mounts, mount_name)
324-
mount_dict = parse_mount(mount_str)
325-
mount = docker.types.Mount(mount_dict["target"],
326-
mount_dict["source"],
327-
type=mount_dict["type"],
328-
propagation=mount_dict["bind-propagation"])
329-
DOCKER_MOUNTS.append(mount)
330-
except KeyError as e:
331-
logging.exception("Failed to create Mount for key=%s, value=%s",
332-
mount_name, mount_str)
333272

334273
# pylint: disable=broad-except
335274
except Exception as e:

0 commit comments

Comments
 (0)