From d6759d3d1b4f7232dbca2025e67ff4f2812968c9 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 1 Nov 2017 17:43:45 +0530 Subject: - Add a pyinvoke based script for running the django server and code server - Modify the requirements to separate the requirements for code server - Modify the docker file - Add a script that runs within the docker instance --- tasks.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tasks.py (limited to 'tasks.py') 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) + ) -- cgit From 2df9850b13bffd83c244a2994d512c79840c17be Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 6 Nov 2017 20:23:04 +0530 Subject: Add further changes to invoke script and yaksh-script --- tasks.py | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 07c252c..66ea233 100644 --- a/tasks.py +++ b/tasks.py @@ -3,14 +3,13 @@ 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' +SRC_IMAGE_NAME = 'yaksh_code_server_image' def create_dir(path): if not os.path.exists(path): - ctx.run("mkdir {0}".format(path)) + os.makedirs(path) @task def setupdb(ctx): @@ -18,8 +17,8 @@ def setupdb(ctx): ctx.run("python manage.py migrate") @task(setupdb) -def run(ctx): - print("** Running the Django web server **") +def serve(ctx): + print("** Running the Django web server. Press Ctrl-C to Exit **") ctx.run("python manage.py runserver") @task @@ -37,7 +36,7 @@ def getimage(ctx, image=SRC_IMAGE_NAME): ctx.run("sudo docker pull {0}".format(image)) @task -def runcodeserver(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): +def start(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") @@ -45,19 +44,42 @@ def runcodeserver(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=Fals 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', + 'vol_mount': os.path.join(SCRIPT_DIR, 'yaksh_data/'), + 'command': 'sh {0}'.format( + os.path.join(SCRIPT_DIR, + 'yaksh_data/yaksh/scripts/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/')) + create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data/data')) + create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data/output')) + + ctx.run('cp -r {0} {1}'.format( + os.path.join(SCRIPT_DIR, 'yaksh/'), + os.path.join(SCRIPT_DIR, 'yaksh_data/') + ) + ) + ctx.run('cp {0} {1}'.format( + os.path.join(SCRIPT_DIR, 'requirements/requirements-codeserver.txt'), + os.path.join(SCRIPT_DIR, 'yaksh_data') + ) + ) ctx.run( - "sudo docker run --privileged \ + "sudo docker run \ -dp {ports}:{ports} --name={name} \ - -v {vol_mount_src}:{vol_mount_dest} \ + -v {vol_mount}:{vol_mount} \ + -w {vol_mount} \ {image} {command}".format(**cmd_params) ) + +@task +def stop(ctx, container=TARGET_CONTAINER_NAME, hide=True): + result = ctx.run("sudo docker ps -q --filter='name={0}'".format(container)) + if result.stdout: + print ("** Discarding the docker container <{0}>".format(container)) + ctx.run("sudo docker rm {0}".format(container)) + else: + print("** Docker container <{0}> not found **".format(container)) -- cgit From 6fb9f74ee9d2de9a8fb6714907da52a3ed870431 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 8 Nov 2017 16:03:10 +0530 Subject: - Add pytest as a requirement to the requirements file - Modify image name in tasks.py --- tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 66ea233..11a207a 100644 --- a/tasks.py +++ b/tasks.py @@ -5,7 +5,7 @@ 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_code_server_image' +SRC_IMAGE_NAME = 'fossee/yaksh_codeserver' def create_dir(path): if not os.path.exists(path): -- cgit From f5090dec9e11000da9a9bb1a86f181fb14372ce4 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 8 Nov 2017 19:03:15 +0530 Subject: Add makemigrations and loaddata command to serve command --- tasks.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 11a207a..2c8882d 100644 --- a/tasks.py +++ b/tasks.py @@ -14,7 +14,9 @@ def create_dir(path): @task def setupdb(ctx): print("** Setting up & migrating database **") + ctx.run("python manage.py makemigrations") ctx.run("python manage.py migrate") + ctx.run("python manage.py loaddata demo_fixtures.json") @task(setupdb) def serve(ctx): -- cgit From 66cbebb858e50114e2102e95265a9f05a5058eaf Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 8 Nov 2017 19:11:54 +0530 Subject: - Add ruaml dependency to requirements-common - Add print stdout prompts to tasks.py --- tasks.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 2c8882d..29adb60 100644 --- a/tasks.py +++ b/tasks.py @@ -34,13 +34,14 @@ def getimage(ctx, image=SRC_IMAGE_NAME): 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)) + print("\n** Pulling latest image <{0}> from docker hub **".format(image)) ctx.run("sudo docker pull {0}".format(image)) @task def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): if unsafe: with ctx.cd(SCRIPT_DIR): + print("** Initializing local code server **") ctx.run("sudo python -m yaksh.code_server") else: cmd_params = {'ports': ports, @@ -55,6 +56,7 @@ def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): getimage(ctx, image=SRC_IMAGE_NAME) + print("** Preparing code server **") create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data/data')) create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data/output')) @@ -69,6 +71,7 @@ def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): ) ) + print("** Initializing code server within docker container **") ctx.run( "sudo docker run \ -dp {ports}:{ports} --name={name} \ -- cgit From 92128185b5d278b3a248f1f5eb8b824947febbce Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 8 Nov 2017 19:48:33 +0530 Subject: - Add command to stop the container before removing it - Fix README based on feedback --- tasks.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 29adb60..4e41ed5 100644 --- a/tasks.py +++ b/tasks.py @@ -85,6 +85,7 @@ def stop(ctx, container=TARGET_CONTAINER_NAME, hide=True): result = ctx.run("sudo docker ps -q --filter='name={0}'".format(container)) if result.stdout: print ("** Discarding the docker container <{0}>".format(container)) + ctx.run("sudo docker stop {0}".format(container)) ctx.run("sudo docker rm {0}".format(container)) else: print("** Docker container <{0}> not found **".format(container)) -- cgit From e827fa8666fa906e1b668ec43b24295889a329c5 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 9 Nov 2017 12:39:09 +0530 Subject: - Add explicit write permissions to output dir - Modify paths in the script to avoid backslashes for cross platform compatibility - Fix README based on feedback --- tasks.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index 4e41ed5..ff5b1cb 100644 --- a/tasks.py +++ b/tasks.py @@ -47,26 +47,26 @@ def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): cmd_params = {'ports': ports, 'image': SRC_IMAGE_NAME, 'name': TARGET_CONTAINER_NAME, - 'vol_mount': os.path.join(SCRIPT_DIR, 'yaksh_data/'), + 'vol_mount': os.path.join(SCRIPT_DIR, 'yaksh_data'), 'command': 'sh {0}'.format( os.path.join(SCRIPT_DIR, - 'yaksh_data/yaksh/scripts/yaksh_script.sh') + 'yaksh_data', 'yaksh', 'scripts', 'yaksh_script.sh') ) } getimage(ctx, image=SRC_IMAGE_NAME) print("** Preparing code server **") - create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data/data')) - create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data/output')) + create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data', 'data')) + create_dir(os.path.join(SCRIPT_DIR, 'yaksh_data', 'output')) ctx.run('cp -r {0} {1}'.format( - os.path.join(SCRIPT_DIR, 'yaksh/'), - os.path.join(SCRIPT_DIR, 'yaksh_data/') + os.path.join(SCRIPT_DIR, 'yaksh'), + os.path.join(SCRIPT_DIR, 'yaksh_data') ) ) ctx.run('cp {0} {1}'.format( - os.path.join(SCRIPT_DIR, 'requirements/requirements-codeserver.txt'), + os.path.join(SCRIPT_DIR, 'requirements', 'requirements-codeserver.txt'), os.path.join(SCRIPT_DIR, 'yaksh_data') ) ) -- cgit From 91de91014b24412f9ec5fe246235c38a00a778ec Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 9 Nov 2017 15:51:11 +0530 Subject: Add a flag for python version while running code server in unsafe mode --- tasks.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tasks.py') diff --git a/tasks.py b/tasks.py index ff5b1cb..eabf8fb 100644 --- a/tasks.py +++ b/tasks.py @@ -38,11 +38,15 @@ def getimage(ctx, image=SRC_IMAGE_NAME): ctx.run("sudo docker pull {0}".format(image)) @task -def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False): +def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False, + version=3): if unsafe: with ctx.cd(SCRIPT_DIR): print("** Initializing local code server **") - ctx.run("sudo python -m yaksh.code_server") + ctx.run("sudo python{0} -m yaksh.code_server".format( + version + ) + ) else: cmd_params = {'ports': ports, 'image': SRC_IMAGE_NAME, -- cgit