
services:
  komodo-mongo:
    image: mongo:7.0
    container_name: ${KOMODO_DB_HOSTNAME}
    restart: always
    networks:
      - komodo_internal
    command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
    volumes:
      - /docker/management/mongodb:/data/db

  komodo:
    image: ghcr.io/moghtech/komodo-core:latest
    container_name: komodo-node${KOMODO_NODE_ID}
    cpus: 2.0
    mem_limit: "2048m"
    mem_reservation: "512m"
    env_file:
      - /docker/management/.env
    ports:
      - "9120:9120"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /root/.ssh:/home/komodo/.ssh:ro
      - /docker/management/komodo/config:/config
      - /docker/management/komodo/backups:/backups
      - /docker/management/komodo/core-etc:/etc/komodo
      - /docker/management/komodo/var:/var/lib/komodo
      - /docker/management/komodo/repo-cache:/repo-cache
      - /docker:/docker
    depends_on:
      - ${KOMODO_DB_HOSTNAME}
    restart: unless-stopped
    labels:
      - "komodo.skip=true"
      - KOMODO_DATABASE_URI=mongodb://${KOMODO_DB_PRI}:27017,${KOMODO_DB_SEC}:27017/komodo?replicaSet=${KOMODO_DB_REPLICA}
      #- KOMODO_DATABASE_ADDRESS=
      - "traefik.enable=${KOMODO_TRAEFIK_ENABLED}"
      - "traefik.docker.network=komodo_external"
      # Router
      - "traefik.http.routers.komodo-admin-${KOMODO_NODE_ID}.rule=Host(`komodo${KOMODO_NODE_ID}.${TRAEFIK_DNS_SUFFIX}`)"
      - "traefik.http.routers.komodo-admin-${KOMODO_NODE_ID}.service=komodo-common-svc"
      - "traefik.http.routers.komodo-admin-${KOMODO_NODE_ID}.entrypoints=${KOMODO_TRAEFIK_ENTRYPOINTS}"
      - "traefik.http.routers.komodo-admin-${KOMODO_NODE_ID}.tls.certresolver=${KOMODO_TRAEFIK_RESOLVER}"
      - "traefik.http.routers.komodo-admin-${KOMODO_NODE_ID}.tls=true"
      # --- SHARED HA ROUTER (komodo.domain.com) ---
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.rule=Host(`komodo.${TRAEFIK_DNS_SUFFIX}`)"
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.service=komodo-common-svc"
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.entrypoints=${KOMODO_TRAEFIK_ENTRYPOINTS}"
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.tls.certresolver=${KOMODO_TRAEFIK_RESOLVER}"
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.tls=true"
      # --- SHARED SERVICE ---
      - "traefik.http.services.komodo-common-svc.loadbalancer.server.port=9123"
    networks:
      - komodo_internal
      - komodo_external

networks:
  komodo_internal:
    external: true
  komodo_external:
    driver: bridge