diff options
-rw-r--r-- | Dockerfile | 17 | ||||
-rw-r--r-- | requirements/requirements-codeserver.txt | 3 | ||||
-rw-r--r-- | requirements/requirements-common.txt | 4 | ||||
-rw-r--r-- | tasks.py | 63 | ||||
-rw-r--r-- | yaksh/scripts/yaksh_script.sh | 13 |
5 files changed, 89 insertions, 11 deletions
@@ -1,13 +1,14 @@ -FROM debian:8.2 +FROM ubuntu:16.04 MAINTAINER FOSSEE <pythonsupport@fossee.in> # Update Packages and Install Python & net-tools -RUN apt-get update && apt-get install -y python net-tools python-pip && pip install tornado +RUN apt-get update && \ +apt-get install -y software-properties-common && \ +add-apt-repository ppa:webupd8team/java -y && \ +apt-get update && \ +apt-get install -y software-properties-common python net-tools git python3-pip vim libmysqlclient-dev scilab build-essential oracle-java8-installer && \ +mkdir /Sites -# Copy the project folder from host into container -COPY ./yaksh /src/yaksh +VOLUME /src/online_test -WORKDIR /src - -# Run Yaksh code server -CMD ["python", "-m", "yaksh.code_server"] +WORKDIR /src/online_test diff --git a/requirements/requirements-codeserver.txt b/requirements/requirements-codeserver.txt new file mode 100644 index 0000000..29b6568 --- /dev/null +++ b/requirements/requirements-codeserver.txt @@ -0,0 +1,3 @@ +requests +tornado +psutil diff --git a/requirements/requirements-common.txt b/requirements/requirements-common.txt index 100d693..895b4f9 100644 --- a/requirements/requirements-common.txt +++ b/requirements/requirements-common.txt @@ -1,9 +1,7 @@ +-r requirements-codeserver.txt django==1.9.5 django-taggit==0.18.1 pytz==2016.4 python-social-auth==0.2.19 -tornado selenium==2.53.6 coverage -psutil -ruamel.yaml==0.15.23 diff --git a/tasks.py b/tasks.py new file mode 100644 index 0000000..07c252c --- /dev/null +++ b/tasks.py @@ -0,0 +1,63 @@ +import invoke +from invoke import task +import os +from yaksh.settings import SERVER_POOL_PORT + + +SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) +TARGET_CONTAINER_NAME = 'yaksh_code_server' +SRC_IMAGE_NAME = 'yaksh_image' + +def create_dir(path): + if not os.path.exists(path): + ctx.run("mkdir {0}".format(path)) + +@task +def setupdb(ctx): + print("** Setting up & migrating database **") + ctx.run("python manage.py migrate") + +@task(setupdb) +def run(ctx): + print("** Running the Django web server **") + ctx.run("python manage.py runserver") + +@task +def clean(ctx): + print("** Discarding database **") + ctx.run("rm -rf {0}".format(os.path.join(SCRIPT_DIR, 'db.sqlite3'))) + +@task +def getimage(ctx, image=SRC_IMAGE_NAME): + try: + result = ctx.run("sudo docker inspect {0}".format(image), hide=True) + except invoke.exceptions.Failure: + print("The docker image {0} does not exist locally".format(image)) + print("\nPulling latest image <{0}> from docker hub".format(image)) + ctx.run("sudo docker pull {0}".format(image)) + +@task +def runcodeserver(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): + if unsafe: + with ctx.cd(SCRIPT_DIR): + ctx.run("sudo python -m yaksh.code_server") + else: + cmd_params = {'ports': ports, + 'image': SRC_IMAGE_NAME, + 'name': TARGET_CONTAINER_NAME, + 'vol_mount_dest': '/src/online_test/', + 'vol_mount_src': os.path.join(SCRIPT_DIR), + 'command': 'sh /src/yaksh_script.sh', + } + + getimage(ctx, image=SRC_IMAGE_NAME) + + create_dir(os.path.join(SCRIPT_DIR, 'output/')) + create_dir(os.path.join(SCRIPT_DIR, 'yaksh/data/')) + + ctx.run( + "sudo docker run --privileged \ + -dp {ports}:{ports} --name={name} \ + -v {vol_mount_src}:{vol_mount_dest} \ + {image} {command}".format(**cmd_params) + ) diff --git a/yaksh/scripts/yaksh_script.sh b/yaksh/scripts/yaksh_script.sh new file mode 100644 index 0000000..83c086c --- /dev/null +++ b/yaksh/scripts/yaksh_script.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# Basic script to install pip packages and run the yaksh code server command + +mkdir /sites/ +echo "** Copying online test directory **" +cp -r /src/online_test /sites/online_test +cd /sites/online_test +echo "** Unmounting online test volume **" +umount /src/online_test +echo "** Installing python dependencies **" +pip3 install -r /sites/online_test/requirements/requirements-codeserver.txt +echo "** Running code server **" +python3 -m yaksh.code_server |