version: '3.8'

services:
    # PostgreSQL Database
    postgres:
        image: postgres:16-alpine
        container_name: qa_pipeline_db
        environment:
            POSTGRES_DB: ragPipeline
            POSTGRES_USER: postgres
            POSTGRES_PASSWORD: root
        ports:
            - '5432:5432'
        volumes:
            - postgres_data:/var/lib/postgresql/data
            - ./scripts/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
        networks:
            - qa_pipeline_network
        healthcheck:
            test: ['CMD-SHELL', 'pg_isready -U postgres']
            interval: 10s
            timeout: 5s
            retries: 5

    # Redis (optional - for caching and session management)
    redis:
        image: redis:7-alpine
        container_name: qa_pipeline_redis
        ports:
            - '6379:6379'
        volumes:
            - redis_data:/data
        networks:
            - qa_pipeline_network
        healthcheck:
            test: ['CMD', 'redis-cli', 'ping']
            interval: 10s
            timeout: 5s
            retries: 5

    # Node.js Application
    app:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: qa_pipeline_app
        environment:
            - NODE_ENV=production
            - PORT=3001
            - DB_HOST=postgres
            - DB_PORT=5432
            - DB_NAME=ragPipeline
            - DB_USER=postgres
            - DB_PASSWORD=root
            - JWT_SECRET=${JWT_SECRET:-your-super-secret-jwt-key-change-this-in-production}
            - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
            - PINECONE_API_KEY=${PINECONE_API_KEY}
            - PINECONE_ENVIRONMENT=${PINECONE_ENVIRONMENT}
            - PINECONE_INDEX_NAME=${PINECONE_INDEX_NAME:-qa-pipeline-index}
            - LOG_LEVEL=info
        ports:
            - '3001:3001'
        depends_on:
            postgres:
                condition: service_healthy
            redis:
                condition: service_healthy
        volumes:
            - ./logs:/app/logs
            - ./uploads:/app/uploads
        networks:
            - qa_pipeline_network
        restart: unless-stopped

volumes:
    postgres_data:
    redis_data:

networks:
    qa_pipeline_network:
        driver: bridge
