
services:
  komodo-mongo:
    image: mongo:7.0
    container_name: mongo-db${KOMODO_NODE_ID}
    hostname: mongo-db${KOMODO_NODE_ID}
    ports:
      - 27017:27017
    restart: always
    networks:
      - komodo_internal
    extra_hosts:
      - "mongo-db1:${KOMODO_DB_PRI}"
      - "mongo-db2:${KOMODO_DB_SEC}"
    command: ["--replSet", "rs${LXC_NUM}", "--bind_ip_all", "--port", "27017"]
    volumes:
      - /docker/mongo:/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"
    ports:
      - "9120:9120"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /root/.ssh:/home/komodo/.ssh:ro
      - /docker/komodo/config:/config
      - /docker/komodo/backups:/backups
      - /docker/komodo/core-etc:/etc/komodo
      - /docker/komodo/var:/var/lib/komodo
      - /docker/komodo/repo-cache:/repo-cache
      - /docker:/docker
    depends_on:
      - ${KOMODO_DB_HOSTNAME}
    restart: unless-stopped
    extra_hosts:
      - "mongo-db1:${KOMODO_DB_PRI}"
      - "mongo-db2:${KOMODO_DB_SEC}"
    environment:
      - KOMODO_DATABASE_URI=mongodb://${KOMODO_DB_PRI}:27017,${KOMODO_DB_SEC}:27017/komodo?replicaSet=rs${LXC_NUM}
      - KOMODO_PASSKEY=${KOMODO_PERIPH_PASS}
      - KOMODO_INIT_ADMIN_PASSWORD=${KOMODO_ADMIN_PASS}
      - KOMODO_INIT_ADMIN_USERNAME=admin
      - KOMODO_DISABLE_CONFIRM_DIALOG=false
      - KOMODO_MONITORING_INTERVAL=5-sec
      - KOMODO_RESOURCE_POLL_INTERVAL=1-hr
      - KOMODO_LOCAL_AUTH=true
      - KOMODO_DISABLE_USER_REGISTRATION=false
      - KOMODO_ENABLE_NEW_USERS=false
      - KOMODO_DISABLE_NON_ADMIN_CREATE=false
      - KOMODO_TRANSPARENT_MODE=false
      - KOMODO_LOGGING_PRETTY=false
      - KOMODO_PRETTY_STARTUP_CONFIG=true
      - KOMODO_OIDC_ENABLED=false
      - KOMODO_GITHUB_OAUTH_ENABLED=false
      - KOMODO_GOOGLE_OAUTH_ENABLED=false
      - KOMODO_TITLE=Komodo
    labels:
      - "komodo.skip=true"
      - "traefik.enable=${KOMODO_TRAEFIK_ENABLED}"
      # 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=${TRAEFIK_ENTRY_POINTS}"
      - "traefik.http.routers.komodo-admin-${KOMODO_NODE_ID}.tls.certresolver=${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=${TRAEFIK_ENTRY_POINTS}"
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.tls.certresolver=${TRAEFIK_RESOLVER}"
      - "traefik.http.routers.komodo-shared-${KOMODO_NODE_ID}.tls=true"
      # --- SHARED SERVICE (THE FIX) ---
      # Since we are in Host Mode, Traefik (also on Host Mode) finds Komodo at 127.0.0.1
      - "traefik.http.services.komodo-common-svc.loadbalancer.server.url=http://127.0.0.1:9120"

    networks:
      - komodo_internal
      - komodo_external

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