Production Deployment

The production setup is based on the docker configuration in the production/ folder of the repository. In contrast to the development setup, there is no database service configured in the docker-compose.yaml. This is to allow for a more flexible setup with a database service installed on the host, for which it is easier to ensure data safety.

Initial installation

We give here step-by-step instructions how to set up an initial Kompass installation starting from a fresh Debian Bookworm installation. Of course these steps can be easily adapted to a different Linux distribution, the steps will mostly differ in the way the system dependencies are installed.

The instructions describe the recommended setup with a docker-independent MySQL database server on the host system.

We assume that all instructions are executed as root or with sudo.

  1. Install the dependencies: To install docker, please follow the official instructions. For the MySQL server, run the following command:

    apt install mariadb-server
    
  2. Setup the database: We need to create the database and create a user with a strong password. To generate a strong password, run

    PASSWORD=$(tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 24)
    

    Now create a MySQL user with the generated password, by executing:

    mysql <<EOF
    CREATE USER 'kompass'@'10.26.42.0/255.255.255.0' IDENTIFIED BY '$PASSWORD';
    GRANT ALL PRIVILEGES ON kompass.* to 'kompass'@'10.26.42.0/255.255.255.0';
    FLUSH PRIVILEGES;
    EOF
    

    To make the MySQL server available from the docker container, edit /etc/mysql/mariadb.cnf and uncomment the port line in the [client-server] code block. It could then look like this:

    [client-server]
    port = 3306
    socket = /run/mysqld/mysqld.sock
    

    Finally, edit /etc/mysql/mariadb.conf.d/50-server.cnf and add 10.26.42.1 [1] to the bind-address line. It could then look like this:

    bind-address  = 127.0.0.1,10.26.42.1
    

    Now restart the MySQL database by running:

    systemctl restart mariadb.service
    

    Bemerkung

    If you are running a firewall service, you will need to allow connections to the 3306 port from the 10.26.42.0/24 subnet. If you use ufw, you can do:

    ufw allow from 10.26.42.0/24 to 10.26.42.1 port 3306
    
  3. Install Kompass:

    mkdir /opt/kompass
    cd /opt/kompass
    

    Copy the contents of the deploy/ directory of the Kompass repository into this folder. Afterwards, the folder structure should look like this:

    .
    ├── config
    │   └── settings.toml
    └── docker-compose.yaml
    

    Bemerkung

    As long as the Kompass repository is private, you need to ask the maintainers to add a read-only deploy key for your installation to the Gitea. Then you can add a .ssh config file on your server with a section

    Host git.jdav-hd.merten.dev
        HostName git.jdav-hd.merten.dev
        User git
        IdentityFile ~/.ssh/your_deploy_key
    

    Now set the password of the MySQL user in the settings.toml by running

    sed -i "s/kompass-db-user-password/$PASSWORD/g" config/settings.toml
    

    Finally, we can start the docker containers for the first time by running:

    docker compose up --build
    

    This will start building the docker images and then launch the application. If everything works as expected, there should be no error messages. In this case open a second terminal, navigate to /opt/kompass/ and run

    docker compose exec master bash
    cd jdav_web
    python3 manage.py createsuperuser
    

    This will prompt you for a username and a password for the initial admin user. Use a strong password and don’t use the same password as the one for the MySQL user above!

    The webserver will be available on localhost on port 3000. To expose it to the outer world, we need to setup a web server, such as apache2.

  4. Install a webserver: This is standard and not Kompass specific, but we still include the steps here for completeness. First, we need to install apache2:

    apt install apache2
    a2enmod md ssl proxy proxy_http headers
    

    To allow the md module to automatically request a Let’s Encrypt certificate for our domain, you need to accept the certificate agreement. If you do, add the following line

    MDCertificateAgreement accepted
    

    to /etc/apache2/apache2.conf.

    Then create a new file /etc/apache2/sites-available/kompass.conf with

    MDomain jdav-town.de
    
    <VirtualHost *:443>
        ServerName jdav-town.de
        ServerAdmin digital@jdav-town.de
    
        SSLEngine on
        SSLOptions      StrictRequire
    
        ErrorLog   /var/log/apache2/error.log
        LogLevel warn
    
        CustomLog /var/log/apache2/access.log vhost_combined
        SSLProxyEngine on
    
        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
        RequestHeader set X-Forwarded-Proto "https"
        RequestHeader set X-Forwarded-Ssl on
        RequestHeader set X-Forwarded-Port 443
    
    </VirtualHost>
    

    Replace the jdav-town.de domain by a domain pointing to your server. Now activate the site and restart apache:

    a2ensite kompass.conf
    systemctl restart apache2
    

    The md module should now request an SSL certificate from Let’s Encrypt, while this is still pending you will receive a connection not secure error when visiting your domain. Check /var/log/apache2/error.log for any possible errors. If everything worked, you will find there a message similar to:

    [Mon Feb 10 ...] ... : The Managed Domain ... has been setup and changes will be activated on next (graceful) server restart.
    

    In this case run

    systemctl restart apache2
    

    again. You should now see the Kompass application at your domain!

  5. Update settings: Adapt /opt/kompass/config/settings.toml to your needs. If you followed the guide as above, there should be no need to change anything in the [database] section.

    Bemerkung

    conn_max_age (default 60) is how many seconds a database connection is kept open and reused across requests; 0 opens a new one for every request. conn_health_checks (default true) makes Django check a reused connection before a request uses it and reconnect if the server dropped it. Django holds one connection per thread: each uwsgi worker thread and each celery worker process keeps one open, about two dozen in a default deployment, far below MariaDB’s default max_connections of 151. With 0, idle threads hold no connection at all.

    Bemerkung

    We recommend to initialize a git repository in the config folder to version control any changes to the local configuration.

  6. Run the container in background mode: If everything is working, you can cancel the docker compose up --build command from above and run

    docker compose up -d --build
    

    Whenever you change your configuration or want to update to the latest version, run this command again.

  7. Setup mail configuration: The Kompass application needs a working mailserver for forwarding incoming mails on personal mail accounts and on configured forward mail addresses. You can either setup a mailserver on your own or use the docker-based Kompass-tailored mailserver.

    For receiving mails, no further changes to the settings.toml are needed. For sending mails, the [mail] sections needs to be updated with authentication details for an SMTP server.

    If you are using (and have already installed) the docker-based mailserver, proceed as follows: In the Kompass administrative interface create a new user account (i.e. login data) with a strong password and without staff access. Then update the [mail] section in the settings.toml accordingly with the created user name and password. The host = 'host' setting is correct in this case and points to the underlying host.

    That covers sending. Receiving is handled by the lmtp service, which the mailserver delivers incoming mail to over LMTP; it decides who each message goes to and forwards it. The mailserver itself holds no forwarding rules. See Mail routing for what has to be configured on both sides and how to verify it.

