diff options
author | ankitjavalkar | 2017-11-06 20:23:04 +0530 |
---|---|---|
committer | ankitjavalkar | 2017-11-08 18:36:26 +0530 |
commit | 2df9850b13bffd83c244a2994d512c79840c17be (patch) | |
tree | 8adb74f5c9fcc2685fd008c9d542a7c954170449 /tasks.py | |
parent | d6759d3d1b4f7232dbca2025e67ff4f2812968c9 (diff) | |
download | online_test-2df9850b13bffd83c244a2994d512c79840c17be.tar.gz online_test-2df9850b13bffd83c244a2994d512c79840c17be.tar.bz2 online_test-2df9850b13bffd83c244a2994d512c79840c17be.zip |
Add further changes to invoke script and yaksh-script
Diffstat (limited to 'tasks.py')
-rw-r--r-- | tasks.py | 48 |
1 files changed, 35 insertions, 13 deletions
@@ -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)) |