---
version: "{{ skylab_compose_version }}"


networks:
  plex:
    name: plex
    driver: overlay
    ipam:
      driver: default
      config:
        - subnet: {{ app.networks.ext }}


volumes:
{% for key, value in app.volumes.items() %}
  plex-{{ key }}:
    name: datastore{{ value }}
    driver: glusterfs
{% endfor %}
  plex-data:
    name: plex-data
    driver: local
    driver_opts:
      type: nfs
      o: "addr={{ app.settings.mediastore }},ro"
      device: ":/nfs/plex"


services:
  server:
    image: plexinc/pms-docker:{{ app.versions.server }}
    hostname: plex-media-server
    networks:
      - plex
    ports:
      - published: {{ app.ports.32400 }}
        target: 32400
        protocol: tcp
        mode: ingress
      - published: {{ app.ports.3005 }}
        target: 3005
        protocol: tcp
        mode: ingress
      - published: {{ app.ports.8324 }}
        target: 8324
        protocol: tcp
        mode: ingress
      - published: {{ app.ports.32469 }}
        target: 32469
        protocol: tcp
        mode: ingress
      - published: {{ app.ports.1900 }}
        target: 1900
        protocol: udp
        mode: ingress
      - published: {{ app.ports.32410 }}
        target: 32410
        protocol: udp
        mode: ingress
      - published: {{ app.ports.32413 }}
        target: 32413
        protocol: udp
        mode: ingress
      - published: {{ app.ports.32414 }}
        target: 32414
        protocol: udp
        mode: ingress
    volumes:
      - type: volume
        source: plex-config
        target: /config
        read_only: false
      - type: volume
        source: plex-data
        target: /data
        read_only: true
      - type: volume
        source: plex-personal
        target: /personal
        read_only: false
    environment:
      TZ: "Americas/New_York"
      ALLOWED_NETWORKS: {{ app.settings.internal_subnets | join(',') }}
      PLEX_UID: "{{ _app_account.uid }}"
      PLEX_GID: "{{ _app_account.uid }}"
    deploy:
      replicas: 1
      placement:
{% if app.settings.exclude_hosts is defined %}
        constraints:
{% for host in app.settings.exclude_hosts %}
          - node.hostname!={{ host }}
{% endfor %}
{% endif %}
