On-call Documentation
Polski Repository

Running the stack

The deployment is four containers: the database db, the API api, the worker process worker and the web server (nginx), which serves the application, this documentation under /docs/ and forwards /api/ and /calendar/ to the API.

api and worker run from one image, ghcr.io/lowicz/oncall-api; web from the image ghcr.io/lowicz/oncall-web. The images are published for every release and tagged with its number - see Releases and versions.

The docker-compose.yml file works unchanged under both Docker Compose and Podman Compose. It uses no syntax or behaviour that Podman Compose does not provide.

Quick start

cp .env.example .env
# set ONCALL_VERSION (the release number, e.g. 1.2.3)
# and ONCALL_ADMIN_USERNAME and ONCALL_ADMIN_PASSWORD (at least 12 characters);
# anywhere other than your own computer also POSTGRES_PASSWORD and ONCALL_DATABASE_URL
docker compose pull
docker compose up -d

Under Podman it is the same command with a different prefix:

podman compose pull
podman compose up -d

The application answers at http://localhost:8080, the API at the same address under /api, and the documentation at http://localhost:8080/docs/.

Without ONCALL_VERSION in .env Compose refuses to start and prints what is missing. This way every host has a record of which version it runs.

The database password from .env.example is publicly known and serves local work only. Every host other than your own computer sets its own before the first start - see Database password.

Administrator account

On every API start the administrator account is created or synchronised: password, display name, role and status. A password rotation takes effect after a restart of the api service. With both variables empty the step is skipped.

Database migrations run at the same start, before the API comes up. The web service waits until api answers on /api/v1/health, so after docker compose up -d the application becomes available only once the migrations have finished.

Demo data

docker compose exec -e ONCALL_DEMO_PASSWORD='local-demo-password' api \
  python -m oncall.seed_demo

Creates the accounts admin, anna, marek, ola, piotr and viewer with a two-week schedule. ONCALL_DEMO_EMAIL_DOMAIN gives them {login}@{domain} addresses.

The admin account takes its password from ONCALL_ADMIN_PASSWORD if it has already been created by the API start - the other accounts get the password from ONCALL_DEMO_PASSWORD.

Key variables

The full list with comments is in .env.example.

Variable Default Meaning
ONCALL_VERSION none - required the image version to run, see Releases
POSTGRES_PASSWORD local, publicly known the database password; unique anywhere other than your own computer, see Database password
ONCALL_DATABASE_URL the address with the local password the connection of api and worker to the database; the same password as POSTGRES_PASSWORD
ONCALL_WEB_HTTP_PORT 8080 the HTTP port exposed on the host
ONCALL_WEB_HTTPS_PORT 8443 the HTTPS port exposed on the host
ONCALL_APP_NAME On-call the product name in the interface, e-mails and calendar names
ONCALL_APP_SUBTITLE empty the second line under the name in the navigation, on the sign-in screen and in the e-mail header; empty hides the line
ONCALL_ACCENT empty optional decorations of the interface, see Seasonal decorations; empty turns them off entirely
ONCALL_ACCENT_FROM, ONCALL_ACCENT_UNTIL empty a winter season other than 6 December - 6 January, as MM-DD; both or neither
ONCALL_PUBLIC_BASE_URL http://localhost:8080 the address in e-mails, ICS feeds and links
ONCALL_HANDOVER_REMINDER_HOUR 9 the hour (Warsaw time) of the announcements and reminders about a starting duty, see Integrations
ONCALL_COORDINATOR_DIGEST_HOUR 8 the hour (Warsaw time, 0-23) of the message sent on working days telling coordinators and administrators who is on duty today and on the days off that follow; independent of ONCALL_HANDOVER_REMINDER_HOUR
ONCALL_SWITCH_URL empty the page for switching the on-call number; the reminder on the first day of a PRIMARY duty leads there; empty leaves the link out
ONCALL_SESSION_COOKIE_SECURE false set true together with TLS
ONCALL_API_WORKERS empty the number of API processes; empty = from the CPU limit, minimum 2
ONCALL_SOLVER_WORKERS empty CP-SAT threads; empty = from the CPU limit, maximum 8
ONCALL_GENERATION_CONCURRENCY 1 parallel generations in the worker process
ONCALL_RETENTION_AUDIT_DAYS 365 after how many days audit entries about operations disappear; 0 = indefinitely, see Data retention
ONCALL_RETENTION_LOGIN_AUDIT_DAYS 90 the same for routine sign-ins and refused attempts
ONCALL_RETENTION_OUTBOX_DAYS 90 sent, failed, skipped and cancelled e-mails
ONCALL_RETENTION_RUNS_DAYS 30 finished generator runs
ONCALL_SMTP_HOST empty the outgoing mail server; empty disables e-mail sending, see SMTP server
ONCALL_SECRETS_KEY empty the Fernet key api and worker encrypt the secrets kept in the database with (the Orange WCO password of the automatic on-call number forwarding); several comma-separated keys rotate it: the first encrypts, every one decrypts; empty turns off the features that need it; the key protects a value an administrator can reveal on the number forwarding screen, so its boundary is the same as an administrator account's; python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" prints a new key
ONCALL_CA_FILE ./tls/ca.pem the one PEM bundle of the CAs the deployment trusts: for LDAP, SMTP, Orange WCO, Keycloak and nginx - see CA file
ONCALL_LDAP_ENABLED false directory sign-in - see LDAP / Active Directory
ONCALL_SSO_ENABLED false SSO sign-in (Keycloak), with ONCALL_SSO_ISSUER, ONCALL_SSO_CLIENT_ID, ONCALL_SSO_CLAIM_PERSONNEL_NUMBER and ONCALL_SSO_TIMEOUT_SECONDS - see SSO sign-in
ONCALL_TLS_ENABLED false HTTPS on nginx - see TLS

