- backup service: nightly pg_dump with retention, recorded as a run
- GET /api/v1/status/sources: 503 when a scheduled source or the backup
missed its last two slots (for Uptime Kuma)
- worker logs to ${DATA_DIR}/logs, so they survive redeploys
- procurement: reject implausible award dates (1900, contract end dates),
skip placeholder contractors, credit framework agreements to the BBG
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6.8 KiB
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
-
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. -
cp .env.example .envand set at least:DATA_DIR=/mnt/user/appdata/politrack– database (postgres/) and raw archive (raw/) live herePOSTGRES_PASSWORD,POLITRACK_READER_PASSWORDPOLITRACK_USER_AGENTwith 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)
-
Build and start:
docker compose build docker compose up -dDocker creates
${DATA_DIR}/rawand${DATA_DIR}/logsas root, but the backend runs as a non-root user, and every fetch then fails with "Permission denied". Hand them over once after the firstup:chown -R "$(docker run --rm --entrypoint id politrack-backend -u):$(docker run --rm --entrypoint id politrack-backend -g)" "$DATA_DIR/raw" "$DATA_DIR/logs".migrateruns once (schema, seed data, source registry, job-queue tables), thenapi,web,mcpand three workers start:service queues what runs there worker-scrapescrape, social most adapters (hourly to daily) worker-bulkbulk large or slow downloads: procurement, RTR, ad libraries, EC meetings, GDELT worker-enrichenrich linking, events, legal detection, topics, corroboration, embeddings -
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 -
Open
http://<unraid-ip>:3000(web),http://<unraid-ip>:8000/api/docs(API) andhttp://<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_URLpointing at this database andprocrastinate --app=politrack.worker.app worker --queues=<queues>. Mount a raw archive volume there too (or setPOLITRACK_RAW_DIRto 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
backupservice dumps it every night at 02:30 UTC toBACKUP_DIR(default./data/backups; better a different share, e.g./mnt/user/backups/politrack) and keepsBACKUP_KEEP_DAYS(14) days. Each dump is recorded as a run ofbackup, so the status endpoint below alerts when backups stop. Restore withpg_restore -h localhost -p 5433 -U politrack -d politrack --clean <file>. For off-site copies, syncBACKUP_DIRelsewhere. - 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 optionallyapi) through the reverse proxy. Keepmcpand 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).
Monitoring
docker compose exec api politrack status– recent runs with stats and errors (tablerun).GET /api/v1/admin/runswithAuthorization: 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/sourcesreturns 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./healthzonly checks that the API reaches the database.- The
watchdogtask (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 logsonly 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.