Files
politics-tracking/docs/deployment-unraid.md
T
simonandClaude Opus 5.5 9f0e2fc115 reports: user articles that embed claims under a database seal and link each other
- /berichte lists published reports; /berichte/<slug> renders a report: Markdown subset built as React
  elements (no raw HTML), [[angabe:ID]] embeds the claim card under a seal (green 'Amtliche Daten' when a
  source is official), [text](angabe:ID|bericht:slug|person:slug|org:slug) links inline, [[bericht:slug]]
  embeds another report; a box says how many claims the text rests on; backlinks between reports.
- /berichte/verfassen (login at the proxy): own reports, editor with a picker that finds claims, reports and
  persons and inserts their codes; draft / published / withdrawn; every save kept in report_revision.
- Claim pages show the embed code, 'use in a new report' and the reports citing the claim.
- API: GET /api/v1/reports, /reports/{slug} (references resolved like permalinks, merged claims follow the
  survivor); POST/PUT for the web app with POLITRACK_AUTHOR_TOKEN on behalf of the proxy user. The web app
  trusts Remote-User only with X-Politrack-Proxy = POLITRACK_PROXY_SECRET.
- Migration 0011 (report, report_revision, report_reference, app_user.display_name); docs: data model,
  deployment (sign-in setup), design system, roadmap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 10:19:50 +01:00

8.4 KiB
Raw Blame History

Deployment on Unraid

Prerequisites

  • Unraid 6.12+ with the Docker Compose Manager plugin (Community Applications).
  • An appdata share, for example /mnt/user/appdata/politrack.
  • Network access from the server to PyPI/npm for the image builds (files.pythonhosted.org, registry.npmjs.org) – see "Troubleshooting".
  • Optional: a reverse proxy (SWAG, Nginx Proxy Manager, Traefik or Caddy) and SSO (Authentik or Authelia) if the site is exposed; an Ollama container for semantic search.

Steps

  1. Clone the repository onto the server (for example /mnt/user/appdata/politrack/src) or add it as a stack in Compose Manager pointing at this folder.

  2. cp .env.example .env and set at least:

    • DATA_DIR=/mnt/user/appdata/politrack – database (postgres/) and raw archive (raw/) live here
    • POSTGRES_PASSWORD, POLITRACK_READER_PASSWORD
    • POLITRACK_USER_AGENT with a real contact address (publishers must be able to reach you)
    • optional: POLITRACK_ADMIN_TOKEN, POLITRACK_OLLAMA_URL, API keys (YouTube, Meta Ad Library, X)
  3. Build and start:

    docker compose build
    docker compose up -d
    

    Docker creates ${DATA_DIR}/raw and ${DATA_DIR}/logs as root, but the backend runs as a non-root user, and every fetch then fails with "Permission denied". Hand them over once after the first up: chown -R "$(docker run --rm --entrypoint id politrack-backend -u):$(docker run --rm --entrypoint id politrack-backend -g)" "$DATA_DIR/raw" "$DATA_DIR/logs".

    migrate runs once (schema, seed data, source registry, job-queue tables), then api, web, mcp and three workers start:

    service queues what runs there
    worker-scrape scrape, social most adapters (hourly to daily)
    worker-bulk bulk large or slow downloads: procurement, RTR, ad libraries, EC meetings, GDELT
    worker-enrich enrich linking, events, legal detection, topics, corroboration, embeddings
  4. Initial load (otherwise the schedules pick everything up over the next day):

    docker compose exec api politrack sources list            # what exists, when it runs
    docker compose exec api politrack run parlament.persons   # members first: other adapters resolve against them
    docker compose exec api politrack run wikidata.politicians
    docker compose exec api politrack run europarl.meps
    docker compose exec api politrack run parlament.items     # votes etc. – the longest run (30-60 min)
    docker compose exec api politrack run config.social_accounts
    docker compose exec api politrack enrich
    
  5. Open http://<unraid-ip>:3000 (web), http://<unraid-ip>:8000/api/docs (API) and http://<unraid-ip>:8001/mcp (MCP).

Upgrading from the first version (v1): the schema was rewritten (0001_schema.sql). Start with a fresh database: stop the stack, move ${DATA_DIR}/postgres away, docker compose up -d, re-run the initial load. Nothing is lost that the sources can't provide again.

Scaling and separate deployments

  • More throughput: docker compose up -d --scale worker-scrape=3. Queueing locks ensure one adapter never runs twice at the same time; per-host throttling is per process, so keep one replica per queue if you are close to a publisher's rate limit.
  • Another machine (different egress IP, GPU): run the same image with POLITRACK_DATABASE_URL pointing at this database and procrastinate --app=politrack.worker.app worker --queues=<queues>. Mount a raw archive volume there too (or set POLITRACK_RAW_DIR to shared storage).