The number of API processes times the connection pool size must stay below PostgreSQL's max_connections.

In Compose the worker process has an allocation of 2 CPUs, and the default number of solver threads follows from it. Changing the allocation changes that number automatically.

Seasonal decorations

The interface can wear seasonal decorations. They are off by default: while ONCALL_ACCENT is empty, nothing changes.

ONCALL_ACCENT is a list of packs separated by commas. You write it once and leave it: each pack knows its own days, so nobody switches the setting when a season starts or ends.

Pack When What it shows
winter from 6 December to 6 January a hat on the product mark, a garland of lights under the “Teraz” strip and snow inside that strip, a winter night on the sign-in screen, a sleigh on the generator's progress bar
doodles seven days a year a small drawing on the product mark: on 31 December and 1 January, on Fat Thursday, on 14 February, on Easter Sunday and Monday, and on 1 April

The garland and the snow inside the strip are on the desktop “Teraz” strip only. A phone has no such strip: its top bar shows only the hat or the day's drawing on the product mark.

ONCALL_ACCENT=winter,doodles

ONCALL_ACCENT_FROM and ONCALL_ACCENT_UNTIL set another winter season: a day of the year as MM-DD, both ends included. You give both or neither, and the season may run across New Year. The doodles pack does not read them. An unknown pack name, a malformed date or only one of the two dates stops api at startup with a message in the log.

Whether today is one of a pack's days is decided by the date in the Europe/Warsaw zone. An open browser tab learns it when the page loads.

The decorations are on the screen only: they do not reach a printout, e-mails, ICS calendars or CSV reports, and they cover nothing. With the system's reduced-motion setting they stand still, and each person can turn them off for themselves in the account menu (Decorations). A preview from a share link never shows them.

CA file

A deployment names its certificate authorities in one PEM file, ONCALL_CA_FILE (./tls/ca.pem by default): the organisation's root and intermediate CAs, or the host's whole system bundle, e.g. /etc/pki/tls/certs/ca-bundle.crt. It is read by:

  • api and worker through the docker-compose.ca.yml overlay: the LDAP directory, the SMTP server, Orange WCO and Keycloak, when their certificate comes from an internal CA (AD CS, a corporate TLS proxy) the image does not know,
  • nginx through the TLS overlay.
# in .env; a path on the host
ONCALL_CA_FILE=/etc/pki/tls/certs/company-ca.pem
docker compose -f docker-compose.yml -f docker-compose.ca.yml up -d
# together with HTTPS
docker compose -f docker-compose.yml -f docker-compose.tls.yml -f docker-compose.ca.yml up -d

SMTP, WCO and Keycloak add the CAs from the file to the image's public CAs rather than replacing them, so the same bundle serves a server on the internal network and a public one. The LDAP directory trusts this bundle alone, so it must hold the domain controllers' CA. Certificate verification cannot be turned off.

