services:
  db:
    image: pgvector/pgvector:pg16
    container_name: agent-db
    env_file:
      - .env
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./docker/postgres-init:/docker-entrypoint-initdb.d
    ports:
      - "${POSTGRES_PORT:-5432}:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U agent -d agent"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: agent-backend
    env_file:
      - .env
    environment:
      DATABASE_URL: postgresql+psycopg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}
      GIGACHAT_AUTH_URL: ${GIGACHAT_AUTH_URL}
      GIGACHAT_API_URL: ${GIGACHAT_API_URL}
      GIGACHAT_SCOPE: ${GIGACHAT_SCOPE}
      GIGACHAT_TOKEN: ${GIGACHAT_TOKEN}
      GIGACHAT_SSL_VERIFY: ${GIGACHAT_SSL_VERIFY}
      GIGACHAT_MODEL: ${GIGACHAT_MODEL}
      GIGACHAT_EMBEDDING_MODEL: ${GIGACHAT_EMBEDDING_MODEL}
      AGENT_PROMPTS_DIR: ${AGENT_PROMPTS_DIR}
    ports:
      - "${BACKEND_PORT:-15000}:15000"
    depends_on:
      db:
        condition: service_healthy

volumes:
  postgres_data:
