On-call without guesswork.
Fair duty rotations for infrastructure teams: PRIMARY, SECONDARY and the 11-19 shift, generated by a CP-SAT solver and run day to day with swaps, availability, reports, e-mail and calendar feeds. Self-hosted, two containers, Polish first and English second.
Dokumentacja (PL) · Documentation (EN) · Releases · Running · Development
| Fair by construction | Runs the day to day | Fits the team |
|---|---|---|
| A CP-SAT generator balances primary, secondary, the 11-19 shift, weekends and holidays over the previous 12 months, and shows the fairness criterion it met. Drafts never replace a published schedule on their own. | Single-day swaps with acceptance and approval, availability and preferences, coordinator overrides, a monthly report, a fairness report and an audit log. | E-mail notifications, ICS calendar feeds, expiring viewer links, LDAP / Active Directory and Keycloak SSO sign-in, a Polish and English interface, and the brand as a deployment setting. |
The name shown in the interface, e-mails and calendar feeds is a deployment
setting (ONCALL_APP_NAME, with an optional ONCALL_APP_SUBTITLE), so the
repository itself carries no organisation brand. Product and user documentation
lives in docs/ (Polish) and docs/en/
(English), is rendered into static HTML served by the application itself at
/docs/ and /docs/en/, and is published from the same source at
https://lowicz.github.io/oncall/. The earlier contents of docs/ - plans, QA
reports, screenshots and test scripts - are preserved unchanged in
archive/docs/.
Every release publishes two images, ghcr.io/lowicz/oncall-api (services
api and worker) and ghcr.io/lowicz/oncall-web, tagged with the release
version. docker-compose.yml runs them; ONCALL_VERSION in .env says which
version, and Compose refuses to start without it.
cp .env.example .env # set ONCALL_VERSION, ONCALL_ADMIN_USERNAME, ONCALL_ADMIN_PASSWORD
docker compose pull
docker compose up -dThe frontend is served at http://localhost:8080, while the API is available through the same origin under /api.
Versions, upgrades, rollback and image verification: docs/wdrozenie/wydania.md.
To start the Podman stack after reboot without an interactive login, use the user systemd unit: docs/wdrozenie/systemd.md.
Such a host moves to another release, .env merged with the new .env.example and the unit restarted, with one command: docs/wdrozenie/aktualizacja.md.
curl -fsSL https://raw.githubusercontent.com/lowicz/oncall/main/deploy/update.sh |
sh -s -- 1.2.3Building from the checkout is an overlay on the same file (ONCALL_VERSION
can be anything, e.g. dev; the overlay names the local images
oncall-api:dev and oncall-web:dev):
docker compose -f docker-compose.yml -f docker-compose.dev.yml up --buildPut COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml in .env to make
plain docker compose up --build do the same. CI (.github/workflows/ci.yml)
runs the backend and frontend gates, the PostgreSQL concurrency and schema
suites, both image builds and every Compose combination on each pull request,
next to SonarCloud, CodeQL and Dependency Review; a tag vX.Y.Z publishes the images
(.github/workflows/release.yml). Required checks and repository security
settings: docs/wdrozenie/wydania.md.
Test coverage on main, as SonarCloud measures it from the reports the two
test jobs upload. Both test jobs fail below 100% of lines and branches
(fail_under in backend/pyproject.toml, thresholds in
frontend/vite.config.ts), so new code arrives with its tests:
The API container derives its Uvicorn worker count from the cgroup CPU quota or
process affinity, with a minimum of two processes. Set ONCALL_API_WORKERS to a
positive integer to override it. Each process owns its SQLAlchemy connection
pool, so keep the chosen worker count and PostgreSQL max_connections aligned.
Read-heavy deployments also use a bounded per-process cache for resolved
published duties (1 s). A process empties its own cache when it commits a
change to duties, so the next request it serves reads the change; another API
process can still serve the previous duties until its entry expires. Set
ONCALL_EFFECTIVE_ASSIGNMENTS_CACHE_SECONDS=0 for strict cross-worker
read-after-write visibility. Authenticated sessions are not
cached: every request revalidates the session, so signing out, resetting a
password or deactivating an account takes effect at once.
For HTTPS, the web container mounts three separate files - the server certificate without its chain, the private key, and the complete system trust CA bundle - through an overlay compose file:
docker compose -f docker-compose.yml -f docker-compose.tls.yml up -ddocker 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 --reloaduv must be the release pinned by required-version in backend/pyproject.toml;
any other refuses to run and prints the command that installs the right one.
The gates CI runs, in the same order: uv run ruff check ., uv run ruff format --check .,
uv run mypy, uv run pytest -n auto --dist worksteal --cov, uv run python scripts/openapi_snapshot.py. The
PostgreSQL suites need a disposable server:
docker compose -f docker-compose.contract.yml up -d and
ONCALL_TEST_POSTGRES_URL=postgresql+asyncpg://oncall_contract:oncall_contract@127.0.0.1:55432/oncall_contract uv run pytest tests/test_concurrency_postgres.py tests/test_schema_postgres.py.
The single sign-on test needs the local Keycloak:
docker compose -f docker-compose.keycloak.yml up -d --wait and
ONCALL_E2E_KEYCLOAK_URL=http://localhost:8180 uv run pytest tests/test_sso_keycloak.py.
For Docker Compose, put the credentials in .env. On every API start the bootstrap
creates the account or synchronizes its password, display name, admin role and active
status. A password rotation therefore takes effect after rebuilding/restarting api.
Passwords must contain at least 12 characters. With both variables unset, bootstrap is
skipped.
To populate a local environment with a two-week schedule and three example accounts:
ONCALL_DEMO_PASSWORD='local-demo-password' uv run python -m oncall.seed_demoThe logins are admin, anna, marek, ola, piotr, and viewer; the password
comes from the environment variable. Set ONCALL_DEMO_EMAIL_DOMAIN (for example
example.com) to also assign {login}@{domain} notification addresses to the demo
accounts. ONCALL_DEMO_NAMES replaces the four member names (exactly four,
comma-separated, in the order of the logins; the default set is Polish), which is how
the screenshot above was made with English names.
cd frontend
npm install
npm run dev
npm run build:docs # renders docs/*.md to public/docs, served at /docs/
npm run build:docs:site # the same pages as a standalone site (site/), as on GitHub Pagesnpm run build renders the documentation first (prebuild), so a production
build can never ship stale pages. The renderer also fails the build on a page
missing from docs/toc.json, a link leaving the documentation tree, or an
anchor matching no heading. .github/workflows/pages.yml publishes the --site
output to GitHub Pages on every change to docs/ on main; nothing is
authored twice.
The interface, the API's answers and the documentation come in Polish (the
default: a new visitor sees Polish whatever the browser prefers) and English.
The choice is made in the account menu, on the "More" screen or under the
sign-in form, is kept in the browser (localStorage, key oncall-language)
and is sent to the API as Accept-Language, which picks the language of
refusals, validation messages, rule warnings and holiday names per request and
answers with Content-Language. What the application records or sends rather
than answers - audit summaries, decision notes, generator diagnostics, e-mails,
calendar feeds, the operator's log - stays Polish.
Where the words live: frontend/src/i18n/pl/ (the source of truth and the
type) and frontend/src/i18n/en/ for the interface, backend/src/oncall/i18n/
for the API, docs/ and docs/en/ for the documentation. The Polish
interface and documentation are locked by snapshot tests
(frontend/src/test/polish-baseline.test.tsx,
frontend/scripts/build-docs.test.mjs): a diff there is a change a Polish
reader would see.
The documentation describes every feature in full, in Polish and in English; the paragraphs below say what each one is and keep the settings that are documented nowhere else.
Schedule generator. Administrators and coordinators pick hybrid (the
default), daily or weekly and generate a draft for up to 35 days, from the
first day no published schedule covers; the CP-SAT model uses role
eligibility, hard unavailability, soft preferences and the previous 12 months
of assignments, counts Saturdays, Sundays and Polish statutory holidays as 2
points, and balances primary, secondary, the 11-19 shift, weekends and holidays
each on its own. A result stays a draft until a coordinator moves it to
proposed and confirms publication; publication is serialized in PostgreSQL,
validates complete coverage and supersedes only the published schedules the new
range fully covers. The solver's default worker count comes from the
container's CPU quota (capped at eight; ONCALL_SOLVER_WORKERS overrides it,
ONCALL_SOLVER_LOG=true enables search output) and its wall-clock budget
(5-300 s, 15 by default) is a field of the scheduling policy, next to the
weights fairness_weight, continuity_weight and preference_weight
(0-100, audited, applied to the next run). Rules, weights and acceptance
criterion: generator ·
EN; the CP-SAT model as first built:
archive/docs/SOLVER.md.
Single-day swaps. A team member asks for a replacement for one date and
role, even under a weekly rotation; only eligible, available members not
already on the opposite role are offered. The replacement accepts first, then
by default a coordinator or administrator approves; the team policy
coordinator_swap_approval_required turns that stage off, so the acceptance
itself writes the swap in and coordinators get an informational notification
instead. A rejection needs a reason, a withdrawal does not, and writing the swap in
changes only the selected slot and increments the published version.
Swaps · EN.
E-mail notifications. Swap events, publications, coordinator overrides,
rotation notices (whoever starts a role hears about it on the last Polish
working day before and on the first day, with a link to ONCALL_SWITCH_URL
when PRIMARY starts) and the working-day digest telling every coordinator and
admin who is on duty today and on the days off that follow
(ONCALL_COORDINATOR_DIGEST_HOUR, default 8) enqueue
rows in notification_outbox inside the business transaction; the worker
service (python -m oncall.worker) drains them with exponential backoff through channel providers (email
today, more can plug into the same outbox). Delivery is at-least-once under a lease
(ONCALL_NOTIFICATION_LEASE_SECONDS, default 300), and every message carries
the outbox row's id as a fixed Message-ID, so a repeat is recognisable. SMTP
is external, configured with ONCALL_SMTP_HOST, ONCALL_SMTP_PORT,
ONCALL_SMTP_USERNAME, ONCALL_SMTP_PASSWORD, ONCALL_SMTP_USE_TLS /
ONCALL_SMTP_STARTTLS, ONCALL_EMAIL_FROM and, when the server insists on a
client name, ONCALL_SMTP_LOCAL_HOSTNAME; the server's certificate is always
verified (ONCALL_CA_FILE with the docker-compose.ca.yml overlay
for an internal CA); without ONCALL_SMTP_HOST messages
are marked skipped with the reason in the outbox, except the working-day digest,
which is not queued at all. The username and password
go together: both log in with SMTP AUTH, neither sends to a relay that trusts
the EHLO name, and one alone stops the application at startup. Addresses come
from the user accounts, edited on the "Osoby" screen.
Notifications ·
EN.
Worker metrics. The worker reports what it is doing on its own logger,
oncall.metrics, one logfmt record per measurement: queue and outbox are
sampled every ONCALL_METRICS_INTERVAL_SECONDS (default 60) whether or not
anything is happening, so a gap means the worker stopped; generation and
generation_abandoned are events. Nothing is written to the database and the
API emits none of it. The fields and what each outcome means:
metrics · EN.
ICS calendar feeds. Calendar applications subscribe to revocable token
URLs under /calendar; a member's personal feed exposes only their own duties
as all-day events with the schedule version as the event sequence, so overrides
and swaps arrive as updates, and an administrator can issue a feed for a viewer
share link, scoped to its range and expiry.
Feeds · EN.
Temporary viewer links. Administrators create one-time links bound to a
recipient label, a date range and an expiry of at most 30 days; opening
/share/{token} exchanges the token for a limited viewer session that sees
only the published schedule clipped to the range, expires with the link and
dies when it is revoked. Share links ·
EN.
Fairness report. Actual duties from published and superseded schedules over a rolling 12-month window: weekdays count 1 point, Saturdays, Sundays and Polish statutory holidays 2, and primary, secondary, weekends, holidays and 11-19 shifts are balanced separately against each member's eligible days. Coordinators see the team, members see themselves. Fairness · EN.
Historical schedule import. Coordinators validate and import a UTF-8 CSV
with service_date (YYYY-MM-DD), role (primary, secondary or
late_shift) and assignee_name (an exact display name); the screen offers a
template and examples/history.csv is a ready one.
Import ·
EN.
Audit log. Sign-ins and failed sign-ins, availability changes, the swap
lifecycle, generation, publication, overrides, policy changes, imports, share
links and feed tokens, and account administration are recorded in
audit_events inside the same transaction as the change, with the actor label
denormalized so the trail survives account deletion. Administrators browse it
on the "Audyt" screen. Audit ·
EN.
LDAP / Active Directory login. Off by default; ONCALL_LDAP_ENABLED=true
and the ONCALL_LDAP_* variables in .env.example set the server, service
bind, search base and filter (which must contain {username}) and the
attribute mapping (employeeNumber, givenName, sn, mail by default). A
service bind finds exactly one entry, a bind as that entry proves the
password, ldap:// uses StartTLS and ldaps:// TLS, always with certificate
validation (ONCALL_CA_FILE with the docker-compose.ca.yml
overlay for an internal CA). The first directory login creates an active
viewer keyed by the personnel number and later logins sync the name and
e-mail while the local role, status, rotation and eligibility stay; an account
an administrator created beforehand links on its first directory login when
its personnel number equals employeeNumber (audit auth.ldap_linked), and a
mismatch ends in a 409 recorded as auth.ldap_identity_conflict. Every
attempt writes event=login and, when the directory stopped it,
event=ldap_auth lines that never carry secrets.
LDAP · EN.
SSO login (Keycloak). Off by default; ONCALL_SSO_ENABLED=true with
ONCALL_SSO_ISSUER and ONCALL_SSO_CLIENT_ID adds a "Zaloguj przez SSO"
button under the password form. The API runs the OpenID Connect Authorization
Code flow with PKCE against a public Keycloak client, verifies the ID token and
opens a session for the existing active account whose personnel number equals
the token's employeeNumber claim; it creates and converts no accounts, so
local and LDAP sign-in keep working, also when Keycloak is down. Signing out
ends the On-call session only.
SSO · EN.
