diff --git a/autodriver/Dockerfile b/autodriver/Dockerfile new file mode 100644 index 00000000..b36fb2a4 --- /dev/null +++ b/autodriver/Dockerfile @@ -0,0 +1,31 @@ +# Autolab - autograding docker image + +FROM ubuntu:14.04 +MAINTAINER Mihir Pandya + +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 diff --git a/autodriver/Dockerfile_122 b/autodriver/Dockerfile_122 new file mode 100644 index 00000000..51a1eaa8 --- /dev/null +++ b/autodriver/Dockerfile_122 @@ -0,0 +1,32 @@ +# Autolab - autograding docker image + +FROM ubuntu:14.04 +MAINTAINER Mihir Pandya + +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 diff --git a/autodriver/Dockerfile_ubuntu b/autodriver/Dockerfile_ubuntu new file mode 100644 index 00000000..dbb40213 --- /dev/null +++ b/autodriver/Dockerfile_ubuntu @@ -0,0 +1,24 @@ +# Autolab - autograding docker image + +FROM ubuntu:14.04 +MAINTAINER Mihir Pandya + +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 diff --git a/autodriver/autograde_wrapper.py b/autodriver/autograde_wrapper.py new file mode 100644 index 00000000..ce27a822 --- /dev/null +++ b/autodriver/autograde_wrapper.py @@ -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() diff --git a/autodriver/cc0wrap.sh b/autodriver/cc0wrap.sh new file mode 100644 index 00000000..4a14c111 --- /dev/null +++ b/autodriver/cc0wrap.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec /usr/local/cc0/bin/cc0 $@ diff --git a/vmms/Dockerfile b/vmms/Dockerfile deleted file mode 100644 index e9053445..00000000 --- a/vmms/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -# Autolab - autograding docker image - -FROM ubuntu:14.04 -MAINTAINER Mihir Pandya - -RUN apt-get update -RUN apt-get install -y gcc -RUN apt-get install -y make -RUN apt-get install -y build-essential - -# Install autodriver -WORKDIR /home -RUN useradd autolab -RUN useradd autograde -RUN mkdir autolab autograde output -RUN chown autolab:autolab autolab -RUN chown autolab:autolab output -RUN chown autograde:autograde autograde -RUN apt-get install -y git -RUN git clone https://github.com/autolab/Tango.git -WORKDIR Tango/autodriver -RUN make clean && make -RUN cp autodriver /usr/bin/autodriver -RUN chmod +s /usr/bin/autodriver - -# Clean up -WORKDIR /home -RUN apt-get remove -y git -RUN apt-get -y autoremove -RUN rm -rf Tango/ - -# Check installation -RUN ls -l /home -RUN which autodriver \ No newline at end of file diff --git a/vmms/Dockerfile_122 b/vmms/Dockerfile_122 deleted file mode 100644 index f021598d..00000000 --- a/vmms/Dockerfile_122 +++ /dev/null @@ -1,49 +0,0 @@ -# Autolab - autograding docker image - -FROM ubuntu:14.04 -MAINTAINER Mihir Pandya - -# Install necessary packages -RUN apt-get update -RUN apt-get install -y gcc -RUN apt-get install -y make -RUN apt-get install -y build-essential -RUN apt-get install -y wget -RUN apt-get install -y git - -# Install autodriver -WORKDIR /home -RUN useradd autolab -RUN useradd autograde -RUN mkdir autolab autograde output -RUN chown autolab:autolab autolab -RUN chown autolab:autolab output -RUN chown autograde:autograde autograde -RUN git clone https://github.com/autolab/Tango.git -WORKDIR Tango/autodriver -RUN make clean && make -RUN cp autodriver /usr/bin/autodriver -RUN chmod +s /usr/bin/autodriver - -# 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 git -RUN apt-get remove -y wget -RUN apt-get -y autoremove -RUN rm -rf Tango/ -RUN rm -f cc0-* -RUN rm -rf cc0/ - -# Check installation -RUN ls -l /home -RUN which autodriver -RUN which cc0 \ No newline at end of file diff --git a/vmms/Dockerfile_ubuntu b/vmms/Dockerfile_ubuntu deleted file mode 100644 index e9053445..00000000 --- a/vmms/Dockerfile_ubuntu +++ /dev/null @@ -1,34 +0,0 @@ -# Autolab - autograding docker image - -FROM ubuntu:14.04 -MAINTAINER Mihir Pandya - -RUN apt-get update -RUN apt-get install -y gcc -RUN apt-get install -y make -RUN apt-get install -y build-essential - -# Install autodriver -WORKDIR /home -RUN useradd autolab -RUN useradd autograde -RUN mkdir autolab autograde output -RUN chown autolab:autolab autolab -RUN chown autolab:autolab output -RUN chown autograde:autograde autograde -RUN apt-get install -y git -RUN git clone https://github.com/autolab/Tango.git -WORKDIR Tango/autodriver -RUN make clean && make -RUN cp autodriver /usr/bin/autodriver -RUN chmod +s /usr/bin/autodriver - -# Clean up -WORKDIR /home -RUN apt-get remove -y git -RUN apt-get -y autoremove -RUN rm -rf Tango/ - -# Check installation -RUN ls -l /home -RUN which autodriver \ No newline at end of file diff --git a/vmms/distDocker.py b/vmms/distDocker.py index c5726176..b1a8498f 100644 --- a/vmms/distDocker.py +++ b/vmms/distDocker.py @@ -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) diff --git a/vmms/localDocker.py b/vmms/localDocker.py index 45b54145..1825a10b 100644 --- a/vmms/localDocker.py +++ b/vmms/localDocker.py @@ -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)