version: '3'

services:
  raggraph_app:
    build: .
    container_name: raggraph_app
    ports:
      - "8000:8000"
    environment:
      - NEO4J_URI=bolt://raggraph_neo4j:7687
      - NEO4J_USER=neo4j
      - NEO4J_PASSWORD=password
      - GOOGLE_APPLICATION_CREDENTIALS=/app/credentials.json
    volumes:
      - .:/app:z
      - ./credentials.json:/app/credentials.json:ro
    depends_on:
      raggraph_neo4j:
        condition: service_healthy

  raggraph_neo4j:
    container_name: raggraph_neo4j
    image: neo4j:5
    ports:
      - "7474:7474"  # HTTP
      - "7687:7687"  # Bolt
    environment:
      - NEO4J_AUTH=neo4j/password
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
      - NEO4J_dbms_memory_pagecache_size=1G
      - NEO4J_dbms_memory_heap_initial__size=1G
      - NEO4J_dbms_memory_heap_max__size=1G
      - NEO4J_dbms_security_procedures_unrestricted=apoc.*,gds.*
      - NEO4J_dbms_security_procedures_allowlist=apoc.*,gds.*
    volumes:
      - neo4j_data:/data
      - neo4j_logs:/logs
      - ./plugins:/plugins:ro
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:7474"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Add Redis for Celery message broker
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    restart: unless-stopped
  # Celery worker for background tasks
  celery_worker:
    build: .
    command: celery -A app.core.etl_pipeline.celery_app worker --loglevel=info
    depends_on:
      - redis
      - raggraph_neo4j
    environment:
      - NEO4J_URI=bolt://raggraph_neo4j:7687
      - NEO4J_USER=neo4j
      - NEO4J_PASSWORD=password
      - VERTEX_AI_PROJECT_ID=${VERTEX_AI_PROJECT_ID}
      - VERTEX_AI_LOCATION=${VERTEX_AI_LOCATION}
      - GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}
      - GOOGLE_APPLICATION_CREDENTIALS=/app/service-account-key.json
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    volumes:
      - ./service-account-key.json:/app/service-account-key.json:ro
    restart: unless-stopped

  # Celery beat for scheduled tasks
  celery_beat:
    build: .
    command: celery -A app.core.etl_pipeline.celery_app beat --loglevel=info
    depends_on:
      - redis
      - raggraph_neo4j
    environment:
      - NEO4J_URI=bolt://raggraph_neo4j:7687
      - NEO4J_USER=neo4j
      - NEO4J_PASSWORD=password
      - VERTEX_AI_PROJECT_ID=${VERTEX_AI_PROJECT_ID}
      - VERTEX_AI_LOCATION=${VERTEX_AI_LOCATION}
      - GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}
      - GOOGLE_APPLICATION_CREDENTIALS=/app/service-account-key.json
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
    volumes:
      - ./service-account-key.json:/app/service-account-key.json:ro
    restart: unless-stopped

volumes:
  neo4j_data:
  neo4j_logs:
  redis_data: 