Skip to content

Commit

Permalink
Don't hardcode container interface in Docker vmms
Browse files Browse the repository at this point in the history
Instead of putting all the file copying and su-ing in the docker run
command constructed by the vmm, include an interface script in the
container and use it as the container entrypoint. The only thing
passed from the vmm to the container are the resource limit parameters.

In addition, rewrite the dockerfile so it (1) includes fewer RUN lines, and
(2) does not need to fetch Tango from github in order to build autodriver;
Instead, the autodriver source is copied to the container using the ADD
instruction
  • Loading branch information
cg2v committed Jul 9, 2015
1 parent 5ec90a2 commit 89ea64b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 57 deletions.
32 changes: 32 additions & 0 deletions autodriver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Autolab - autograding docker image

FROM ubuntu:14.04
MAINTAINER Mihir Pandya <mihir.m.pandya@gmail.com>

RUN apt-get update && apt-get install -y build-essential wget

# Install autodriver
WORKDIR /home
RUN useradd autolab && useradd autograde
RUN mkdir autolab autograde output && chown autolab:autolab autolab output && chown autograde:autograde autograde
ADD . /home/autodriver
WORKDIR /home/autodriver
RUN make clean && make && install -c -o root -g root -m 4755 autodriver /usr/bin/autodriver && install -c -m 755 autograde_wrapper.py /usr/bin/autograde_wrapper
ENTRYPOINT ["/usr/bin/autograde_wrapper"]

# Install C0
WORKDIR /home
RUN wget http://c0.typesafety.net/dist/cc0-v0440-linux3.18.1-64bit-bin.tgz
RUN tar -xvzf cc0-*
WORKDIR /home/cc0
RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0
#RUN ./a.out
RUN cp bin/cc0 /usr/bin/cc0

# Clean up
WORKDIR /home
RUN apt-get remove -y wget && apt-get -y autoremove
RUN rm -rf autodriver cc0*

# Check installation
RUN ls -l /home && which autodriver && which cc0
33 changes: 33 additions & 0 deletions autodriver/autograde_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3
import sys
import os
import pwd
import shutil
import subprocess
print("Running "+ str(sys.argv))

for f in os.listdir("mount"):
src=os.path.join("mount", f)
dst=os.path.join("autolab", f)
shutil.copy(src, dst)

autolabuser=pwd.getpwnam("autolab")
pid=os.fork()
if pid == 0:
os.setgroups([])
os.setgid(autolabuser.pw_gid)
os.setuid(autolabuser.pw_uid)
outfile=open("output/feedback", "w")
args=["autodriver"]
args.extend(sys.argv[1:])
args.append("autolab")
print("Executing "+str(args), file=outfile)
sys.exit(subprocess.call(args, stdout=outfile, stderr=outfile, close_fds=True))
(np, status)=os.waitpid(pid, 0)
# if core, exit -1, else pass through code.
if status & 0xff:
status=-1
else:
status>>=8;
shutil.copy("output/feedback", "mount/feedback")
sys.exit(status)
48 changes: 0 additions & 48 deletions vmms/Dockerfile

This file was deleted.

10 changes: 1 addition & 9 deletions vmms/localDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,8 @@ def runJob(self, vm, runTimeout, maxOutputFileSize):
args = ['docker', 'run', '--name', instanceName, '-v']
args = args + ['%s:%s' % (volumePath, '/home/mount')]
args = args + [vm.image]
args = args + ['sh', '-c']

autodriverCmd = 'autodriver -u %d -f %d -t %d -o %d autolab &> output/feedback' % \
(config.Config.VM_ULIMIT_USER_PROC,
config.Config.VM_ULIMIT_FILE_SIZE,
runTimeout, config.Config.MAX_OUTPUT_FILE_SIZE)

args = args + ['cp -r mount/* autolab/; su autolab -c "%s"; \
cp output/feedback mount/feedback' %
autodriverCmd]
args = args + [ "-u", str(config.Config.VM_ULIMIT_USER_PROC), "-f", str(config.Config.VM_ULIMIT_FILE_SIZE), "-t", str(runTimeout), "-o", str(config.Config.MAX_OUTPUT_FILE_SIZE)]

self.log.debug('Running job: %s' % str(args))
ret = timeout(args, runTimeout)
Expand Down

0 comments on commit 89ea64b

Please sign in to comment.