Skip to content
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

Don't hardcode container interface in Docker vmms #76

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions autodriver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Autolab - autograding docker image

FROM ubuntu:14.04
MAINTAINER Mihir Pandya <[email protected]>

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

# 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 && cp cc0wrap.sh /usr/bin/cc0 && chmod +x /usr/bin/cc0
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 -C /usr/local -xvzf cc0-*
WORKDIR /usr/local/cc0
RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0
#RUN ./a.out

# 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
32 changes: 32 additions & 0 deletions autodriver/Dockerfile_122
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 <[email protected]>

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

# 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 && cp cc0wrap.sh /usr/bin/cc0 && chmod +x /usr/bin/cc0

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 -C /usr/local -xvzf cc0-*
WORKDIR /usr/local/cc0
RUN bin/cc0 -d doc/src/exp.c0 doc/src/exp-test.c0
#RUN ./a.out

# 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
24 changes: 24 additions & 0 deletions autodriver/Dockerfile_ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Autolab - autograding docker image

FROM ubuntu:14.04
MAINTAINER Mihir Pandya <[email protected]>

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

# 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"]

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

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

# Wait for all processes, since we are pid 1 in the container,
# exit thread (which is blocking the main thread) once the
# interesting process exits
class WaitLoop(object):
def __init__(self, pid=None):
self.waitfor = pid
self.status = None
def __call__(self):
try:
(nextpid, self.status) = os.wait()
while nextpid is None or nextpid != self.waitfor:
(nextpid, self.status) = os.wait()
except OSError:
if nextpid:
print("Chld process {} never exited, but no more children left".
format(self.waitfor))
self.status = -1

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

autolabuser = pwd.getpwnam("autolab")
(r_p, w_p) = os.pipe()
pid = os.fork()
if pid == 0:
os.close(r_p)
os.setgroups([])
os.setgid(autolabuser.pw_gid)
os.setuid(autolabuser.pw_uid)
args = ["autodriver"]
args.extend(sys.argv[1:])
args.append("autolab")
if w_p != 1:
os.dup2(w_p, 1)
if w_p != 2:
os.dup2(w_p, 2)
if w_p > 2:
os.close(w_p)
os.execvp(args[0], args)
os.close(w_p)
waiter = WaitLoop(pid)
thr = threading.Thread(target=waiter)
thr.start()
rpf = os.fdopen(r_p)
shutil.copyfileobj(rpf, open("mount/feedback", "w"))
#print("Copied output")
rpf.close()
thr.join()
# if core, exit -1, else pass through code.
if os.WIFSIGNALED(waiter.status):
status = -1
else:
status = os.WEXITSTATUS(waiter.status)
#print("Status is {}".format(status))
sys.exit(status)

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions autodriver/cc0wrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec /usr/local/cc0/bin/cc0 $@
34 changes: 0 additions & 34 deletions vmms/Dockerfile

This file was deleted.

49 changes: 0 additions & 49 deletions vmms/Dockerfile_122

This file was deleted.

34 changes: 0 additions & 34 deletions vmms/Dockerfile_ubuntu

This file was deleted.

12 changes: 3 additions & 9 deletions vmms/distDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,13 @@ def runJob(self, vm, runTimeout, maxOutputFileSize):
self.log.debug("Lost persistent SSH connection")
return ret

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

# IMPORTANT: The single and double quotes are important, since we
# are switching to the autolab user and then running
# bash commands.
setupCmd = 'cp -r mount/* autolab/; su autolab -c "%s"; \
cp output/feedback mount/feedback' % autodriverCmd

args = "(docker run --name %s -v %s:/home/mount %s sh -c '%s')" % \
(instanceName, volumePath, vm.image, setupCmd)
args = "(docker run --name %s -v %s:/home/mount %s %s)" % \
(instanceName, volumePath, vm.image, autodriverArgs)

self.log.debug('Running job: %s' % args)

Expand Down
10 changes: 1 addition & 9 deletions vmms/localDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,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 * 2)
Expand Down