Наше LMS приложение
Requirements for local development: Python 3.4, PostgreSQL, Gulp, NodeJS, Graphviz
Requirements for python: requirements.txt
Requirements for frontend: package.json
-
Git clone
https://github.com/vitaliyharchenko/quantzone.git
-
For local development create copy of quantzone/settings_dev.py named settings_local.py
import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) DEBUG = True CURRENT_HOST = 'http://127.0.0.1:8000' ALLOWED_HOSTS = ['http://127.0.0.1:8000'] DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'qdb', 'HOST': 'localhost', 'PASSWORD': '***', 'USER': 'quser', } } STATIC_URL = '/static/' STATIC_ROOT = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), )
-
Install Graphvis (http://django-extensions.readthedocs.io/en/latest/graph_models.html)
pip install pygraphvis --install-option="--include-path=/usr/local/include/graphviz/" \ --install-option="--library-path=/usr/local/lib/graphviz" pip install pydotplus
-
Load requirements
npm install
-
Start Gulp
gulp
-
That's it -- you're done!
-
Create and activate virtualenv
virtualenv qenv --python=python3.4 source quenv/bin/activate
-
Load requirements
pip install -r requirements.txt
-
Create database
sudo su - postgres psql create user "quser" with password '***'; create database "qdb" owner "quser"; alter user quser createdb; grant all privileges on database qdb TO quser;
-
Create data structure for django
python manage.py makemigrations python manage.py migrate python manage.py createsuperuser
-
Load all data from .json file
python manage.py loaddata db.json
-
Save all data to .json file and load locally
python manage.py dumpdata --exclude contenttypes > fixtures/db.json scp root@188.93.211.161:/opt/quantzone/fixtures/db.json /Users/vitaliyharchenko/Dev/quantzone
-
Create png file with models relation
python manage.py graph_models --pydot -a -g -o project_vis.png
-
Connect to server
ssh-keygen -R 188.93.211.161 ssh root@188.93.211.161 aw!Biiug16Z3X2
-
Upgrade Ubuntu
sudo apt-get update sudo apt-get upgrade
-
Language settings
locale-gen ru_RU.UTF-8 sudo nano /etc/default/locale * LANG="ru_RU.UTF-8" * LC_ALL="ru_RU.UTF-8" ```
-
Install system packages
sudo apt-get install python3-pip sudo apt-get install libpq-dev python3.4-dev sudo apt-get install python-virtualenv git nginx postgresql postgresql-contrib sudo apt-get install libfreetype6 libfreetype6-dev sudo apt-get install libjpeg8 libjpeg62-dev sudo apt-get install python-imaging
-
Init database structure
sudo su - postgres psql create user "quser" with password '4203'; create database "qdb" owner "quser"; alter user quser createdb; grant all privileges on database qdb TO quser; \q su - root
-
Clone git project
cd /opt git clone https://github.com/vitaliyharchenko/quantzone.git
-
Create? activate and set virtualenv
virtualenv /opt/qenv --python=python3.4 source /opt/qenv/bin/activate cd /opt git clone https://github.com/vitaliyharchenko/quantzone.git pip3 install -r /opt/quantzone/requirements.txt pip3 install uwsgi
-
Test uwsgi
uwsgi --http :8000 --wsgi-file test.py
-
Make Django migrations
cd /opt/quantzone python manage.py collectstatic python manage.py makemigrations users testing tasks results nodes lms courses blocks python manage.py migrate python manage.py createsuperuser
-
Run Django and connect by port
python manage.py runserver 0.0.0.0:8000 go to http://quant.zone:8000
the web client <-> Django | works
-
Run Django by uWSGI in virtualenv
uwsgi --http :8000 --module quantzone.wsgi go to http://quant.zone:8000
the web client <-> uWSGI <-> Django | works
-
Configure nginx
sudo nano /etc/nginx/sites-available/quantzone cd /etc/nginx/sites-enabled sudo ln -s ../sites-available/quantzone sudo rm default sudo service nginx restart sudo chown -R www-data:www-data /var/log/nginx; sudo chmod -R 755 /var/log/nginx; sudo nginx -t go to http://quant.zone/static/css/main.css ```
Nginx serving static and media correctly
-
Run Django by uWSGI globally
uwsgi --http :8000 --chdir /opt/quantzone --module quantzone.wsgi --virtualenv /opt/qenv go to http://quant.zone:8000
the web client <-> uWSGI <-> Django | works
-
Check nginx work
go to http://quant.zone
the web client <-> the web server |works
-
Set up sockets
sudo nano /etc/nginx/sites-available/quantzone (uncomment socket in nginx) uwsgi --socket :8001 --wsgi-file test.py --chmod-socket=664 sudo chmod -R 777 quantzone.sock sudo chown www-data /opt/quantzone/quantzone.sock uwsgi --socket quantzone.sock --wsgi-file test.py --chmod-socket=666 go to http://quant.zone
the web client <-> the web server <-> the socket <-> uWSGI <-> Python | works correctly
-
Run server by .ini file in virtualenv and globally
uwsgi --ini uwsgi.ini deactivate pip3 install uwsgi
-
Create vassals for serving several versions of product together
sudo mkdir /opt/uwsgi sudo mkdir /opt/uwsgi/vassals sudo ln -s /opt/quantzone/uwsgi.ini /opt/uwsgi/vassals/ sudo chown -R www-data:www-data /opt; sudo uwsgi --emperor /opt/uwsgi/vassals --uid www-data --gid www-data
-
Set auto reloading of vassals
nano /etc/rc.local перед строкой “exit 0” добавляем: /usr/local/bin/uwsgi --emperor /opt/uwsgi/vassals --uid www-data --gid www-data
-
Final settings of nginx
change port nginx to 80
-
Work in coding style: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/