Skip to content

Commit c7ac82a

Browse files
committed
Allow specifying the docker network
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.
1 parent 4249205 commit c7ac82a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

config.template.py

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class Config(object):
8989
# Docker autograding container resource limits
9090
DOCKER_CORES_LIMIT = None
9191
DOCKER_MEMORY_LIMIT = None # in MB
92+
# Docker network to attach to (must already exist)
93+
DOCKER_NETWORK = None
9294

9395
# Maximum size for input files in bytes
9496
MAX_INPUT_FILE_SIZE = 10 * 1024 * 1024 * 1024 # 10GB

restful_tango/tangoREST.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,22 @@ def createTangoMachine(self, image, vmms=Config.VMMS_NAME, vmObj=None):
115115
"""createTangoMachine - Creates a tango machine object from image"""
116116
cores = getattr(Config, "DOCKER_CORES_LIMIT", None)
117117
memory = getattr(Config, "DOCKER_MEMORY_LIMIT", None)
118+
docker_network = getattr(Config, "DOCKER_NETWORK", None)
119+
if docker_network:
120+
network = {'docker_attachment': docker_network}
118121
if vmObj and "cores" in vmObj and "memory" in vmObj:
119122
cores = vmObj["cores"]
120123
memory = vmObj["memory"]
124+
if vmObj and "network" in vmObj:
125+
network = vmObj["network"]
121126
return TangoMachine(
122127
name=image,
123128
vmms=vmms,
124129
image="%s" % (image),
125130
cores=cores,
126131
memory=memory,
127132
disk=None,
128-
network=None,
133+
network=network,
129134
)
130135

131136
def convertJobObj(self, dirName, jobObj):

vmms/localDocker.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import sys
1313
import shutil
14+
from collections.abc import Mapping
1415
import config
1516
from tangoObjects import TangoMachine
1617

@@ -163,6 +164,8 @@ def runJob(self, vm, runTimeout, maxOutputFileSize, disableNetwork):
163164
args = args + ["-m", f"{vm.memory}m"]
164165
if disableNetwork:
165166
args = args + ["--network", "none"]
167+
elif vm.network and isinstance(vm.network, Mapping) and "docker_attachment" in vm.network:
168+
args.append("--network", vm.network["docker_attachment"])
166169
args = args + [vm.image]
167170
args = args + ["sh", "-c"]
168171

0 commit comments

Comments
 (0)