summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README_production.rst151
-rw-r--r--tasks.py36
2 files changed, 82 insertions, 105 deletions
diff --git a/README_production.rst b/README_production.rst
index 1438dcd..29d79e5 100644
--- a/README_production.rst
+++ b/README_production.rst
@@ -29,14 +29,14 @@ Pre-Requisite
4. Install Python MySql support
5. Install Apache Server for deployment
-1. Create a database named ``yaksh`` by following the steps below
+6. Create a database named ``yaksh`` by following the steps below
::
$> mysql -u root -p
$> mysql> create database yaksh
-2. Add a user named ``yaksh_user`` and give access to it on the database
+7. Add a user named ``yaksh_user`` and give access to it on the database
``yaksh`` by following the steps below
::
@@ -46,88 +46,9 @@ Pre-Requisite
mysql> grant all privileges on yaksh to yaksh_user@localhost;
-3. Add ``DATABASE_PASSWORD = 'mysecretpassword'`` and
+8. Add ``DATABASE_PASSWORD = 'mysecretpassword'`` and
``DATABASE_USER = 'yaksh_user'`` to online\_test/settings.py
-To deploy this app follow the steps below:
-
-1. Clone this repository and cd to the cloned repo.
-
- ::
-
- $ git clone https://github.com/FOSSEE/online\_test.git
-
-2. Run:
-
- ::
-
- python manage.py makemigrations yaksh
-
- python manage.py migrate yaksh
-
-4. First run the python server provided. This ensures that the code is
- executed in a safe environment. Do this like so:
-
- ::
-
- $ sudo python -m yaksh.code_server # For Python 2
-
- $ sudo python3 -m yaksh.code_server # For Python 3
-
- Put this in the background once it has started since this will not
- return back the prompt. It is important that the server be running
- *before* students start attempting the exam. Using sudo is necessary
- since the server is run as the user "nobody". This runs on the ports
- configured in the settings.py file in the variable "SERVER\_PORTS".
- The "SERVER\_TIMEOUT" also can be changed there. This is the maximum
- time allowed to execute the submitted code. Note that this will
- likely spawn multiple processes as "nobody" depending on the number
- of server ports specified.
-
-5. The ``wsgi.py`` script should make it easy to deploy this using
- mod\_wsgi. You will need to add a line of the form:
-
- ::
-
- WSGIScriptAlias / "/online_test/wsgi.py"
-
- to your apache.conf. For more details see the Django docs here:
-
- https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
-
-6. Go to http://desired\_host\_or\_ip:desired\_port/admin
-
-7. Login with your credentials and look at the questions and modify if
- needed. Create a new Quiz, set the date and duration or
- activate/deactivate the quiz.
-
-8. Now ask users to login at:
-
- ::
-
- http://host:port/exam
-
- And you should be all set.
-
-9. Note that the directory "output" will contain directories, one for
- each user. Users can potentially write output into these that can be
- used for checking later.
-
-10. As Moderator user you can visit http://host/exam/monitor to view
- results and user data interactively. You could also "grade" the
- papers manually if needed.
-
-11. You may dump the results and user data using the results2csv and
- dump\_user\_data commands.
-
-12. The file docs/sample\_questions.py is a template that you can use
- for your own questions.
-
-13. Sometimes you might be in the situation where you are not hosted as
- "host.org/exam/" but as "host.org/foo/exam/" for whatever reason. In
- this case edit "settings.py" and set the "URL\_ROOT" to the root you
- have to serve at. In the above example for "host.org/foo/exam" set
- URL\_ROOT='/foo'.
Installation & Usage
^^^^^^^^^^^^^^^^^^^^
@@ -137,7 +58,19 @@ To install this app follow the steps below:
1. Clone this repository and cd to the cloned repo.
``$ git clone https://github.com/FOSSEE/online_test.git``
-2. Run:
+2. Rename the ``.sampleenv`` to ``.env``
+
+3. In the ``.env`` file, uncomment the following and replace the values (please keep the remaining settings as is);
+
+ ::
+
+ DB_ENGINE=mysql # Or psycopg (postgresql), sqlite3 (SQLite)
+ DB_NAME=yaksh
+ DB_USER=root
+ DB_PASSWORD=mypassword # Or the password used while creating a Database
+ DB_PORT=3306
+
+4. Run:
::
@@ -145,7 +78,7 @@ To install this app follow the steps below:
$ python manage.py migrate yaksh
-3. Run the python server provided. This ensures that the code is
+5. Run the python server provided. This ensures that the code is
executed in a safe environment. Do this like so:
::
@@ -167,27 +100,32 @@ To install this app follow the steps below:
You can also use a Dockerized code server, see :ref:`dockerized-code-server`.
-4. Now, Run:
+6. The ``wsgi.py`` script should make it easy to deploy this using
+ mod\_wsgi. You will need to add a line of the form:
- ::
+ ::
- python manage.py runserver <desired_ip>:<desired_port>
+ WSGIScriptAlias / "/online_test/wsgi.py"
+
+ to your apache.conf. For more details see the Django docs here:
-5. Create a Superuser/Administrator:
+ https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
+
+7. Create a Superuser/Administrator:
::
python manage.py createsuperuser
-6. Go to http://desired\_host\_or\_ip:desired\_port/exam
+8. Go to http://desired\_host\_or\_ip:desired\_port/exam
And you should be all set.
-7. Note that the directory "output" will contain directories, one for
+9. Note that the directory "output" will contain directories, one for
each user. Users can potentially write output into these that can be
used for checking later.
-8. As admin user you can visit http://desired\_host\_or\_ip/exam/monitor to view results
+10. As admin user you can visit http://desired\_host\_or\_ip/exam/monitor to view results
and user data interactively. You could also "grade" the papers
manually if needed.
@@ -227,40 +165,55 @@ Follow these steps to deploy and run the Django Server, MySQL instance and Code
2. Install `Docker Compose <https://docs.docker.com/compose/install/>`__
-2. Go to the ``docker`` directory where the project is located:
+3. Rename the ``.sampleenv`` to ``.env``
+
+4. In the ``.env`` file, uncomment all the values and keep the default values as is.
+
+5. Go to the ``docker`` directory where the project is located:
::
cd /path/to/online_test/docker
-3. Build the docker images
+6. Build the docker images
::
invoke build
-4. Run the containers and scripts necessary to deploy the web
+7. Run the containers and scripts necessary to deploy the web
application
::
- invoke deploy
+ invoke begin
+
+8. Make sure that all the containers are ``Up`` and stable
+
+ ::
+
+ invoke status
+
+8. Run the containers and scripts necessary to deploy the web
+ application, ``--fixtures`` allows you to load fixtures.
+
+ ::
-5. Use ``invoke deploy --fixtures`` to load the fixtures
+ invoke deploy --fixtures
-7. Stop the containers
+10. Stop the containers, you can use ``invoke restart`` to restart the containers without removing them
::
invoke halt
-8. Remove the containers
+11. Remove the containers
::
invoke clean
-9. You can use ``invoke --list`` to get a list of all the available commands
+12. You can use ``invoke --list`` to get a list of all the available commands
.. _add-commands:
diff --git a/tasks.py b/tasks.py
index 5e7295a..4a29c4d 100644
--- a/tasks.py
+++ b/tasks.py
@@ -26,6 +26,10 @@ def remove_check_file(path):
if os.path.isfile(path):
os.remove(path)
+def remove_dir(path):
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+
def run_as(os_name):
if os_name.startswith('linux') or os_name == 'darwin' or os_name.startswith('freebsd'):
return 'sudo'
@@ -186,8 +190,8 @@ def begin(ctx):
ctx.run(cmd)
print ("** Done! Initialized the docker containers **")
-@task(begin)
-def deploy(ctx, fixtures=False):
+@task
+def deploy(ctx, fixtures=False, static=True):
run_as_cmd = run_as(OS_NAME)
print("** Setting up & migrating database **")
@@ -210,11 +214,20 @@ def deploy(ctx, fixtures=False):
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 **")
+ if static:
+ 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 status(ctx):
+ run_as_cmd = run_as(OS_NAME)
+ base_cmd = "docker-compose ps"
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ print ("** Fetching container status **")
ctx.run(cmd)
- print ("** Done! Set up static assets **")
@task
def halt(ctx):
@@ -225,11 +238,22 @@ def halt(ctx):
ctx.run(cmd)
print ("** Done! Stopped containers **")
+@task
+def restart(ctx):
+ run_as_cmd = run_as(OS_NAME)
+ base_cmd = "docker-compose restart"
+ cmd = get_cmd(run_as_cmd, base_cmd)
+ print ("** Restarting containers **")
+ ctx.run(cmd)
+ print ("** Done! Restarted 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)
+ sql_dir = os.path.join(SCRIPT_DIR, 'docker', 'mysql')
print ("** Removing containers **")
+ remove_dir(sql_dir)
ctx.run(cmd)
print ("** Done! Removed containers **")