Installation
AK Planning: Setup
This repository contains a Django project with several apps.
Requirements
AKPlanning has two types of requirements: System requirements are dependent on operating system and need to be installed manually beforehand. Python requirements will be installed inside a virtual environment (strongly recommended) during setup.
System Requirements
Python3.13+ incl. development tools
Virtualenv
pdflatex & beamer class (
texlive-latex-base texlive-latex-recommended texlive-latex-extra texlive-fonts-extra texlive-luatex)for production using uwsgi:
C compiler e.g. gcc
uwsgi
uwsgi Python3 plugin
for production using Apache (in addition to uwsgi)
the mod proxy uwsgi plugin for apache2
Python Requirements
Python requirements are listed in requirements.txt and in the files in the requirements directory.
They can be installed with pip using -r requirements.txt and for production setup -r requirements_mysql.txt.
Development Setup
create a new directory that should contain the files in future, e.g.
mkdir AKPlanningchange into that directory
cd AKPlanningclone this repository
git clone URL .
Automatic Setup
execute the setup bash script
Utils/setup.sh
Manual Setup
setup a virtual environment using the proper python version
virtualenv venv -p python3.13activate virtualenv
source venv/bin/activateinstall python requirements
pip install -r requirements.txtsetup necessary database tables etc.
python manage.py migrateprepare static files (can be omitted for dev setups)
python manage.py collectstaticcompile translations
python manage.py compilemessagescreate a priviledged user, credentials are entered interactively on CLI
python manage.py createsuperuserdeactivate virtualenv
deactivate
Development Server
Do not use this for deployment!
To start the application for development, in the root directory,
activate virtualenv
source venv/bin/activatestart development server
python manage.py runserver 0:8000In your browser, access
http://127.0.0.1:8000/admin/and continue from there.
Deployment Setup
This application can be deployed using a web server as any other Django application. Remember to use a secret key that
is not stored in any repository or similar, and disable DEBUG mode (settings.py).
Step-by-Step Instructions
log into your system with a sudo user
install system requirements
create a folder, e.g.
mkdir /srv/AKPlanning/change to the new directory
cd /srv/AKPlanning/clone this repository
git clone URL .setup a virtual environment using the proper python version
virtualenv venv -p python3.13activate virtualenv
source venv/bin/activateupdate tools
pip install --upgrade setuptools pip wheelinstall python requirements
pip install -r requirements.txtcreate the file
AKPlanning/settings_secrets.py(copy fromsettings_secrets.py.sample) and fill it with the necessary secrets (e.g. generated bytr -dc 'a-z0-9!@#$%^&*(-_=+)' < /dev/urandom | head -c50) (it is a good idea to restrict read permissions from others)if necessary enable uwsgi proxy plugin for Apache e.g.
a2enmod proxy_uwsgiedit the apache config to serve the application and the static files, e.g. on a dedicated system in
/etc/apache2/sites-enabled/000-default.confwithin theVirtualHosttag add:Alias /static /srv/AKPlanning/static <Directory /srv/AKPlanning/static> Require all granted </Directory> ProxyPassMatch ^/static/ ! ProxyPass / uwsgi://127.0.0.1:3035/
or create a new config (.conf) file (similar to
apache-akplanning.conf) replacing $SUBDOMAIN with the subdomain the system should be available under, and $MAILADDRESS with the e-mail address of your administrator and $PATHTO with the appropriate paths. Copy or symlink it to/etc/apache2/sites-available. Then symlink it tosites-enablede.g. by usingln -s /etc/apache2/sites-available/akplanning.conf /etc/apache2/sites-enabled/akplanning.conf.restart Apache
sudo systemctl restart apache2.servicecreate a dedicated user, e.g.
adduser djangotransfer ownership of the folder to the new user
chown -R django:django /srv/AKPlanningCopy or symlink the uwsgi config in
uwsgi-akplanning.inito/etc/uwsgi/apps-available/and then symlink it to/etc/uwsgi/apps-enabled/using e.g.,ln -s /srv/AKPlanning/uwsgi-akplanning.ini /etc/uwsgi/apps-available/akplanning.iniandln -s /etc/uwsgi/apps-available/akplanning.ini /etc/uwsgi/apps-enabled/akplanning.inistart uwsgi using the configuration fileuwsgi --ini uwsgi-akplanning.inirestart uwsgi
sudo systemctl restart uwsgiexecute the update script
./Utils/update.sh --prod
Optional: Protocol migration from HedgeDoc to MediaWiki
AK protocols written in HedgeDoc (linked in the protocol_link field of an AK) can be copied to the wiki page of
the AK (link field). Each protocol is downloaded as markdown, converted to MediaWiki syntax using pandoc (bundled
with the python requirement pypandoc_binary) and written to the wiki page, but only if that page does not exist
yet or is still empty. Existing content is never overwritten.
The feature is disabled until it is configured:
in the wiki, create a bot password for the account that should perform the edits (
Special:BotPasswords) with the grants Basic rights, Edit existing pages and Create, edit, and move pagesconfigure the wikis in a local settings file, e.g.,
AKPlanning/settings/protocols.py(files in that folder are included by the production settings):# Wikis protocols may be written to, by hostname used in the wiki links of the AKs. # article_path is the path pages are served under (default: /wiki/) PROTOCOL_MIGRATION_WIKIS = { "wiki.example.com": { "api_url": "https://wiki.example.com/w/api.php", "article_path": "/wiki/", }, }
add the credentials of the bot password to
AKPlanning/settings_secrets.py, using the API URL of the wiki as key (the username is the login name of the bot password, i.e., user name and bot name separated by @):PROTOCOL_MIGRATION_WIKI_CREDENTIALS = { "https://wiki.example.com/w/api.php": {"username": "User@AKPlanning", "password": "..."}, }
restart uwsgi
Protocols can be migrated from any HedgeDoc instance, but only from public notes. Since protocol links are entered
by users and downloaded by the server, only https links on the default port are accepted, and only if the host
resolves to public IP addresses (to prevent requests to the server itself or internal networks). Downloads must be
served as markdown (as HedgeDoc does) and are limited to 5 MB.
To migrate protocols, select the AKs in the AK list of the admin interface and choose the action Migrate protocols to wiki (only shown to users allowed to change AKs). After confirmation, the protocols are migrated one AK after another while the page shows the outcome for each AK (keep the page open until it is finished). AKs are skipped (with a reason) if a link is missing or invalid, the protocol is empty or the wiki page already has content, hence the migration can safely be repeated. Each successful migration is recorded in the admin history of the AK.
Wiki logins are cached for 30 minutes to avoid logging in again for each AK. Without a cache configured in the
Django settings (CACHES), each uwsgi process keeps its own in-memory cache.
Deployment Setup using Docker
This project also provides a docker file for easy deployment.
The container described by the docker file only contains the project itself. Additional containers for the database and webserver are needed to use it.
The following docker-compose file shows a typical usage:
version: "3"
networks:
akplanning:
external: false
volumes:
static-files:
services:
mariadb:
image: mariadb:10
restart: always
environment:
MYSQL_ROOT_PASSWORD: supermegasecrey
MYSQL_DATABASE: akplanning
MYSQL_USER: akplanning
MYSQL_PASSWORD: secret
TZ: Europe/Berlin
networks:
- akplanning
akplanning-server:
image: neumantm/akplanning:2021-03-10
restart: always
environment:
SECRET_KEY: superlongandsupersecret
DB_HOST: mariadb
DB_USER: akplanning
DB_NAME: akplanning
DB_PASSWORD: secret
HOSTS: "['akplanning.example.net', 'akplanning.example.de']"
TZ: Europe/Berlin
AUTO_MIGRATE_DB: 'true'
DJANGO_SUPERUSER_USERNAME: admin
DJANGO_SUPERUSER_EMAIL: admin@example.com
DJANGO_SUPERUSER_PASSWORD: supersecret
EXTRA_DJANGO_SETTING_FOO: DJANGO_FOO = True\nDJANGO_BAR = False
depends_on:
- mariadb
networks:
- akplanning
volumes:
- static-files:/app/static
web-server:
image: nginx
restart: always
volumes:
- /path/to/nginx.conf:/etc/nginx/nginx.conf:ro
- static-files:/var/www/akplanning-static
ports:
- "8080:80"
depends_on:
- akplanning-server
networks:
- akplanning
The nginx.conf would look like this:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost:8080;
location /static/ {
alias /var/www/akplanning-static/;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass uwsgi://akplanning-server:3035;
}
}
}
Initializing and migrating database
On the first start, the database must be initialized (the Tables created and so on).
When updating the project the database must be migrated.
Both are done using the migrate command.
This can be done manually by running the following command after the container has started:
docker-compose exec -it akplanning-server ./manage.py migrate
It can also be done automatically on each container start by setting AUTO_MIGRATE_DB to the string true
(as shown in the docker-compose file above).
Database migration may lead to the corruption or loss of data in some cases. Make sure you have a backup before running the command and be very careful with enabling auto migration.
Creating initial superuser
There are two ways to create the initial superuser when using the docker container. For both the database must have been intialized before.
The first way is already shown in the docker-compose file above:
Using the environment variables DJANGO_SUPERUSER_{USERNAME,EMAIL,PASSWORD}.
The second way is to run the following command after the container has started:
docker-compose exec -it akplanning-server ./manage.py createsuperuser
Extra django settings
For simple cases you can pass environment variables starting with EXTRA_DJANGO_SETTING.
The content of such variables is written into python files, which are loaded as settings.
For more complex scenarios you can also mount a docker volume to /app/AKPlanning/settings and add any number of python
files to the volume.
Updates
To update the setup to the current version on the main branch of the repository use the update
script Utils/update.sh or Utils/update.sh --prod in production.
Afterwards, you may check your setup by executing Utils/check.sh or Utils/check.sh --prod in production.
Updating when using docker
To update when using docker, just switch the tag of the image for akplanning-server.
Then (if AUTO_MIGRATE_DB is not enabled), do a database migration as described
in Initializing and migrating database