summaryrefslogtreecommitdiff
path: root/tasks.py
diff options
context:
space:
mode:
authorankitjavalkar2017-11-20 16:07:43 +0530
committerankitjavalkar2018-01-04 11:37:20 +0530
commit6f2e29a067cbeaf88b8ea478bb7c24fe8772180a (patch)
tree63f6efac4d2167bbe96a268ac990a4d9e0a1cc69 /tasks.py
parent2c057133d1b131a1573c93f0d0dbb548dcc8223e (diff)
downloadonline_test-6f2e29a067cbeaf88b8ea478bb7c24fe8772180a.tar.gz
online_test-6f2e29a067cbeaf88b8ea478bb7c24fe8772180a.tar.bz2
online_test-6f2e29a067cbeaf88b8ea478bb7c24fe8772180a.zip
Multiple Changes:
- Add python-decouple package to requirements - use sane defaults and python-decouple in yaksh.settings and online_test.settings module - Replace hardcoded localhost domain name referring to code server with dynamic - Move Dockerfile to dedicated directory - Add dynamic run-as-admin commands to the base command depending on OS - Replace linux specific commands like cp with Python functions
Diffstat (limited to 'tasks.py')
-rw-r--r--tasks.py54
1 files changed, 33 insertions, 21 deletions
diff --git a/tasks.py b/tasks.py
index 04a2ef5..47edb20 100644
--- a/tasks.py
+++ b/tasks.py
@@ -1,7 +1,13 @@
from __future__ import print_function
+import os
+import sys
+import shutil
+from distutils.dir_util import copy_tree
+from distutils.file_util import copy_file
+
import invoke
from invoke import task
-import os
+
from yaksh.settings import SERVER_POOL_PORT
SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
@@ -52,7 +58,10 @@ def clean(ctx):
@task
def getimage(ctx, image=SRC_IMAGE_NAME):
try:
- result = ctx.run("sudo docker inspect {0}".format(image), hide=True)
+ base_cmd = "docker inspect {0}".format(image)
+ run_as_cmd = run_as(OS_NAME)
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ ctx.run(cmd, hide=True)
except invoke.exceptions.Failure:
print("The docker image {0} does not exist locally".format(image))
print("\n** Pulling latest image <{0}> from docker hub **".format(image))
@@ -92,47 +101,50 @@ def start(ctx, ports=SERVER_POOL_PORT, image=SRC_IMAGE_NAME, unsafe=False,
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')
- )
+ copy_tree(
+ os.path.join(SCRIPT_DIR, 'yaksh'),
+ os.path.join(SCRIPT_DIR, 'yaksh_data', 'yaksh')
)
- ctx.run('cp {0} {1}'.format(
- os.path.join(SCRIPT_DIR, 'requirements', 'requirements-codeserver.txt'),
- os.path.join(SCRIPT_DIR, 'yaksh_data')
- )
+
+ copy_file(
+ os.path.join(SCRIPT_DIR, 'requirements', 'requirements-codeserver.txt'),
+ os.path.join(SCRIPT_DIR, 'yaksh_data')
)
print("** Initializing code server within docker container **")
- ctx.run(
- "sudo docker run \
+ base_cmd = "docker run \
-dp {ports}:{ports} --name={name} \
-v {vol_mount}:{vol_mount} \
-w {vol_mount} \
{image} {command}".format(**cmd_params)
- )
+ run_as_cmd = run_as(OS_NAME)
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ ctx.run(cmd)
while not os.path.isfile(CHECK_FILE_PATH):
print("** Checking code server status. Press Ctrl-C to exit **\r", end="")
- print("** Code server is up and running successfully **")
+ print("\n** Code server is up and running successfully **")
@task
def stop(ctx, container=TARGET_CONTAINER_NAME, hide=True):
- result = ctx.run("sudo docker ps -q --filter='name={0}'".format(container))
+ base_filter_cmd = "docker ps -q --filter='name={0}'".format(container)
+ run_as_cmd = run_as(OS_NAME)
+ cmd = get_cmd(run_as_cmd, base_filter_cmd)
+ result = ctx.run(cmd)
+
remove_check_file(CHECK_FILE_PATH)
if result.stdout:
print ("** Stopping the docker container <{0}>".format(container))
- base_cmd = "docker stop {0}".format(container)
- run_as_cmd = run_as(OS_NAME)
- cmd = get_cmd(run_as_cmd, base_cmd)
+ base_stop_cmd = "docker stop {0}".format(container)
+ cmd = get_cmd(run_as_cmd, base_stop_cmd)
ctx.run(cmd)
print ("** Done! Stopped the docker container <{0}>".format(container))
print ("** Discarding the docker container <{0}>".format(container))
- base_cmd = "docker rm {0}".format(container)
- run_as_cmd = run_as(OS_NAME)
- cmd = get_cmd(run_as_cmd, base_cmd)
+ base_rm_cmd = "docker rm {0}".format(container)
+ cmd = get_cmd(run_as_cmd, base_rm_cmd)
+ ctx.run(cmd)
print ("** Done! Discarded the docker container <{0}>".format(container))
else:
print("** Docker container <{0}> not found **".format(container))