# Catodi for a household: `docker compose -f compose.yaml up -d`, then open http://<this machine>:8096.
# No .env and nothing to fill in. The server, its transcode worker and Postgres; the worker finds the server by
# itself (the join token on the shared data volume), so it needs no enrolment.
name: catodi
services:
  catodi:
    image: gitea.mauro.top/urogna/catodi:latest
    restart: unless-stopped
    ports:
      # Port 8096 already taken (another media server still runs there)? Publish "18096:8096" instead (D22). Any
      # other port works too: people then type it with the address (myserver:9000).
      - "8096:8096"
    volumes:
      - data:/data
      - cache:/cache
      # Your media, read-only below /media: first run offers the folders there (and one level below) as libraries,
      # and Catodi never writes to them. One folder, or one line per folder (/path/to/films:/media/films:ro):
      # - /path/to/your/media:/media:ro
    networks: [default, db]
    depends_on:
      postgres:
        condition: service_healthy

  # The worker runs ffmpeg and ffprobe; the server image has neither. One worker per GPU (render node).
  catodi-worker:
    image: gitea.mauro.top/urogna/catodi-worker:latest
    restart: unless-stopped
    volumes:
      # Read-only: the worker only reads the join token here.
      - data:/data:ro
      - cache:/cache
    depends_on:
      catodi:
        condition: service_healthy
    # GPU: uncomment one block. Without one the worker encodes on the CPU.
    # Intel or AMD (VAAPI/QSV): the render node under its own name (the Intel driver finds the GPU by that name, so
    # never map renderD129 as renderD128) and the host's `render` group id (`getent group render`).
    # devices:
    #   - /dev/dri/renderD128:/dev/dri/renderD128
    # group_add:
    #   - "989"
    # NVIDIA (needs the NVIDIA Container Toolkit on the host):
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: 1
    #           capabilities: [gpu, video]

  # Reached only by the server, on the internal db network, and never published, so it needs no password
  # (the server's default DATABASE_URL is postgres://postgres@postgres/catodi).
  postgres:
    image: pgvector/pgvector:pg17
    restart: unless-stopped
    environment:
      POSTGRES_DB: catodi
      POSTGRES_HOST_AUTH_METHOD: trust
    volumes:
      - pg:/var/lib/postgresql/data
    networks: [db]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d catodi"]
      interval: 2s
      timeout: 3s
      retries: 30

networks:
  default:
  # Internal and joined only by catodi and postgres: the worker (ffmpeg on media nobody vetted) never reaches the
  # password-less database; it talks to the server over HTTP with its token.
  db:
    internal: true

volumes:
  data:
  cache:
  pg:
