Installation (Docker)
Note: docker-based installation is work in progress. The docker files are not optimal nor secure for production.
In the current setup, the container is given read-write access to the repository root folder, because media files are stored in local/
and similar subfolders.
First, build the image and start the container:
./docker/build.sh
./docker/run_mount.sh
Then, attach to the container:
docker attach skoljka
(This command might look stuck, press enter to see the interactive shell.)
Within the container, run the following:
cd /app
./docker/build_internal.sh
./docker/setup_internal.sh
The default mysql root password is empty.
To run skoljka, run
cd /app
python2 manage.py runserver 0.0.0.0:8000
and open http://localhost:8000/ .
Set DEBUG
in settings/local.py
to True
for CSS and JS files to work.
After closing the container, run the following to resume it:
docker start skoljka
docker attach skoljka
service mysql start # Fails for some reason.
service mysql start # Try again.
Installation
This procedure is based on the following tutorial: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
NOTE: Consider using Docker installation above. The following installation procedure might be broken.
- Go to your projects folder (e.g.
~/projects
). Create and go to a virtual environment:
sudo apt-get install gettext git python2.7-dev python-virtualenv
virtualenv -p `which python2` skoljka
cd skoljka
echo -e "export PYTHONPATH=\$PWD:\$PWD/skoljka:\$PYTHONPATH\nexport PROD=true\n\nsource bin/activate" > profile
source profile
- Clone skoljka and run the installation script:
git clone https://github.com/ikicic/skoljka.git
cd skoljka
scripts/install_dependencies.sh
scripts/setup.sh
- Create an empty
UTF8
database (use your username):
mysql -e "CREATE DATABASE skoljka CHARACTER SET utf8 COLLATE utf8_general_ci;" -u username -p
-
Fill out
settings/local.py
, at least the fields marked asREQUIRED
. -
Initialize database and build:
python2 manage.py syncdb --noinput
python2 manage.py loaddata folders userprofiles
python2 build.py
You can now use Django test server by running python2 manage.py runserver
.
The database is pre-filled with superuser arhiva
whose password is a
.
Note that in settings/local.py
the variable DEBUG
is False
by default, so static files won't be loaded correctly.
Configuring gunicorn
The following three sections are used only for running in the release mode.
You should now be in ~/projects/skoljka/skoljka/
.
-
Run
cd ..
to move to~/projects/skoljka/
. -
Create file
runserver.sh
. (fill out user and group variables)
#!/bin/bash
set -e
PORT=8079 # Internal port for non-static files
LOGFILE=logs/skoljka.log
NUM_WORKERS=3
# user/group to run as
USER=""
GROUP=""
source profile
exec gunicorn skoljka.wsgi:application -w $NUM_WORKERS \
--user=$USER --group=$GROUP --log-level=debug \
--log-file=$LOGFILE -b localhost:$PORT
- Set up
gunicorn
.
chmod +x runserver.sh
mkdir -p logs
pip install gunicorn
Configuring supervisor
- Run the following commands:
sudo apt-get install supervisor
touch logs/gunicorn_supervisor.log
- Create file
/etc/supervisor/conf.d/skoljka.conf
(usesudo
, and change these paths)
[program:skoljka]
directory = /home/username/projects/skoljka/
command = /home/username/projects/skoljka/runserver.sh
user = username
stdout_logfile = /home/username/projects/skoljka/logs/gunicorn_supervisor.log
stderr_logfile = /home/username/projects/skoljka/logs/gunicorn_supervisor.log
- Run
skoljka
Django webserver:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart skoljka
Configuring nginx
- Install and start
nginx
:
sudo apt-get install nginx
sudo service nginx start
-
Create
/etc/nginx/sites-available/skoljka
and the symlink/etc/nginx/sites-enabled/skoljka
to the first file. Use e.g.8080
as the main port and remember to redirect/
to the port8079
. Look at the tutorial for the details. -
Restart
nginx
sudo service nginx restart
Testing
End to end tests (E2E)
To run the E2E tests, first launch the test server in the Docker container:
sh python2 manage.py testserver --noinput --traceback --addrport=0.0.0.0:8000 skoljka/userprofile/fixtures/test_userprofiles.json
Then, run the tests:
sh npx cypress run
Or, launch the GUI with:
sh npx cypress open