The file must exist and be readable by the image's user (0644 permissions) before the containers start: Compose creates a missing mount source as an empty directory. The start does not notice that, the first connection of each feature does: a directory sign-in (reason=ca_file_unreadable), an e-mail send (Plik CA jest niedostępny) or a WCO number switch (ONCALL_CA_FILE is unreadable). Sign-in with local accounts keeps working. The default systemd path starts this overlay. A changed file takes effect after api and worker restart.

SMTP server

The project does not host mail. Notifications from the queue and the alert about a failed backup go out through the external server in ONCALL_SMTP_HOST, with ONCALL_EMAIL_FROM as the sender. The application supports both ways a server can accept it:

  • With a login. ONCALL_SMTP_USERNAME and ONCALL_SMTP_PASSWORD are set; the application logs in (SMTP AUTH) before every send. A refused username or password ends the message as failed, without a retry.
  • Without a login. Both variables are empty; the application introduces itself in EHLO with the name in ONCALL_SMTP_LOCAL_HOSTNAME and hands the message over straight away, and the relay decides by that name or by the address whether it may send. The relay's refusal is final as well. An empty ONCALL_SMTP_LOCAL_HOSTNAME means the system's name, in a container usually its identifier, so a relay that trusts the name needs this variable.

Only one of the two login variables stops api and worker from starting, with an explanation in the log: a username without a password would fail to authenticate, and a password without a username would send mail without logging in. A value of nothing but spaces counts as empty; otherwise the username and password are used exactly as written.

ONCALL_SMTP_PORT, ONCALL_SMTP_USE_TLS and ONCALL_SMTP_STARTTLS choose the connection:

Connection Port USE_TLS STARTTLS
upgraded to TLS with STARTTLS (default) 587 false true
TLS from the first byte 465 true false
unencrypted, e.g. a relay on the internal network 25 false false

The application does not accept both switches at once and will not start. A server that does not offer STARTTLS needs ONCALL_SMTP_STARTTLS=false, otherwise every send fails. An example of a relay without a login:

# in .env
ONCALL_SMTP_HOST=relay.company.example
ONCALL_SMTP_PORT=25
ONCALL_SMTP_USERNAME=
ONCALL_SMTP_PASSWORD=
ONCALL_SMTP_LOCAL_HOSTNAME=oncall.company.example
ONCALL_SMTP_STARTTLS=false
ONCALL_EMAIL_FROM="On-call <oncall@company.example>"

The server's certificate is always verified, with STARTTLS and with TLS from the first byte. A server with a certificate from an internal CA the image does not know fails every send with certificate verify failed: self-signed certificate in certificate chain (or unable to get local issuer certificate). That CA goes into the deployment's CA file, which the docker-compose.ca.yml overlay mounts into api (the backup alert) and worker (the notifications). When the file cannot be read, every send fails with Plik CA jest niedostępny.

The change takes effect after api and worker restart. Whether mail gets through is checked by the test alert ./deploy/backup/oncall-backup.sh alert --test, see Verification.

Data retention

Six tables grow with every use of the application and nothing but retention ever deletes from them: the audit log (audit_events), the e-mail queue with the full text of every message (notification_outbox), generator runs (schedule_runs), sessions (sessions), the one-time activation and password reset links (account_tokens) and the remembered state of availability ranges for undoing a save (availability_range_snapshots). The worker process (worker) once every ONCALL_RETENTION_INTERVAL_SECONDS (an hour by default) deletes the rows older than the configured age, oldest first, in batches of ONCALL_RETENTION_BATCH_SIZE (1000 by default) rows, each in a short transaction of its own, at most ONCALL_RETENTION_MAX_BATCHES (20 by default) batches per table in one pass. Whatever is left is simply older on the next pass: a database that grew for years is cleaned up gradually, and an interrupted pass breaks nothing.

On the same rhythm the worker closes the swap requests whose day passed with no decision (see Date passed). That is not retention: the request stays in the database as a closed one.

Data Default What retention never touches
audit: operations (ONCALL_RETENTION_AUDIT_DAYS) 365 days nothing; a republish reads whom a schedule correction replaced from the duty itself, not from the log
audit: sign-ins and refused attempts (ONCALL_RETENTION_LOGIN_AUDIT_DAYS) 90 days the last five minutes, which the sign-in throttle reads
sent, failed, skipped and cancelled e-mails (ONCALL_RETENTION_OUTBOX_DAYS) 90 days messages waiting or being sent, whatever their age
finished generator runs (ONCALL_RETENTION_RUNS_DAYS) 30 days queued and running runs
expired sessions and activation or password reset links a day after expiry, no setting sessions and links still valid
the state of availability ranges kept for undoing a save a day after the save, no setting nothing; Undo works for a few seconds

