Skip to content

Allow specifying the docker network #268

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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
Loading