- Python 44.1%
- HTML 21.4%
- JavaScript 18.8%
- SCSS 6%
- CSS 4.2%
- Other 5.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| contrib | ||
| entrypoints | ||
| phasesix | ||
| .dockerignore | ||
| .editorconfig | ||
| .env.docker | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| .stylelintrc | ||
| CHANGELOG.md | ||
| docker-compose.yml | ||
| Dockerfile | ||
| LICENSE.txt | ||
| modals-plan.md | ||
| README.md | ||
| RELEASING.md | ||
Phase Six Pen'n'Paper Roleplay Platform
This repository contains the source code which runs the RPG Sites Phase Six and Realms of Tirakan. This is a Django project.
The code is licensed under the GNU GPLv3 as stated in the LICENSE.txt file. However, the text content of both phasesix.org and tirakans-reiche.de (game elements, rules etc.) is licensed under the CC-BY-NC-SA 4.0.
This source code comes with a minimal example set of demo data, which can be inserted into a database to get started.
Getting Started - Docker Compose
To run the project in a docker compose environment, all you need is an installed Docker engine or Docker Desktop, and the docker-compose package.
$ docker-compose up
$ docker-compose exec web .venv/bin/python manage.py migrate
$ docker-compose exec web .venv/bin/python manage.py loaddata demo_data.json
$ docker-compose exec web .venv/bin/python manage.py createsuperuser
You can access the admin interface at http://localhost:8000/admin after that.
Getting Started - Native setup
Alternatively, you can install the needed setup locally on your machine without docker.
You need a Linux (WSL2 works too), macOS (untested) or Windows (untested) machine to run this project. There are some prerequisites used by this django project.
Redis
Phase Six relies on a local redis server. The installation depends on your system. For linux, use your package manager (i.e. apt install redis-server). On macOS, use Homebrew to brew install redis.
The cache (with django-cachalot's ORM query cache) uses CACHE_URL, by default the same Redis as REDIS_HOST/REDIS_PORT. In production it should be a Redis of its own with maxmemory and maxmemory-policy allkeys-lru: cachalot's keys only ever grow, and that policy must not evict the Channels layer or the Celery queues.
PostgreSQL
Phase Six runs on PostgreSQL only, in development and in tests as in production. Install it with your package manager (i.e. apt install postgresql, or brew install postgresql on macOS), then create a role and a database owned by it. The role needs CREATEDB so the test runner can create its test_<name> database:
$ sudo -u postgres createuser --createdb --pwprompt phasesix
$ sudo -u postgres createdb --owner phasesix phasesix
Python and uv
The supported python version is 3.14. A system-wide installed python interpreter is fine, but you want to create a virtualenv. PhaseSix uses uv for requirements. This can be done with:
$ cd phasesix
$ uv sync
$ . .venv/bin/activate
Environment, Database, Superuser
This project uses a .env file to set basic settings (like mail server and database). There is an example .env.example, which can be copied to the name .env in the project folder. Adjust the settings for your needs, in particular DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD, DATABASE_HOST and DATABASE_PORT for the database created above. All of them are required.
To create the database tables, run the django migrations:
(venv) $ python manage.py migrate
This will not create a superuser for the site, so you need to use the django management command to do this:
(venv) $ python manage.py createsuperuser
Demo data
After this, a simple setup without any data should be ready to run. Although phase six needs some prerequisites present in the database. A simple set of demo data containing some extensions, weapons, armour and skills can be inserted from a json file.
(venv) $ python manage.py loaddata demo_data.json
Running the local server
To run the local development server, just run the following management command:
(venv) $ python manage.py runserver
A single threaded server will be available at http://localhost:8000. Note that this server is not suitable for production deployment. There are many ways to deploy a django project.
Background tasks (Celery)
With DEBUG=True the dev server runs Celery tasks inline, so it needs no worker. To try the real thing, set
CELERY_TASK_ALWAYS_EAGER=False in .env and start a worker and the beat next to runserver:
(venv) $ celery -A phasesix worker -l info
(venv) $ celery -A phasesix beat -l info --schedule /tmp/celerybeat-schedule
(venv) $ celery -A phasesix inspect ping # is a worker alive?
Broker and results use Redis database 1 (CELERY_BROKER_URL overrides it). The schedule is
CELERY_BEAT_SCHEDULE in phasesix/settings.py: delete_anonymous_characters at 04:00 and
rebuild_search_index at 04:15, Berlin time.
Deployment
Production setup of phasesix.org
The public sites (phasesix.org, tirakans-reiche.de, division-v.de) run as a Docker Swarm stack behind Traefik, which terminates TLS and routes by host name:
web: the Docker image as built, several replicas. Each runs hypercorn with five workers on port 4444 (DockerfileCMD) and handles all HTTP requests.ws: the same image, one replica, started asdaphne -p 4242 -b 0.0.0.0 phasesix.asgi:application. Traefik sends every request below/wsto it (higher router priority, sticky cookie), so all websockets (campaign dice and virtual tables) run in this one daphne process. daphne pings websocket clients every 20 seconds by default, which keeps idle connections open; the websocket settings inphasesix/hypercorn.tomldo not apply there.nginx: serves the collected static files and the uploads from a shared data directory on separate hosts (public.phasesix.org,public.tirakans-reiche.de,public.division-v.de).STATIC_URLandMEDIA_URLpoint there, so they are on a different origin than the site. nginx echoesAccess-Control-Allow-Originfor the three site origins, which the virtual table needs: it loads its JavaScript as ES modules, and browsers block those across origins without CORS headers. It sends ETag/Last-Modified and supports Range requests (audio/video seeking).migrate: runsentrypoints/migrate.shon deploy (migrations,collectstaticwithout the virtual table's offline dev harness, stylesheet compression).celery_worker(any number of replicas) andcelery_beat(exactly one): the same image, started ascelery -A phasesix workerandcelery -A phasesix beat. They run background tasks and the nightly jobs (CELERY_BEAT_SCHEDULE).- PostgreSQL behind pgbouncer in transaction pooling mode, so Django keeps no persistent connections
(
CONN_MAX_AGE=0) and uses no server-side cursors (DISABLE_SERVER_SIDE_CURSORS). - Redis for the Channels layer and the Celery broker. Because of the Redis Channels layer, broadcasts reach clients on any process.
- A second Redis for the cache (
CACHE_URL), withmaxmemoryandallkeys-lru. django-cachalot caches ORM queries there for up to 7 days; after a restore or another write outside Django, runmanage.py invalidate_cachalot.
Recommended for any static/media host: Cache-Control: no-cache for /static/table/ (the table's
modules have no hashed file names, so browsers must revalidate them after a deploy), Vary: Origin when
echoing CORS headers (the header depends on the requesting site) and X-Content-Type-Options: nosniff.
Other setups
hypercorn does not serve static files or uploads, and Django serves /media/ only with DEBUG=True. Any
setup needs a reverse proxy in front of the container that
- serves
/static/and/media/(thestatic-filesandmedia-filesvolumes indocker-compose.yml), with Range requests and ideallyX-Content-Type-Options: nosniff, - sends
Cache-Control: no-cachefor/static/table/, - accepts request bodies of at least 55 MB (table uploads are limited to 50 MB by Django),
- forwards websocket upgrades on
/ws/with a read timeout above the 20 second ping interval (hypercorn pings with the settings inphasesix/hypercorn.toml: every 20 seconds, messages up to 256 KiB), - sets
Host/X-Forwarded-HostandX-Forwarded-Proto, which Django uses for absolute URLs, CSRF checks and thewss://URL of the table.
STATIC_URL must be on the same origin as the site (for example /static/), or the static host must send
CORS headers for the site's origin, as production does.
contrib/nginx-phasesix.conf is an example nginx site for a single host serving everything on one origin.
Production is set up differently (see above); adjust server names, certificates, paths and the upstream
address before using it.