summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2017-12-07 16:25:52 +0530
committerankitjavalkar2018-01-04 11:37:20 +0530
commit8c9c7fdf227c7a107345c70fea4cf77cc550a10f (patch)
tree45d91e438caa2dc0ff5f97ae978fc15326f94694
parent0713c60a5ad4b71d4a2050d13cf30afaf37d935b (diff)
downloadonline_test-8c9c7fdf227c7a107345c70fea4cf77cc550a10f.tar.gz
online_test-8c9c7fdf227c7a107345c70fea4cf77cc550a10f.tar.bz2
online_test-8c9c7fdf227c7a107345c70fea4cf77cc550a10f.zip
Multiple changes:
- Add deployment commands to tasks.py - Add deployment commands to README_production.md
-rw-r--r--README_production.md25
-rw-r--r--tasks.py104
2 files changed, 123 insertions, 6 deletions
diff --git a/README_production.md b/README_production.md
index 8b79785..1251ce0 100644
--- a/README_production.md
+++ b/README_production.md
@@ -169,7 +169,7 @@ To install this app follow the steps below:
1. Install [Docker](https://github.com/FOSSEE/online_test/blob/master/README.md)
- 1. Got to the directory where the project is located
+ 1. Go to the directory where the project is located
cd /path/to/online_test
1. Create a docker image. This may take a few minutes
@@ -181,6 +181,29 @@ To install this app follow the steps below:
1. Run the invoke script using the command ```invoke start```
The command will create and run a new docker container (that is running the code_server.py within it), it will also bind the ports of the host with those of the container
+#### Deploying Multiple Dockers
+
+ 1. Install [Docker](https://github.com/FOSSEE/online_test/blob/master/README.md)
+
+ 1. Go to the ```docker``` directory
+
+ 1. Build the docker images
+ invoke build
+
+ 1. Run the containers and scripts necessary to deploy the web application
+ invoke deploy
+
+ Use ```invoke deploy --fixtures``` to load the fixtures
+
+ 1. Create the superuser and moderator group
+ invoke createsuperuser
+
+ 1. Stop the containers
+ invoke halt
+
+ 1. Remove the containers
+ invoke clean
+
#### Additional commands available
We provide several convenient commands for you to use:
diff --git a/tasks.py b/tasks.py
index 47edb20..d518374 100644
--- a/tasks.py
+++ b/tasks.py
@@ -43,9 +43,14 @@ def setupdb(ctx):
print("** Setting up & migrating database **")
ctx.run("python manage.py makemigrations")
ctx.run("python manage.py migrate")
+ print("** Done! Migrations complete **")
+
+def loadfixtures(ctx):
+ print("** Loading fixtures into database **")
ctx.run("python manage.py loaddata demo_fixtures.json")
+ print("** Done! Loaded fixtures into database **")
-@task(setupdb)
+@task(setupdb, loadfixtures)
def serve(ctx):
print("** Running the Django web server. Press Ctrl-C to Exit **")
ctx.run("python manage.py runserver")
@@ -135,16 +140,105 @@ def stop(ctx, container=TARGET_CONTAINER_NAME, hide=True):
remove_check_file(CHECK_FILE_PATH)
if result.stdout:
- print ("** Stopping the docker container <{0}>".format(container))
+ print ("** Stopping the docker container <{0}> **".format(container))
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 ("** Done! Stopped the docker container <{0}> **".format(container))
- print ("** Discarding the docker container <{0}>".format(container))
+ print ("** Discarding the docker container <{0}> **".format(container))
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))
+ print ("** Done! Discarded the docker container <{0}> **".format(container))
else:
print("** Docker container <{0}> not found **".format(container))
+
+@task
+def build(ctx):
+ run_as_cmd = run_as(OS_NAME)
+
+ base_build_cmd = "docker-compose build --no-cache"
+ cmd = get_cmd(run_as_cmd, base_build_cmd)
+ print ("** Building docker images **")
+ ctx.run(cmd)
+ print ("** Done! Built the docker images **")
+
+ base_build_cmd = "docker pull mariadb:10.2 "
+ cmd = get_cmd(run_as_cmd, base_build_cmd)
+ print ("** Pulling maria-db base image **")
+ ctx.run(cmd)
+ print ("** Done! Pulled maria-db base image **")
+
+@task
+def begin(ctx):
+ print("** Initializing docker containers **")
+ base_cmd = "docker-compose up -d"
+ run_as_cmd = run_as(OS_NAME)
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ ctx.run(cmd)
+ print ("** Done! Initialized the docker containers **")
+
+@task(begin)
+def deploy(ctx, fixtures=False):
+ run_as_cmd = run_as(OS_NAME)
+
+ print("** Setting up & migrating database **")
+ base_make_migrate_cmd = "docker exec -i yaksh_django" \
+ " python3 manage.py makemigrations"
+ cmd = get_cmd(run_as_cmd, base_make_migrate_cmd)
+ ctx.run(cmd)
+
+ base_migrate_cmd = "docker exec -i yaksh_django" \
+ " python3 manage.py migrate"
+ cmd = get_cmd(run_as_cmd, base_migrate_cmd)
+ ctx.run(cmd)
+ print("** Done! Migrations complete **")
+
+ if fixtures:
+ base_fixture_cmd = "docker exec -i yaksh_django" \
+ " python3 manage.py loaddata demo_fixtures.json"
+ cmd = get_cmd(run_as_cmd, base_fixture_cmd)
+ print("** Loading fixtures into database **")
+ ctx.run(cmd)
+ print("** Done! Loaded fixtures into database **")
+
+ base_static_cmd = "docker exec -i yaksh_django python3 manage.py collectstatic"
+ cmd = get_cmd(run_as_cmd, base_static_cmd)
+ print ("** Setting up static assets **")
+ ctx.run(cmd)
+ print ("** Done! Set up static assets **")
+
+@task
+def createsuperuser(ctx):
+ run_as_cmd = run_as(OS_NAME)
+
+ base_su_cmd = "docker exec -it yaksh_django python3 manage.py createsuperuser"
+ cmd = get_cmd(run_as_cmd, base_su_cmd)
+ print ("** Creating Superuser **")
+ ctx.run(cmd)
+ print ("** Done! Created Superuser **")
+
+ base_mod_cmd = "docker exec -it yaksh_django python3 manage.py add_group"
+ cmd = get_cmd(run_as_cmd, base_mod_cmd)
+ print ("** Creating Moderator group **")
+ ctx.run(cmd)
+ print ("** Done! Created Moderator group **")
+
+@task
+def halt(ctx):
+ run_as_cmd = run_as(OS_NAME)
+ base_cmd = "docker-compose stop"
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ print ("** Stopping containers **")
+ ctx.run(cmd)
+ print ("** Done! Stopped containers **")
+
+@task(halt)
+def remove(ctx):
+ run_as_cmd = run_as(OS_NAME)
+ base_cmd = "docker-compose rm --force"
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ print ("** Removing containers **")
+ ctx.run(cmd)
+ print ("** Done! Removed containers **")