version: '3.8'

services:
  edu-search-service:
    build: .
    container_name: breakpilot-edu-search
    ports:
      - "8086:8086"
    environment:
      - PORT=8086
      - OPENSEARCH_URL=http://opensearch:9200
      - OPENSEARCH_USERNAME=admin
      - OPENSEARCH_PASSWORD=${OPENSEARCH_PASSWORD:-admin}
      - INDEX_NAME=bp_documents_v1
      - EDU_SEARCH_API_KEY=${EDU_SEARCH_API_KEY:-}
      - "USER_AGENT=BreakpilotEduCrawler/1.0 (+contact: security@breakpilot.com)"
      - RATE_LIMIT_PER_SEC=0.2
      - MAX_DEPTH=4
      - MAX_PAGES_PER_RUN=500
      - DB_HOST=breakpilot-pwa-postgres
      - DB_PORT=5432
      - DB_USER=breakpilot
      - DB_PASSWORD=${DB_PASSWORD:-breakpilot123}
      - DB_NAME=breakpilot_db
      - DB_SSLMODE=disable
      - STAFF_CRAWLER_EMAIL=crawler@breakpilot.de
    depends_on:
      opensearch:
        condition: service_healthy
    networks:
      - edu-search-network
      - breakpilot-pwa-network
    restart: unless-stopped

  opensearch:
    image: opensearchproject/opensearch:2.11.1
    container_name: breakpilot-opensearch
    environment:
      - cluster.name=edu-search-cluster
      - node.name=opensearch-node1
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD:-Admin123!}
      - plugins.security.disabled=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch-data:/usr/share/opensearch/data
    ports:
      - "9200:9200"
      - "9600:9600"
    networks:
      - edu-search-network
    healthcheck:
      test: ["CMD-SHELL", "curl -s http://localhost:9200 >/dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s

  opensearch-dashboards:
    image: opensearchproject/opensearch-dashboards:2.11.1
    container_name: breakpilot-opensearch-dashboards
    ports:
      - "5601:5601"
    environment:
      - OPENSEARCH_HOSTS=["http://opensearch:9200"]
      - DISABLE_SECURITY_DASHBOARDS_PLUGIN=true
    depends_on:
      opensearch:
        condition: service_healthy
    networks:
      - edu-search-network

networks:
  edu-search-network:
    driver: bridge
  breakpilot-pwa-network:
    external: true
    name: breakpilot-pwa_breakpilot-pwa-network

volumes:
  opensearch-data:
