# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

version: "3.3"

services:
  redis-vector-db:
    image: redis/redis-stack:7.2.0-v9
    container_name: redis-vector-db
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
    ports:
      - "6379:6379"
      - "8001:8001"
  dataprep-redis-service:
    image: ${REGISTRY:-opea}/dataprep-redis:${TAG:-latest}
    container_name: dataprep-redis-server
    depends_on:
      - redis-vector-db
    ports:
      - "6007:6007"
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      REDIS_URL: ${REDIS_URL}
      REDIS_HOST: redis-vector-db
      INDEX_NAME: ${INDEX_NAME}
      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      DATAPREP_TYPE: ${DATAPREP_TYPE}
      LOGFLAG: ${LOGFLAG}
  tei-embedding-service:
    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
    entrypoint: /bin/sh -c "apt-get update && apt-get install -y curl && text-embeddings-router --json-output --model-id ${EMBEDDING_MODEL_ID} --auto-truncate"
    container_name: tei-embedding-server
    ports:
      - "6006:80"
    volumes:
      - "./data_embedding:/data"
    shm_size: 1g
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      host_ip: ${host_ip}
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://$host_ip:6006/health || exit 1"]
      interval: 10s
      timeout: 10s
      retries: 60
  embedding:
    image: ${REGISTRY:-opea}/embedding:${TAG:-latest}
    container_name: embedding-server
    depends_on:
      tei-embedding-service:
        condition: service_healthy
    ports:
      - "6000:6000"
    ipc: host
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
      HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped
  retriever:
    image: ${REGISTRY:-opea}/retriever-redis:${TAG:-latest}
    container_name: retriever-redis-server
    depends_on:
      - redis-vector-db
    ports:
      - "7000:7000"
    ipc: host
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      REDIS_URL: ${REDIS_URL}
      REDIS_HOST: redis-vector-db
      INDEX_NAME: ${INDEX_NAME}
      TEI_EMBEDDING_ENDPOINT: ${TEI_EMBEDDING_ENDPOINT}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      RETRIEVER_TYPE: ${RETRIEVER_TYPE}
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped
  tei-reranking-service:
    image: ghcr.io/huggingface/text-embeddings-inference:cpu-1.5
    entrypoint: /bin/sh -c "apt-get update && apt-get install -y curl && text-embeddings-router --json-output --model-id ${RERANK_MODEL_ID} --auto-truncate"
    container_name: tei-reranking-server
    ports:
      - "8808:80"
    volumes:
      - "./data_tei:/data"
    shm_size: 1g
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      HF_HUB_DISABLE_PROGRESS_BARS: 1
      HF_HUB_ENABLE_HF_TRANSFER: 0
      host_ip: ${host_ip}
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://$host_ip:8808/health || exit 1"]
      interval: 10s
      timeout: 10s
      retries: 60
  reranking:
    image: ${REGISTRY:-opea}/reranking-tei:${TAG:-latest}
    container_name: reranking-tei-xeon-server
    depends_on:
      tei-reranking-service:
        condition: service_healthy
    ports:
      - "8000:8000"
    ipc: host
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      RERANK_TYPE: ${RERANK_TYPE}
      TEI_RERANKING_ENDPOINT: ${TEI_RERANKING_ENDPOINT}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      HF_HUB_DISABLE_PROGRESS_BARS: 1
      HF_HUB_ENABLE_HF_TRANSFER: 0
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped
  tgi_service:
    image: ghcr.io/huggingface/text-generation-inference:2.4.0-intel-cpu
    container_name: tgi-service
    ports:
      - "9009:80"
    volumes:
      - "./data:/data"
    shm_size: 1g
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      HF_HUB_DISABLE_PROGRESS_BARS: 1
      HF_HUB_ENABLE_HF_TRANSFER: 0
      host_ip: ${host_ip}
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://$host_ip:9009/health || exit 1"]
      interval: 10s
      timeout: 10s
      retries: 100
    command: --model-id ${LLM_MODEL_ID} --cuda-graphs 0
  llm:
    image: ${REGISTRY:-opea}/llm-textgen:${TAG:-latest}
    container_name: llm-textgen-server
    depends_on:
      tgi_service:
        condition: service_healthy
    ports:
      - "9000:9000"
    ipc: host
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      LLM_ENDPOINT: ${TGI_LLM_ENDPOINT_CHATQNA}
      LLM_MODEL_ID: ${LLM_MODEL_ID}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      HF_HUB_DISABLE_PROGRESS_BARS: 1
      HF_HUB_ENABLE_HF_TRANSFER: 0
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped
  chatqna-xeon-backend-server:
    image: ${REGISTRY:-opea}/chatqna:${TAG:-latest}
    container_name: chatqna-xeon-backend-server
    depends_on:
      - redis-vector-db
      - tei-embedding-service
      - dataprep-redis-service
      - retriever
      - tei-reranking-service
      - tgi_service
      - embedding
      - reranking
      - llm
    ports:
      - "8888:8888"
    environment:
      no_proxy: ${no_proxy}
      https_proxy: ${https_proxy}
      http_proxy: ${http_proxy}
      MEGA_SERVICE_HOST_IP: ${MEGA_SERVICE_HOST_IP}
      EMBEDDING_SERVER_HOST_IP: ${EMBEDDING_SERVICE_HOST_IP}
      EMBEDDING_SERVER_PORT: ${EMBEDDING_SERVER_PORT:-80}
      RETRIEVER_SERVICE_HOST_IP: ${RETRIEVER_SERVICE_HOST_IP}
      RERANK_SERVER_HOST_IP: ${RERANK_SERVICE_HOST_IP}
      RERANK_SERVER_PORT: ${RERANK_SERVER_PORT:-80}
      LLM_SERVER_HOST_IP: ${LLM_SERVICE_HOST_IP_CHATQNA}
      LLM_SERVER_PORT: ${LLM_SERVER_PORT:-80}
      LLM_MODEL: ${LLM_MODEL_ID}
      LOGFLAG: ${LOGFLAG}
    ipc: host
    restart: always
  tgi_service_codegen:
    image: ghcr.io/huggingface/text-generation-inference:2.4.0-intel-cpu
    container_name: tgi_service_codegen
    ports:
      - "8028:80"
    volumes:
      - "./data_codegen:/data"
    shm_size: 1g
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      HF_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      host_ip: ${host_ip}
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://$host_ip:8028/health || exit 1"]
      interval: 10s
      timeout: 10s
      retries: 30
    command: --model-id ${LLM_MODEL_ID_CODEGEN}
  llm_codegen:
    image: ${REGISTRY:-opea}/llm-textgen:${TAG:-latest}
    container_name: llm-textgen-server-codegen
    depends_on:
      tgi_service_codegen:
        condition: service_healthy
    ports:
      - "9001:9000"
    ipc: host
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      LLM_ENDPOINT: ${TGI_LLM_ENDPOINT_CODEGEN}
      LLM_MODEL_ID: ${LLM_MODEL_ID}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped
  codegen-xeon-backend-server:
    image: ${REGISTRY:-opea}/codegen:${TAG:-latest}
    container_name: codegen-xeon-backend-server
    depends_on:
      - llm
    ports:
      - "7778:7778"
    environment:
      no_proxy: ${no_proxy}
      https_proxy: ${https_proxy}
      http_proxy: ${http_proxy}
      MEGA_SERVICE_HOST_IP: ${MEGA_SERVICE_HOST_IP}
      LLM_SERVICE_HOST_IP: ${LLM_SERVICE_HOST_IP_CODEGEN}
      LLM_SERVICE_PORT: ${LLM_SERVICE_HOST_PORT_CODEGEN}
      LOGFLAG: ${LOGFLAG}
    ipc: host
    restart: always
  llm_faqgen:
    image: ${REGISTRY:-opea}/llm-faqgen-tgi:${TAG:-latest}
    container_name: llm-faqgen-server
    depends_on:
      - tgi_service
    ports:
      - "9002:9000"
    ipc: host
    environment:
      no_proxy: ${no_proxy}
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      TGI_LLM_ENDPOINT: ${TGI_LLM_ENDPOINT_FAQGEN}
      HUGGINGFACEHUB_API_TOKEN: ${HUGGINGFACEHUB_API_TOKEN}
    restart: unless-stopped
  faqgen-xeon-backend-server:
    image: ${REGISTRY:-opea}/faqgen:${TAG:-latest}
    container_name: faqgen-xeon-backend-server
    depends_on:
      - tgi_service
      - llm_faqgen
    ports:
      - "8889:8888"
    environment:
      no_proxy: ${no_proxy}
      https_proxy: ${https_proxy}
      http_proxy: ${http_proxy}
      MEGA_SERVICE_HOST_IP: ${MEGA_SERVICE_HOST_IP}
      LLM_SERVICE_PORT: ${LLM_SERVICE_HOST_PORT_FAQGEN}
      LLM_SERVICE_HOST_IP: ${LLM_SERVICE_HOST_IP_FAQGEN}
      LOGFLAG: ${LOGFLAG}
    ipc: host
    restart: always
  mongo:
    image: mongo:7.0.11
    container_name: mongodb
    ports:
      - 27017:27017
    environment:
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      no_proxy: ${no_proxy}
    command: mongod --quiet --logpath /dev/null

  chathistory-mongo:
    image: ${REGISTRY:-opea}/chathistory-mongo-server:${TAG:-latest}
    container_name: chathistory-mongo-server
    ports:
      - "6012:6012"
    ipc: host
    environment:
      http_proxy: ${http_proxy}
      no_proxy: ${no_proxy}
      https_proxy: ${https_proxy}
      MONGO_HOST: ${MONGO_HOST}
      MONGO_PORT: ${MONGO_PORT}
      COLLECTION_NAME: ${COLLECTION_NAME}
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped

  promptregistry-mongo:
    image: ${REGISTRY:-opea}/promptregistry-mongo-server:${TAG:-latest}
    container_name: promptregistry-mongo-server
    ports:
      - "6018:6018"
    ipc: host
    environment:
      http_proxy: ${http_proxy}
      https_proxy: ${https_proxy}
      no_proxy: ${no_proxy}
      MONGO_HOST: ${MONGO_HOST}
      MONGO_PORT: ${MONGO_PORT}
      COLLECTION_NAME: ${PROMPT_COLLECTION_NAME}
      LOGFLAG: ${LOGFLAG}
    restart: unless-stopped
  keycloak:
    image: quay.io/keycloak/keycloak:25.0.2
    container_name: keycloak-server
    ports:
      - 8080:8080
    environment:
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
      - KC_PROXY=edge
    ipc: host
    command: start-dev
    restart: always

  productivity-suite-xeon-react-ui-server:
    image: ${REGISTRY:-opea}/productivity-suite-react-ui-server:${TAG:-latest}
    container_name: productivity-suite-xeon-react-ui-server
    ports:
      - "5174:80"
    environment:
      - APP_BACKEND_SERVICE_ENDPOINT_CHATQNA=${BACKEND_SERVICE_ENDPOINT_CHATQNA}
      - APP_BACKEND_SERVICE_ENDPOINT_CODEGEN=${BACKEND_SERVICE_ENDPOINT_CODEGEN}
      - APP_BACKEND_SERVICE_ENDPOINT_DOCSUM=${BACKEND_SERVICE_ENDPOINT_DOCSUM}
      - APP_BACKEND_SERVICE_ENDPOINT_FAQGEN=${BACKEND_SERVICE_ENDPOINT_FAQGEN}
      - APP_DATAPREP_SERVICE_ENDPOINT=${DATAPREP_SERVICE_ENDPOINT}
      - APP_DATAPREP_GET_FILE_ENDPOINT=${DATAPREP_GET_FILE_ENDPOINT}
      - APP_DATAPREP_DELETE_FILE_ENDPOINT=${DATAPREP_DELETE_FILE_ENDPOINT}
      - APP_CHAT_HISTORY_CREATE_ENDPOINT=${CHAT_HISTORY_CREATE_ENDPOINT}
      - APP_CHAT_HISTORY_DELETE_ENDPOINT=${CHAT_HISTORY_DELETE_ENDPOINT}
      - APP_CHAT_HISTORY_GET_ENDPOINT=${CHAT_HISTORY_GET_ENDPOINT}
      - APP_PROMPT_SERVICE_GET_ENDPOINT=${PROMPT_SERVICE_GET_ENDPOINT}
      - APP_PROMPT_SERVICE_CREATE_ENDPOINT=${PROMPT_SERVICE_CREATE_ENDPOINT}
      - APP_KEYCLOAK_SERVICE_ENDPOINT=${KEYCLOAK_SERVICE_ENDPOINT}
      - LOGFLAG=${LOGFLAG}
    ipc: host
    restart: always
networks:
  default:
    driver: bridge
