services:
  opensearch:
    image: phact/openrag-opensearch:${OPENRAG_VERSION:-latest}
    #build:
    #context: .
    #dockerfile: Dockerfile
    container_name: os
    depends_on:
      - openrag-backend
    environment:
      - discovery.type=single-node
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD}
    # Run security setup in background after OpenSearch starts
    command: >
      bash -c "
        # Start OpenSearch in background
        /usr/share/opensearch/opensearch-docker-entrypoint.sh opensearch &

        # Wait a bit for OpenSearch to start, then apply security config
        sleep 10 && /usr/share/opensearch/setup-security.sh &

        # Wait for background processes
        wait
      "
    ports:
      - "9200:9200"
      - "9600:9600"

  dashboards:
    image: opensearchproject/opensearch-dashboards:3.0.0
    container_name: osdash
    depends_on:
      - opensearch
    environment:
      OPENSEARCH_HOSTS: '["https://opensearch:9200"]'
      OPENSEARCH_USERNAME: "admin"
      OPENSEARCH_PASSWORD: ${OPENSEARCH_PASSWORD}
    ports:
      - "5601:5601"

  openrag-backend:
    image: phact/openrag-backend:${OPENRAG_VERSION:-latest}
    # build:
    #   context: .
    #   dockerfile: Dockerfile.backend
    container_name: openrag-backend
    depends_on:
      - langflow
    environment:
      - OPENSEARCH_HOST=opensearch
      - LANGFLOW_URL=http://langflow:7860
      - LANGFLOW_PUBLIC_URL=${LANGFLOW_PUBLIC_URL}
      - LANGFLOW_AUTO_LOGIN=${LANGFLOW_AUTO_LOGIN}
      - LANGFLOW_SUPERUSER=${LANGFLOW_SUPERUSER}
      - LANGFLOW_SUPERUSER_PASSWORD=${LANGFLOW_SUPERUSER_PASSWORD}
      - LANGFLOW_CHAT_FLOW_ID=${LANGFLOW_CHAT_FLOW_ID}
      - LANGFLOW_INGEST_FLOW_ID=${LANGFLOW_INGEST_FLOW_ID}
      - LANGFLOW_URL_INGEST_FLOW_ID=${LANGFLOW_URL_INGEST_FLOW_ID}
      - DISABLE_INGEST_WITH_LANGFLOW=${DISABLE_INGEST_WITH_LANGFLOW:-false}
      - NUDGES_FLOW_ID=${NUDGES_FLOW_ID}
      - OPENSEARCH_PORT=9200
      - OPENSEARCH_USERNAME=admin
      - OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - WATSONX_API_KEY=${WATSONX_API_KEY}
      - WATSONX_ENDPOINT=${WATSONX_ENDPOINT}
      - WATSONX_PROJECT_ID=${WATSONX_PROJECT_ID}
      - OLLAMA_ENDPOINT=${OLLAMA_ENDPOINT}
      - NVIDIA_DRIVER_CAPABILITIES=compute,utility
      - NVIDIA_VISIBLE_DEVICES=all
      - GOOGLE_OAUTH_CLIENT_ID=${GOOGLE_OAUTH_CLIENT_ID}
      - GOOGLE_OAUTH_CLIENT_SECRET=${GOOGLE_OAUTH_CLIENT_SECRET}
      - MICROSOFT_GRAPH_OAUTH_CLIENT_ID=${MICROSOFT_GRAPH_OAUTH_CLIENT_ID}
      - MICROSOFT_GRAPH_OAUTH_CLIENT_SECRET=${MICROSOFT_GRAPH_OAUTH_CLIENT_SECRET}
      - WEBHOOK_BASE_URL=${WEBHOOK_BASE_URL}
      - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
      - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
    volumes:
      - ./documents:/app/documents:Z
      - ./keys:/app/keys:Z
      - ./flows:/app/flows:U,z
    gpus: all

  openrag-frontend:
    image: phact/openrag-frontend:${OPENRAG_VERSION:-latest}
    # build:
    #   context: .
    #   dockerfile: Dockerfile.frontend
    container_name: openrag-frontend
    depends_on:
      - openrag-backend
    environment:
      - OPENRAG_BACKEND_HOST=openrag-backend
    ports:
      - "3000:3000"

  langflow:
    volumes:
      - ./flows:/app/flows:U,z
    image: langflowai/langflow-nightly:${LANGFLOW_VERSION:-1.7.0.dev5}
    # build:
    #   context: .
    #   dockerfile: Dockerfile.langflow
    container_name: langflow
    ports:
      - "7860:7860"
    environment:
      - LANGFLOW_DEACTIVATE_TRACING=true
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - WATSONX_API_KEY=${WATSONX_API_KEY}
      - WATSONX_ENDPOINT=${WATSONX_ENDPOINT}
      - WATSONX_PROJECT_ID=${WATSONX_PROJECT_ID}
      - OLLAMA_BASE_URL=${OLLAMA_ENDPOINT}
      - LANGFLOW_LOAD_FLOWS_PATH=/app/flows
      - LANGFLOW_SECRET_KEY=${LANGFLOW_SECRET_KEY}
      - JWT=None  
      - OWNER=None
      - OWNER_NAME=None
      - OWNER_EMAIL=None
      - CONNECTOR_TYPE=system
      - CONNECTOR_TYPE_URL=url
      - OPENRAG-QUERY-FILTER="{}"
      - FILENAME=None
      - MIMETYPE=None
      - FILESIZE=0
      - OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD}
      - LANGFLOW_VARIABLES_TO_GET_FROM_ENVIRONMENT=JWT,OPENRAG-QUERY-FILTER,OPENSEARCH_PASSWORD,OWNER,OWNER_NAME,OWNER_EMAIL,CONNECTOR_TYPE,FILENAME,MIMETYPE,FILESIZE
      - LANGFLOW_LOG_LEVEL=DEBUG
      - LANGFLOW_AUTO_LOGIN=${LANGFLOW_AUTO_LOGIN}
      - LANGFLOW_SUPERUSER=${LANGFLOW_SUPERUSER}
      - LANGFLOW_SUPERUSER_PASSWORD=${LANGFLOW_SUPERUSER_PASSWORD}
      - LANGFLOW_NEW_USER_IS_ACTIVE=${LANGFLOW_NEW_USER_IS_ACTIVE}
      - LANGFLOW_ENABLE_SUPERUSER_CLI=${LANGFLOW_ENABLE_SUPERUSER_CLI}
      # - DEFAULT_FOLDER_NAME=OpenRAG
      - HIDE_GETTING_STARTED_PROGRESS=true
