# Teaching template: split web, AI and video into separate VMs/containers for production.
services:
  postgres:
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: perfectworld
      POSTGRES_USER: perfectworld
      POSTGRES_PASSWORD: CHANGE_ME_LONG_RANDOM
    volumes:
      - /srv/fast/postgres:/var/lib/postgresql/data
    shm_size: 2gb
    restart: unless-stopped
    networks: [backend]

  mediamtx:
    image: bluenviron/mediamtx:1.20.0
    volumes:
      - ./mediamtx.yml:/mediamtx.yml:ro
      - /srv/archive/video:/recordings
    ports:
      - "8554:8554"
      - "127.0.0.1:8888:8888"
      - "127.0.0.1:8889:8889"
      - "8189:8189/udp"       # WebRTC media; firewall to intended clients
    restart: unless-stopped
    networks: [backend]

  llama:
    image: ghcr.io/ggml-org/llama.cpp:server-rocm
    devices:
      - /dev/kfd:/dev/kfd
      - /dev/dri:/dev/dri
    group_add: ["video"]
    volumes:
      - /srv/fast/models:/models:ro
    command: ["-m", "/models/replace-with-model.gguf", "--host", "0.0.0.0", "--port", "8080", "--n-gpu-layers", "99", "--split-mode", "layer"]
    expose: ["8080"]
    restart: unless-stopped
    networks: [backend]

networks:
  backend:
    internal: true