Trying the new frontend on a second domain

The new TypeScript frontend ships as its own image and its own service, spa, which publishes port 3001 on localhost. The Django site keeps port 3000 and its nginx configuration untouched, so this can be switched on without disturbing what users are working in today. Point a second domain’s TLS proxy at 127.0.0.1:3001 and both are live side by side: the old interface on the main domain, the new one on the second.

The spa container serves the frontend’s static files and proxies /api/, /o/, /accounts/ and /media/ through to Django, so everything runs on one origin. That is what keeps the setup simple — there is no CORS to configure and no cross-site cookie to get right.

It proxies to spa_master, a second uwsgi running the same application image, not to the one serving the existing site. That separation is the point: a single visitor on the pilot opens several API requests per page, and sharing the two workers the live site runs on would let them queue in front of real users until nginx starts answering with the downtime page.

Bemerkung

The first deploy that includes this file also pulls ghcr.io/…/kompass-spa. A newly published GHCR package is private until it is made visible and linked to the repository; until then docker compose up -d fails on that pull and the app and nginx updates in the same command do not land either. Make the package public before the first deploy.

  1. Register the frontend with the OAuth2 provider. The frontend signs in with Authorization Code + PKCE, which needs an application whose redirect URI matches the domain it is served from:

    docker compose exec master python jdav_web/manage.py ensure_frontend_oauth_app \
        --redirect-uri https://neu.jdav-town.de/callback
    

    The command is idempotent — run it again to add another domain. If the frontend image was built with a different VITE_OAUTH_CLIENT_ID, pass the same value as --client-id.

  2. Let Django answer for the second domain. In settings.toml:

    [django]
    allowed_hosts = ['jdav-town.de', 'neu.jdav-town.de']
    csrf_trusted_origins = ['https://neu.jdav-town.de']
    trust_forwarded_proto_hosts = ['neu.jdav-town.de']
    

    csrf_trusted_origins is needed because the sign-in form is served under a domain Django would not otherwise recognise. trust_forwarded_proto_hosts makes Django believe the X-Forwarded-Proto header from the reverse proxy; without it Django sees plain HTTP behind the TLS termination and rejects the https:// origin of that same form.

    List the new domain only. The setting is per host on purpose: Django’s SECURE_PROXY_SSL_HEADER would apply to every domain this one process serves, and turning it on for the domain that has always run without it also turns on stricter CSRF Referer checking there — which can start refusing POSTs that used to be accepted. Only list hosts that cannot reach the container except through the TLS proxy.

  3. Point the second domain at port 3001, the same way the main domain is pointed at 3000 — including a certificate for it.

