networks:
  media-net:
    driver: bridge
  ix-databases_shared-databases:
    external: true
  pangolin:
    external: true

services:

  romm-db:
    container_name: romm-db
    image: mariadb:12.2
    restart: unless-stopped
    networks:
      - media-net
    environment:
      MARIADB_ROOT_PASSWORD: ${ROMM_DB_ROOT_PASSWORD}
      MARIADB_DATABASE: ${ROMM_DB_NAME}
      MARIADB_USER: ${ROMM_DB_USER}
      MARIADB_PASSWORD: ${ROMM_DB_PASS}
    volumes:
      - /mnt/docker-ssd/docker/appdata/romm-db/mysql:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s

  gamevault-db:
    container_name: gamevault-db
    image: postgres:17
    restart: unless-stopped
    networks:
      - media-net
    environment:
      POSTGRES_USER: ${GAMEVAULT_DB_USER}
      POSTGRES_PASSWORD: ${GAMEVAULT_DB_PASS}
      POSTGRES_DB: gamevault
    volumes:
      - /mnt/docker-ssd/docker/appdata/gamevault-db/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${GAMEVAULT_DB_USER} -d gamevault"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 30s

  plex:
    container_name: ix-plex-plex-1
    image: lscr.io/linuxserver/plex:latest
    restart: unless-stopped
    networks:
      - media-net
      - pangolin
    ports:
      - "32400:32400/tcp"
      - "1900:1900/udp"
      - "8324:8324/tcp"
      - "32410:32410/udp"
      - "32412:32412/udp"
      - "32413:32413/udp"
      - "32414:32414/udp"
      - "32469:32469/tcp"
    environment:
      TZ: ${TZ}
      PUID: ${PUID}
      PGID: ${PGID}
      VERSION: docker
      NVIDIA_VISIBLE_DEVICES: all
      NVIDIA_DRIVER_CAPABILITIES: compute,video,utility
    volumes:
      - /mnt/docker-ssd/docker/appdata/plex:/config
      - /mnt/unraid/data/media/anime:/anime
      - /mnt/unraid/data/media/movies:/movies
      - /mnt/unraid/data/media/tv:/tv
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu, video, compute]

  tautulli:
    container_name: ix-tautulli-tautulli-1
    image: ghcr.io/tautulli/tautulli:latest
    restart: unless-stopped
    networks:
      - media-net
      - pangolin
    ports:
      - "8181:8181"
    environment:
      TZ: ${TZ}
      PUID: ${PUID}
      PGID: ${PGID}
    volumes:
      - /mnt/docker-ssd/docker/appdata/tautulli:/config
    healthcheck:
      test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8181/ || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  audiobookshelf:
    container_name: ix-audiobookshelf-audiobookshelf-1
    image: ghcr.io/advplyr/audiobookshelf:latest
    restart: unless-stopped
    networks:
      - media-net
      - pangolin
    ports:
      - "13358:80"
    environment:
      TZ: ${TZ}
    volumes:
      - /mnt/unraid/data/media/books/Audiobooks:/audiobooks
      - /mnt/docker-ssd/docker/appdata/audiobookshelf/config:/config
      - /mnt/docker-ssd/docker/appdata/audiobookshelf/metadata:/metadata
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:80/ >/dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  gamevault:
    container_name: gamevault
    user: "99:100"
    image: phalcode/gamevault-backend:latest
    restart: unless-stopped
    networks:
      - media-net
      - ix-databases_shared-databases
      - pangolin
    ports:
      - "8785:8080"
    environment:
      TZ: ${TZ}
      PUID: 99
      PGID: 100
      NODE_ENV: production
      DB_HOST: gamevault-db
      DB_PORT: 5432
      DB_USERNAME: ${GAMEVAULT_DB_USER}
      DB_PASSWORD: ${GAMEVAULT_DB_PASS}
      SAVEFILES_ENABLED: "true"
      MEDIA_GC_INTERVAL_IN_MINUTES: 60
      METADATA_IGDB_ENABLED: "true"
      METADATA_IGDB_CLIENT_ID: ${METADATA_IGDB_CLIENT_ID}
      METADATA_IGDB_CLIENT_SECRET: ${METADATA_IGDB_CLIENT_SECRET}
      RAWG_API_URL: https://rawg2steam.phalco.de/api
      RAWG_API_CACHE_DAYS: 36500
      SERVER_PORT: 8080
      SERVER_HTTPS_PORT: 8443
      YES: "yes"
    volumes:
      - /mnt/unraid/data/media/Games-Apps Isos:/files
      - /mnt/unraid/data/media/Saved Games:/savefiles
      - /mnt/docker-ssd/docker/appdata/gamevault/media:/media
      - /mnt/docker-ssd/docker/appdata/gamevault/logs:/logs
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:$${SERVER_PORT}/api/status || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 300s

  romm:
    container_name: romm
    image: rommapp/romm:latest
    restart: unless-stopped
    depends_on:
      romm-db:
        condition: service_healthy
    networks:
      - media-net
      - pangolin
    ports:
      - "8457:8080"
    environment:
      TZ: ${TZ}
      DB_HOST: romm-db
      DB_PORT: 3306
      DB_USER: ${ROMM_DB_USER}
      DB_NAME: ${ROMM_DB_NAME}
      DB_PASSWD: ${ROMM_DB_PASS}
      STEAMGRIDDB_API_KEY: ${STEAMGRIDDB_API_KEY}
      ENABLE_SCHEDULED_RESCAN: ${ENABLE_SCHEDULED_RESCAN}
      GUNICORN_WORKERS: ${GUNICORN_WORKERS}
      MOBYGAMES_API_KEY: ${MOBYGAMES_API_KEY}
      IGDB_CLIENT_ID: ${IGDB_CLIENT_ID}
      RESCAN_ON_FILESYSTEM_CHANGE_DELAY: ${RESCAN_ON_FILESYSTEM_CHANGE_DELAY}
      ENABLE_SCHEDULED_UPDATE_SWITCH_TITLEDB: ${ENABLE_SCHEDULED_UPDATE_SWITCH_TITLEDB}
      SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON: ${SCHEDULED_UPDATE_SWITCH_TITLEDB_CRON}
      DISABLE_DOWNLOAD_ENDPOINT_AUTH: ${DISABLE_DOWNLOAD_ENDPOINT_AUTH}
      ROMM_AUTH_SECRET_KEY: ${ROMM_AUTH_SECRET_KEY}
      IGDB_CLIENT_SECRET: ${IGDB_CLIENT_SECRET}
      SCHEDULED_RESCAN_CRON: ${SCHEDULED_RESCAN_CRON}
      SCAN_TIMEOUT: ${SCAN_TIMEOUT}
      DISABLE_CSRF_PROTECTION: ${DISABLE_CSRF_PROTECTION}
    volumes:
      - /mnt/unraid/data/media/RomM:/romm/library
      - /mnt/docker-ssd/docker/appdata/romm/resources:/romm/resources
      - /mnt/docker-ssd/docker/appdata/romm/assets:/romm/assets
      - /mnt/docker-ssd/docker/appdata/romm/config:/romm/config
      - /mnt/docker-ssd/docker/appdata/romm/redis-data:/redis-data
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:8080/ >/dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  seerr:
    container_name: seerr
    image: ghcr.io/seerr-team/seerr:latest
    restart: unless-stopped
    networks:
      - media-net
      - ix-databases_shared-databases
      - pangolin
    ports:
      - "5055:5055"
    environment:
      TZ: ${TZ}
      DB_TYPE: postgres
      DB_HOST: shared-postgres
      DB_PORT: 5432
      DB_NAME: ${SEERR_DB_NAME}
      DB_USER: ${SEERR_DB_USER}
      DB_PASS: ${SEERR_DB_PASS}
      LOG_LEVEL: info
    volumes:
      - /mnt/docker-ssd/docker/appdata/seerr:/app/config
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:5055/ >/dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  calibre-web-automated:
    container_name: calibre-web-automated
    image: crocodilestick/calibre-web-automated:latest
    restart: unless-stopped
    networks:
      - media-net
      - pangolin
    ports:
      - "8183:8083"
    environment:
      TZ: ${TZ}
      PUID: ${CWA_PUID}
      PGID: ${CWA_PGID}
    volumes:
      - /mnt/tank/docker/appdata/autocalibreweb-clean/config:/config
      - /mnt/unraid/data/media/books/ingest:/cwa-book-ingest
      - /mnt/unraid/data/media/books/Calibre:/calibre-library
    healthcheck:
      test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8083/ >/dev/null 2>&1 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