0 in any *_DAYS variable switches that category off. Retention is on by default, also after an update from a release that did not have it: the first pass after the start begins removing the backlog. To keep older audit history, set ONCALL_RETENTION_AUDIT_DAYS=0 in .env before updating, or take a database backup - deleted entries cannot be recovered. The “Audit” screen shows the administrator the ages in force, and every pass leaves an event=retention record with the number of deleted rows in the worker process's logs, see Worker process metrics.

After rows are deleted PostgreSQL reuses the freed space but does not shrink the files on disk: retention stops the growth, it does not reverse it. The table sizes are shown by:

docker compose exec db psql -U oncall -d oncall -c "select relname, pg_size_pretty(pg_total_relation_size(oid)) from pg_class where relname in ('audit_events', 'notification_outbox', 'schedule_runs', 'sessions', 'account_tokens', 'availability_range_snapshots')"

The space taken by years without retention is given back once, in a maintenance window, by VACUUM FULL audit_events, notification_outbox; - the tables are locked while they are rewritten.

Database password

.env.example and docker-compose.yml have a default PostgreSQL password, the same in every copy of the repository. It is publicly known and exists solely for the convenience of local work: docker compose up on your own computer works without any additional configuration.

Every deployment other than a local one - a test server, a pre-production server, a production server, any machine shared with others - sets two values in .env before the first start:

  • POSTGRES_PASSWORD - a unique, random password for this deployment, e.g. from openssl rand -hex 32;
  • ONCALL_DATABASE_URL - the address with that same password and the same user and database as POSTGRES_USER and POSTGRES_DB.
POSTGRES_PASSWORD=<unique password>
ONCALL_DATABASE_URL=postgresql+asyncpg://oncall:<the same password>@db:5432/oncall

api and worker read the same ONCALL_DATABASE_URL, so it is one change in .env. A password from openssl rand -hex has only digits and the letters a-f; characters such as @, :, /, # or % have to be percent-encoded in the address (@ is %40).

The postgres image reads POSTGRES_PASSWORD only once, when it initialises the empty oncall-postgres-18 volume. On an existing database a change in .env changes nothing in PostgreSQL, and api and worker stop connecting. The password of a running database is changed first in the database itself, then in .env:

docker compose exec db psql -U oncall -d oncall -c '\password oncall'
# in .env: the new POSTGRES_PASSWORD and the same password in ONCALL_DATABASE_URL
docker compose up -d

psql asks for the new password twice and does not store it in the shell history. docker compose up -d recreates the containers whose configuration has changed.

Trust boundary

In docker-compose.yml the db service publishes no port: PostgreSQL listens on 5432 only in this project's Compose network, where api and worker connect to it. The database cannot be reached either from other machines or through localhost on the host. CI makes sure that neither the base file nor any overlay in the repository adds a port to it (.github/scripts/compose-hardening.sh).

The password therefore protects the database from whatever has access to the container network:

  • from other containers attached to the Compose network, e.g. a reverse proxy directing traffic to web:8080;
  • from a compromised web service, which is in the same network as the database;
  • under Docker on Linux also from users of the host itself, because the container's address in the bridge network is reachable from the host.

Whoever has access to the Docker or Podman daemon on the host has full access to the database regardless of the password. An overlay of your own that adds a port to the db service moves the database outside this boundary: the unique password is then its only protection, and the port should listen only on 127.0.0.1.

Container privileges

Every service runs with a read-only root filesystem, with no kernel capabilities (cap_drop: [ALL]) and with no-new-privileges. It writes only to its own tmpfs mounts and volumes:

