Skip to content

Commit

Permalink
Allow specifying the docker network
Browse files Browse the repository at this point in the history
Allow for the use of docker networks other than "bridge" and "none" for
for autograding containers. The network name can be specified in
config.py or via the preallocator. The network must exist on the target
docker host for the containers to run.
  • Loading branch information
cg2v committed Dec 16, 2024
1 parent 92ae12f commit b6582a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config.template.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Config(object):
# Docker autograding container resource limits
DOCKER_CORES_LIMIT = None
DOCKER_MEMORY_LIMIT = None # in MB
# Docker network to attach to (must already exist)
DOCKER_NETWORK = None

# Maximum size for input files in bytes
MAX_INPUT_FILE_SIZE = 10 * 1024 * 1024 * 1024 # 10GB
Expand Down
7 changes: 6 additions & 1 deletion restful_tango/tangoREST.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,22 @@ def createTangoMachine(self, image, vmms=Config.VMMS_NAME, vmObj=None):
"""createTangoMachine - Creates a tango machine object from image"""
cores = getattr(Config, "DOCKER_CORES_LIMIT", None)
memory = getattr(Config, "DOCKER_MEMORY_LIMIT", None)
docker_network = getattr(Config, "DOCKER_NETWORK", None)
if docker_network:
network = {"docker_attachment": docker_network}
if vmObj and "cores" in vmObj and "memory" in vmObj:
cores = vmObj["cores"]
memory = vmObj["memory"]
if vmObj and "network" in vmObj:
network = vmObj["network"]
return TangoMachine(
name=image,
vmms=vmms,
image="%s" % (image),
cores=cores,
memory=memory,
disk=None,
network=None,
network=network,
)

def convertJobObj(self, dirName, jobObj):
Expand Down
7 changes: 7 additions & 0 deletions vmms/localDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import sys
import shutil
from collections.abc import Mapping
import config
from tangoObjects import TangoMachine

Expand Down Expand Up @@ -163,6 +164,12 @@ def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork):
args = args + ["-m", f"{vm.memory}m"]
if disableNetwork:
args = args + ["--network", "none"]
elif (
vm.network
and isinstance(vm.network, Mapping)
and "docker_attachment" in vm.network
):
args.append("--network", vm.network["docker_attachment"])
args = args + [vm.image]
args = args + ["sh", "-c"]

Expand Down

0 comments on commit b6582a4

Please sign in to comment.