Case ·
Case is a web application written using the Django Framework for Dr. Kenneth Lee and students studying Pharmacy at the University of Western Australia.
The purpose of the application is to allow students to populate a database with case studies that they have experienced, so that other users can attempt the case. Additionally it gives students an opportunity to try more cases, than currently available in the course.
Authors
License
This project is licensed under the MIT License.
Deployment
Database Server
-
Install postgres 9.5 or greater
-
Set up postgres database for case with associated user
-
Allow postgres connections to the app server
App Server:
Distribution: Red Hat Enterprise 7
- Install EPEL repo
yum install epel-release
- Install required packages
yum install python-pip python-devel gcc nginx
- Clone the project
git clone https://github.com/320011/case
- Set up and activate a virtualenv inside case root
pip install virtualenv
virtualenv venv
. venv/bin/activate
- Install pip requirements (including production specific)
pip install -r requirements.txt
pip install gunicorn psycopg2-binary
- Create
local_settings.py
file in the same directory assettings.py
and populate it with required data
import os
ALLOWED_HOSTS = ["example.com"]
DEBUG = False
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = "/path/to/static/for/nginx"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pass',
'HOST': 'db_host',
}
}
EMAIL_USE_TLS = True
EMAIL_HOST = 'my.smtp.server'
EMAIL_HOST_USER = "case@example.com"
EMAIL_HOST_PASSWORD = "email_app_password"
EMAIL_PORT = 587
- Collect static files for Nginx to serve
python manage.py collectstatic
- Create systemd daemon for gunicorn
vim /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=case_linux_user
Group=nginx
WorkingDirectory=/path/to/repo/core
ExecStart=/path/to/repo/venv/bin/gunicorn --workers 3 --bind unix:/path/to/repo/case.sock core.wsgi:application
[Install]
WantedBy=multi-user.target
- Create an Nginx server block inside
http {...}
(or use SSL here)
vim /etc/nginx/nginx.conf
http {
...
server {
listen 80;
server_name example.com;
location = /favicon.ico {
alias /path/to/staticfiles/favicon.ico;
}
location /static/ {
alias /path/to/staticfiles/;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/path/to/repo/case.sock;
}
}
...
}
-
Allow port 80 through the firewall
-
Grant nginx file permissions to execute (important) your staticfiles directory
-
Compile scss files into css. Follow the instructions here to download sass and compile
-
Once the database is running, migrate our django models to it
python manage.py makemigrations
python manage.py migrate
- Start and enable systemd daemons
systemctl start gunicorn
systemctl enable gunicorn
systemctl start nginx
systemctl enable nginx