services:
  db:
    image: pgvector/pgvector:pg16
    restart: unless-stopped
    environment:
      POSTGRES_DB: amcs
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./docker/postgres/init:/docker-entrypoint-initdb.d:ro
      - ./migrations:/migrations:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d amcs"]
      interval: 5s
      timeout: 5s
      retries: 20

  app:
    build:
      context: .
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped
    volumes:
      - ./configs:/app/configs:ro
    environment:
      AMCS_CONFIG: /app/configs/docker.yaml
      AMCS_DATABASE_URL: postgres://postgres:postgres@db:5432/amcs?sslmode=disable
      AMCS_LITELLM_BASE_URL: ${AMCS_LITELLM_BASE_URL:-http://host.containers.internal:4000/v1}
      AMCS_LITELLM_API_KEY: ${AMCS_LITELLM_API_KEY:-replace-me}
      AMCS_SERVER_PORT: 8080
    ports:
      - "8080:8080"

  migrate-config:
    build:
      context: .
    profiles: ["tools"]
    restart: "no"
    volumes:
      - ./configs:/app/configs
    environment:
      AMCS_CONFIG: /app/configs/docker.yaml
    entrypoint: ["/app/amcs-migrate-config"]
    command: ["--config", "/app/configs/docker.yaml", "--dry-run"]

volumes:
  postgres_data:

networks:
  default:
    name: amcs