Service User Writes Ports in the container
db postgres (70) the oncall-postgres-18 volume, /var/run/postgresql, /tmp 5432
api 10001 /tmp 8000
worker 10001 /tmp -
web 101 (nginx) /tmp, /etc/nginx/conf.d 8080, 8443
  • web listens on 8080 and 8443. An unprivileged user cannot open a port below 1024, so nginx in the container uses 8080 (HTTP) and 8443 (HTTPS). ONCALL_WEB_HTTP_PORT and ONCALL_WEB_HTTPS_PORT still choose the host ports. A reverse proxy in the same Compose network directs traffic to web:8080.
  • The TLS key is read by user 101. The owner and permissions of the key - see TLS.
  • The database gets a few capabilities back. The postgres image's entrypoint script starts as root, hands the data directory over to the postgres user and switches to it, for which it needs CHOWN, DAC_READ_SEARCH, FOWNER, SETUID and SETGID. The database server itself then runs with none.
  • tmpfs is RAM. nginx's temporary files (large API responses) count towards the container's memory.

CI checks these settings for the base file and every overlay (.github/scripts/compose-hardening.sh) and rejects an image that would run as root.

Updating

The Compose files belong to the release just as the images do: they assume the same ports, users and write paths. Take them from the same git tag as ONCALL_VERSION:

git fetch --tags
git checkout v<new number>
# in .env: ONCALL_VERSION=<new number>
docker compose pull
docker compose up -d

Database migrations run at the start of api. Rolling back to the previous version is the same sequence with the previous number - details in Releases and versions.

From the release with data retention, the first start after an update begins removing audit entries about operations older than a year and sign-ins older than 90 days. To keep older history, switch it off in .env before updating, see Data retention.

Building from the repository (development work)

Building the images from the current checkout is an overlay on the base file, just like TLS. The docker-compose.dev.yml file replaces only the source of the images; the variables, healthchecks, volumes and ports stay as in production (CI makes sure the overlay changes nothing else).

cp .env.example .env
# ONCALL_VERSION=dev  (the base file requires a value; the overlay builds locally anyway)
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build

To avoid repeating -f, put this into .env once:

COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml

and from then on docker compose up --build builds from the repository. The local images are named oncall-api:dev and oncall-web:dev, so they never overwrite an image pulled from the registry.

Documentation in the image

The web image contains this documentation as static HTML. It is produced while the image is built:

docs/*.md ──► frontend/scripts/build-docs.mjs ──► frontend/public/docs/ ──► dist/docs/

The script is hooked into prebuild in frontend/package.json, so npm run build always renders the current documentation. That is why the build context of the web image is the repository root, not frontend/: docs/ lies outside the application directory.

The same script in --site mode renders the standalone site published on GitHub Pages - see Releases and versions.

Outside the image:

cd frontend
npm install
npm run build:docs        # output in frontend/public/docs/
npm run build:docs:site   # standalone site in site/ (as on GitHub Pages)

The script is at the same time a test of the documentation: it aborts the build when an .md file is not listed in docs/toc.json (or the other way round), when a link leads outside the documentation tree, and when a # anchor matches no heading.

Running locally without containers

Backend:

docker compose up -d db
cd backend
uv sync --extra dev
uv run alembic upgrade head
ONCALL_ADMIN_USERNAME=admin ONCALL_ADMIN_PASSWORD='change-me-now' uv run python -m oncall.seed_admin
uv run uvicorn oncall.main:app --reload

(docker compose up -d db requires ONCALL_VERSION in .env, although the database does not use it - any value will do. uv must be the version given in required-version in backend/pyproject.toml; any other version refuses to work and prints the command that installs it.)

Frontend:

cd frontend
npm install
npm run build:docs   # documentation at http://localhost:5173/docs/
npm run dev          # http://localhost:5173, /api forwarded to :8000

Podman

podman compose delegates to the installed Compose provider and accepts the same files unchanged. Five things are worth knowing:

  • The API socket. The Compose provider talks to Podman through the user socket. If the command ends with the message “failed to connect to the docker API”, run systemctl --user start podman.socket once.
  • Rootless mode. Ports below 1024 require privileges; the default 8080 and 8443 work without them.
  • Container users have different numbers on the host. The TLS key that nginx reads (101 in the container) gets its owner through podman unshare chown - see TLS.
  • A missing mount source behaves the same as under Docker: a non-existent host path is created as an empty directory instead of stopping the start. That is why the base file mounts nothing from the host, and the TLS mounts are in a separate overlay, which checks every file at start - see TLS.
  • Start after a reboot. The systemd user unit, linger and the setup script - see Systemd (Podman Compose).

Checking the files themselves, without starting anything:

docker compose config --quiet
docker compose -f docker-compose.yml -f docker-compose.dev.yml config --quiet
podman compose config --quiet