Two things stay deliberately unchanged while the pilot runs. Notification mails still link into the old interface, since that is where everyone is still working; frontend_base_url switches those links over when the time comes. And the old interface remains the one users are sent to, so nothing depends on the pilot being up.

Local configuration

If you followed the steps outlined in Initial installation, you have a folder /opt/kompass/config currently containing only a settings.toml.

While the settings.toml configures the most important options, in practice you might want to have more control over texts on the website, used logos or texts used in automatically generated emails. Here we will explain how to configure these.

  • Mail texts: To modify the standard email texts, create a file texts.toml in your config directory. This could then for example look like this:

    confirm_mail = """
    Hello {name},
    
    please confirm your email address! For this use the cool link at {link}.
    
    ..."""
    
    new_unconfirmed_registration = """
    Hi {name},
    
    your group {group} has a new registration! ..."""
    
  • Templates: To override .html of the Kompass application, create a directory templates inside your config directory. This is loaded as a regular templates directory by django, hence you can override anything that lives in one of the many templates directories in the main repository.

    For example, to fill the impressum page with content, you need to create a file templates/startpage/impressum_content.html. In this file you can put any .html document and this will be placed in the impressum page.

    Typical templates to override here are (with their respective paths):

    • templates/startpage/impressum_content: impressum page

    • templates/startpage/faq_content: group registration FAQ

    • templates/startpage/group_introduction: introductory text placed above the group listing

  • Finance rules: How the section settles a statement — what an allowance is, who gets it, what the participants contribute, who has to sign — is a Python package in the config directory, named from the settings.toml:

    [finance]
    ruleset = "rules"   # a package directory under KOMPASS_CONFIG_DIR_PATH
    

    manage.py importruleset runs when the master container starts — the only one of the five containers whose entrypoint imports — so a rule change needs neither a Kompass release nor a rebuild. A package that fails its checks or its cases is stored as a draft, the previous version stays active, the command says so loudly and the container keeps serving.

    deploy/config-template/ in this repository is the directory to copy, and A section’s finance rules is the reference for writing the rules themselves.

    Warnung

    With [finance] ruleset unset, the reference Heidelberg ruleset that ships in the image applies. For any section that is not Heidelberg that is the wrong answer, and a silent one: the statements resolve, the books add up, and the figures are somebody else’s. A section that deploys without a ruleset settles its statements under Heidelberg’s rules.

Footnotes