This README provides documentation to help deploy Yaksh in a production environment. If you wish to take Yaksh on a trial run, here is a Quickstart Guide
Python 3.6, 3.7, 3.8
Django 3.0.3
Follow these steps to deploy locally on the server. For deployment instructions using Docker see Deploying Multiple Dockers
Ensure pip is installed
Install MySQL Server
Install Python MySQL system dependencies
Install Apache Server for deployment
Create a database named
yaksh
by following the steps below$> mysql -u root -p $> mysql> create database yaksh
Add a user named
yaksh_user
and give access to it on the databaseyaksh
by following the steps belowmysql> grant usage on yaksh to yaksh_user@localhost identified by 'mysecretpassword'; mysql> grant all privileges on yaksh to yaksh_user@localhost;
To install this app follow the steps below:
Clone this repository and cd to the cloned repo.
git clone https://github.com/FOSSEE/online_test.git
cd online_test
Install Yaksh dependencies, Run
pip3 install -r requirements/requirements-common.txt
pip3 install -r requirements/requirements-production.txt
sudo pip3 install -r requirements/requirements-codeserver.txt
Rename the
.sampleenv
to.env
4. 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
Run:
$ python manage.py migrate
Run the python server provided. This ensures that the code is executed in a safe environment. Do this like so:
$ sudo python3 -m yaksh.code_server # For Python 3.x 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". Code server requires several parameters specified in `.env` file such as "N\_CODE\_SERVERS", "SERVER\_TIMEOUT", "SERVER\_POOL\_PORT", "SERVER\_HOST\_NAME" set to some default values. These parameters can be changed to different values based on your requirement. Multiple code server processes are spawned based on "N\_CODE\_SERVERS" value. The "SERVER\_TIMEOUT" also can be changed. This is the maximum time allowed to execute the submitted code. You can also use a Dockerized code server, see :ref:`Dockerized Code Server <https://github.com/FOSSEE/online_test/blob/add-docker-compose-test/README_production.rst#using-dockerized-code-server>`__
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/2.0/howto/deployment/wsgi/
Create a Superuser/Administrator:
python manage.py createsuperuser
Go to http://desired_host_or_ip:desired_port/exam
And you should be all set.
Note that the "output" directory present in "yaksh_data" folder will contain directories, one for each user. Users' code files are created in "output" directory that can be used for checking later.
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.
Install Docker
Go to the directory where the project is located
cd /path/to/online_test
Create a docker image. This may take a few minutes,
docker build -t yaksh_code_server -f ./docker/Dockerfile_codeserver
Check if the image has been created using the output of
docker images
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 containerYou can use
invoke --list
to get a list of all the available commands
Follow these steps to deploy and run the Django Server, MySQL instance and Code Server in seperate Docker instances.
Install Docker
Install Docker Compose
Rename the
.sampleenv
to.env
In the
.env
file, uncomment all the values and keep the default values as is.Go to the
docker
directory where the project is located:cd /path/to/online_test/docker
Build the docker images
invoke build
Run the containers and scripts necessary to deploy the web application
invoke begin
Make sure that all the containers are
Up
and stableinvoke status
Run the containers and scripts necessary to deploy the web application,
--fixtures
allows you to load fixtures.invoke deploy --fixtures
- To stop the containers, run
invoke halt
- You can use
invoke restart
to restart the containers without removing them. - Remove the containers
invoke remove
- You can use
invoke --list
to get a list of all the available commands.