Semantic search (optional)

docker compose --profile ai up -d ollama
docker compose exec ollama ollama pull bge-m3
# .env: POLITRACK_OLLAMA_URL=http://ollama:11434
docker compose up -d

bge-m3 runs fine on CPU for this data volume. With an NVIDIA GPU, add a device reservation (deploy.resources.reservations.devices) to the ollama service.

Backups

  • Database: the backup service dumps it every night at 02:30 UTC to BACKUP_DIR (default ./data/backups; better a different share, e.g. /mnt/user/backups/politrack) and keeps BACKUP_KEEP_DAYS (14) days. Each dump is recorded as a run of backup, so the status endpoint below alerts when backups stop. Restore with pg_restore -h localhost -p 5433 -U politrack -d politrack --clean <file>. For off-site copies, sync BACKUP_DIR elsewhere.
  • Raw archive (${DATA_DIR}/raw): optional to back up – it saves refetching after parser fixes, and it can be pruned (find raw -mtime +365 -delete); missing blobs are simply refetched.

Exposing publicly

  • Expose only web (and optionally api) through the reverse proxy. Keep mcp and the DB port LAN- or VPN-only, or protect them with SSO or an API key at the proxy.
  • Read legal.md before going public (Impressum, privacy policy, §7b MedienG).

Reports and sign-in

Anyone can read published reports; writing (/berichte/verfassen…) needs a login at the reverse proxy. The proxy authenticates (Authelia, Authentik …) and passes Remote-User, Remote-Name, Remote-Email and Remote-Groups to the web container. The web app trusts these headers only when the request also carries X-Politrack-Proxy: $POLITRACK_PROXY_SECRET, which only the proxy sets, so a request straight to the web port can't pretend to be someone. The web app then calls the API's write endpoints with Authorization: Bearer $POLITRACK_AUTHOR_TOKEN (read by both web and api from .env).

  1. Put POLITRACK_AUTHOR_TOKEN and POLITRACK_PROXY_SECRET (random, e.g. openssl rand -hex 32) into .env and docker compose up -d web api.
  2. SWAG: in the site's location / after the Authelia includes, add proxy_set_header X-Politrack-Proxy "<the secret>"; and reload nginx. The SWAG Authelia include already sets the Remote-* headers (empty when nobody is signed in, which also overwrites forged ones).
  3. Authelia: if the site bypasses the login on the LAN, add a rule before the bypass that requires a login for the write paths, e.g.
    - domain: 'politrack.example.org'
      resources: ['^/(en/)?berichte/verfassen([/?].*)?$']
      policy: 'one_factor'
    
    Pages behind a bypass rule see nobody as signed in (no edit buttons there); the write pages always do.

Members of POLITRACK_REPORT_EDITOR_GROUPS (default ["admins"]) may edit and withdraw any report. Every saved version stays in report_revision.

Monitoring

  • docker compose exec api politrack status – recent runs with stats and errors (table run).
  • GET /api/v1/admin/runs with Authorization: Bearer $POLITRACK_ADMIN_TOKEN.
  • Fetch log: SELECT adapter, status, count(*) FROM fetch_log WHERE fetched_at > now() - interval '1 day' GROUP BY 1, 2;
  • Job queue: SELECT task_name, status, count(*) FROM procrastinate_jobs GROUP BY 1, 2;
  • GET /api/v1/status/sources returns HTTP 503 as soon as a scheduled source (or the backup) missed its last two slots, and lists every task with its last successful run: point an HTTP monitor (Uptime Kuma) at it. /healthz only checks that the API reaches the database.
  • The watchdog task (every 10 minutes) fails jobs of dead workers, closes abandoned runs and starts any scheduled source whose last slot was missed (Procrastinate skips slots that are more than ten minutes overdue).
  • Worker logs: ${DATA_DIR}/logs/worker-*.log (rotating), kept across redeploys; docker compose logs only covers the current containers.

Troubleshooting

pip install / npm install fail during the build with TLS errors, while other sites work. Something between the server and the internet blocks the package CDNs by host name (TLS SNI): typically a DNS filter (Pi-hole/AdGuard, router "parental control"/"web protection"), a firewall with TLS inspection, or antivirus web protection on the build machine. Check:

nslookup files.pythonhosted.org                 # resolves to a Fastly address, not 0.0.0.0 / your router?
curl -v https://pypi.org/simple/ -o /dev/null   # works?
curl -v https://files.pythonhosted.org/ -o /dev/null
curl -v https://registry.npmjs.org/ -o /dev/null

If pypi.org works but files.pythonhosted.org / registry.npmjs.org fail during the TLS handshake, allow these host names in the filter/firewall/AV (also *.pythonhosted.org, registry.yarnpkg.com if used). On Windows, the System event log (source Schannel) and the AV's web-protection log show which component reset the connection.