version: '3.8'

services:

  # See (https://tumlive-docs.pages.dev/docs/deployment/add-runner)
  runner:
    image: ghcr.io/tum-dev/gocast/runner:latest
    networks:
      - default
    environment:
      - LOG_FMT=txt
      - LOG_LEVEL=debug
      - PORT=52735 # serves the HLS files of running streams to the edge server
      - UPLOAD_PORT=8188 # receives uploaded videos from the GoCast server
      - GOCAST_SERVER=<your-gocast-host>:50056 # TODO: replace this with the address of your GoCast server
      - REALHOST={{.Node.Hostname}} # the hostname the GoCast server reaches this runner under
      - EDGE_SERVER=<your-edge-server-addr> # TODO: replace this with the address of your edge server (e.g. https://edge.example.com)
      - STORAGE_PATH=/storage/mass
      - SEGMENT_PATH=/storage/live
      - UPLOAD_PATH=/storage/uploads
    ports:
      - target: 52735
        published: 52735
        protocol: tcp
        mode: host
      - target: 8188
        published: 8188
        protocol: tcp
        mode: host
    volumes:
      - /path/to/live:/storage/live
      - /path/to/uploads:/storage/uploads
      - /path/to/mass:/storage/mass
    deploy:
      mode: global # replicate to every node
      placement:
        constraints:
          - "node.labels.runner==true"
      restart_policy:
        condition: on-failure

  # See (https://tumlive-docs.pages.dev/docs/deployment/add-vodservice)
  vodservice:
    image: ghcr.io/tum-dev/gocast/vod-service:1.7.11
    networks:
      - default
    ports:
      - target: 8089
        published: 8089
        protocol: tcp
        mode: host
    environment:
      - OUTPUT_DIR=/out
    volumes:
      - /path/to/vod:/out
    deploy:
      mode: global
      placement:
        constraints:
          - "node.labels.runner==true"

  # See (https://tumlive-docs.pages.dev/docs/deployment/setup-edge)
  edge:
    image: ghcr.io/tum-dev/gocast/edge-service:latest
    networks:
      - default
    ports:
      - target: 8090
        published: 80
        mode: host
        protocol: tcp
      - target: 8443
        published: 443
        mode: host
        protocol: tcp
    environment:
      - CERT_DIR=/cert/
      - VOD_DIR=/vod/
      - MAIN_INSTANCE=https://live.rbg.tum.de
      - ADMIN_TOKEN=123 # TODO: replace this with a random secret only known to your team (this can be used to access video files without the usually required JWT)
      - PORT=8090
    volumes:
      - /path/to/vod:/vod
      - /path/to/cert:/cert # needs to contain fullchain.pem and privkey.pem
    deploy:
      mode: global
      endpoint_mode: dnsrr
      placement:
        constraints:
          - "node.labels.edge==true"
  
  # The following services are optional and only needed if you want to use the whisper transcriber
  voice-service:
    image: ghcr.io/tum-dev/tum-live-voice-service-nvidia:0.0.5
    volumes:
      - /path/to/mass:/mass
    networks:
      - default
    deploy:
      resources:
        reservations:
          generic_resources:
            - discrete_resource_spec:
                kind: 'gpu'
                value: 0
      mode: global
      placement:
        constraints:
          - "node.labels.voiceservice==true"
    environment:
      - TRANSCRIBER=whisper
      - WHISPER_MODEL=medium
      - MAX_WORKERS=1
      - DEBUG=1
      - REC_HOST=tumlive
      - REC_PORT=50053
    ports:
      - target: 50055
        published: 50055
        protocol: tcp
        mode: host

volumes:
  mass:
  vod:
  cert:

networks:
  default:
    driver: overlay
  host:
    name: host
    external: true
