Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically create docker container and launch python script

I am working on creating an automated unit testing system which will utilise docker to test individual student assignments, written in Python, against a single unit test file.

I have created a website where students can upload their assignments but I'm a little but unsure as to how to get the automation with Docker working.

The workflow looks something like this:

  1. A student uploads an assignment for marking
  2. This is copied to a linux host which contains docker
  3. The file sits here while it waits to be tested

So, say I had twenty student uploading there .py files, named as their unique student numbers, could I:

  1. Create a Docker container which runs Ubuntu and Python
  2. Copy the student file and unit test into this container
  3. Run the unit test
  4. Output the results as a text file
  5. Copy this text file back to my webserver to display the results

Could somebody point me in the right direction to get started with this automation? I'm really just after some help of the Docker side of things, not on copying the files from my webserver to the Docker host.

Thanks.

like image 927
PuffinMaster Avatar asked Sep 08 '14 04:09

PuffinMaster


1 Answers

Yes, it is possible to use Docker for that.

The Dockerfile would look like this:

FROM ubuntu
MAINTAINER xxx <[email protected]>

# update ubuntu repository
RUN DEBIAN_FRONTEND=noninteractive apt-get -y update

# install ubuntu packages
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python python-pip

# install python requirements
RUN pip install ...

# define a mount point
VOLUME /student.py

# define command for this image
CMD ["python","/student.py"]

Now, you have to build this image with docker build -t student_test ..

To start the script and grab the output you can use:

docker run --volume /path/to/s12345.py:/student.py student_test > student_results_12345.txt`.

The --volume parameter is needed, to mount a student script to the defined mount point. Also, you could start multiple containers at once.

All paths are relative to current working directory.

like image 159
svenwltr Avatar answered Sep 30 '22 15:09

svenwltr