summaryrefslogtreecommitdiff
path: root/yaksh/documentation/installation.rst
blob: e74a6f0581f8c6ce95ffc4d8af87f7aa9c5e5075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
============
Installation
============

Requirements
------------

Python 3.6, 3.7, 3.8

Django 3.0.3

Installing Yaksh
----------------

If Python 3.6 and above is not available in the system, then we recommend using
miniconda

**Installing Miniconda**

1. Download miniconda from https://docs.conda.io/en/latest/miniconda.html according to the OS version.

2. Follow the installation instructions as given in https://conda.io/projects/conda/en/latest/user-guide/install/index.html#regular-installation

3. Restart the Terminal.

**Pre-Requisite**

* Ensure  `pip <https://pip.pypa.io/en/latest/installing.html>`_ is installed

**Installing Yaksh**

    1. **Clone the repository**::

            git clone https://github.com/FOSSEE/online_test.git

    2. **Go to the online_test directory**::

            cd ./online_test

    3. **Install the dependencies**:

        * Install Django and dependencies::

            pip install -r ./requirements/requirements-common.txt

        * Install Code Server dependencies::

            sudo pip3 install -r requirements/requirements-codeserver.txt

Quick Start
-----------

1. **Start up the code server that executes the user code safely**:
    * To run the code server in a sandboxed docker environment, run the command::

        $ invoke start

    .. note::

        Make sure that you have Docker installed on your system beforehand.
        Find docker installation guide `here <https://docs.docker.com/engine/installation/#desktop>`_.

    * To run the code server without docker, locally use::

        $ invoke start --unsafe

    .. note::

        Note this command will run the yaksh code server locally on your machine and is susceptible to malicious code. You will have to install the code server requirements in sudo mode.

2. **On another terminal, run the application using the following command**
    * To start the django server::

        $ invoke serve

    .. note::

        The serve command will run the django application server on the 8000 port and hence this port will be unavailable to other processes.

3. **Open your browser and open the URL** - ``http://localhost:8000/exam``

4. **Login as a teacher to edit the quiz or as a student to take the quiz**
    
    * Credentials:
        For Student:
            * Username: student
            * Password: student
        For Teacher:
            * Username: teacher
            * Password: teacher

5. **User can also login to the Default Django admin by going to URL and entering the following admin credentials** ``http://localhost:8000/admin``
    For admin:
        * Username: admin
        * Password: admin


Production Deployment
---------------------

* **Deploying Locally**

    Follow these steps to deploy locally on the server.

    * **Pre-Requisite**

        1. Ensure `pip <https://pip.pypa.io/en/latest/installing.html>`__ is
           installed
        2. Install dependencies, Run;
           
           ::

               pip3 install -r requirements/requirements-py3.txt # For Python 3.x

        3. Install MySql Server
        4. Install Python MySql support
        5. Install Apache Server for deployment

        6. Create a database named ``yaksh`` by following the steps below

           ::

               $> mysql -u root -p    
               $> mysql> create database yaksh

        7. Add a user named ``yaksh_user`` and give access to it on the database
           ``yaksh`` by following the steps below

           ::

              mysql> grant usage on yaksh to yaksh_user@localhost identified
              by 'mysecretpassword';

              mysql> grant all privileges on yaksh to yaksh_user@localhost;

        8. Add ``DATABASE_PASSWORD = 'mysecretpassword'`` and
           ``DATABASE_USER = 'yaksh_user'`` to online\_test/settings.py


    * **Installation & Usage**

        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. 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:

           ::

               $ python manage.py makemigrations yaksh

               $ python manage.py migrate yaksh

        5. 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". This runs the number
           ports configured in the settings.py file in the variable
           "N\_CODE\_SERVERS". 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.

           You can also use a Dockerized code server, see `Dockerized Code Server`


        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:

            ::

                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/

        7. Create a Superuser/Administrator:

           ::

               python manage.py createsuperuser

        8. Go to http://desired\_host\_or\_ip:desired\_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 a moderator 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.

.. _dockerized-code-server:

* **Using Dockerized Code Server**

    1. Install
       `Docker <https://docs.docker.com/engine/installation/>`__

    2. Go to the directory where the project is located 

       ::

           cd /path/to/online_test

    3. Create a docker image. This may take a few minutes,

       ::

           docker build -t yaksh_code_server -f ./docker/Dockerfile_codeserver

    4. Check if the image has been created using the output of ``docker
       images``

    5. 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

    6. You can use ``invoke --list`` to get a list of all the available commands


    .. _deploying-multiple-dockers:


* **Deploying Multiple Dockers**

    Follow these steps to deploy and run the Django Server, MySQL instance and Code Server in seperate Docker instances.

    1. Install `Docker <https://docs.docker.com/engine/installation/>`__

    2. Install `Docker Compose <https://docs.docker.com/compose/install/>`__

    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

    6. Build the docker images

       ::

           invoke build

    7. Run the containers and scripts necessary to deploy the web
       application

       ::

           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.

       ::

           invoke deploy --fixtures

    10. Stop the containers, you can use ``invoke restart`` to restart the containers without removing them

       ::

           invoke halt

    11. Remove the containers

       ::

           invoke remove

    12. You can use ``invoke --list`` to get a list of all the available commands


    .. _add-commands:

* **Additional commands available**

    * **create_moderator** : Use this command to make a user as moderator.

      ::

        python manage.py create_moderator <username>

    For more information on the command:

    ::

      python manage.py help [command-name]