name: ${APP_NAME:-ai-agent-admin}

services:
  postgres:
    image: postgres:16-alpine
    container_name: ${APP_NAME:-ai-agent-admin}-postgres
    restart: unless-stopped
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${DB_NAME:-ai_agent_admin}
      POSTGRES_USER: ${DB_USER:-postgres}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-postgres}
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres} -d ${DB_NAME:-ai_agent_admin}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    ports:
      - "${DB_PORT_MAPPING:-5432}"
    networks:
      - zq-network

  redis:
    image: redis:7-alpine
    container_name: ${APP_NAME:-ai-agent-admin}-redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD:-redis123}
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:-redis123}", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    ports:
      - "${REDIS_PORT_MAPPING:-6379}"
    networks:
      - zq-network

  backend:
    build:
      context: .
      dockerfile: docker/backend/Dockerfile
    image: ai-agent-admin-backend:latest
    container_name: ${APP_NAME:-ai-agent-admin}-backend
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      ENV: prod
      APP_NAME: ${APP_NAME:-ai-agent-admin}
      DB_TYPE: postgresql
      DB_HOST: postgres
      DB_PORT: 5432
      DB_USER: ${DB_USER:-postgres}
      DB_PASSWORD: ${DB_PASSWORD:-postgres}
      DB_NAME: ${DB_NAME:-ai_agent_admin}
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PASSWORD: ${REDIS_PASSWORD:-redis123}
      REDIS_DB: 0
      JWT_SECRET_KEY: ${JWT_SECRET_KEY:-your-secret-key-change-in-production}
      ACCESS_TOKEN_EXPIRE_MINUTES: ${ACCESS_TOKEN_EXPIRE_MINUTES:-1440}
      REFRESH_TOKEN_EXPIRE_DAYS: ${REFRESH_TOKEN_EXPIRE_DAYS:-30}
      FILE_STORAGE_TYPE: ${FILE_STORAGE_TYPE:-local}
      FILE_STORAGE_LOCAL_PATH: ${FILE_STORAGE_LOCAL_PATH:-/app/storage}
      MINIO_ENDPOINT: ${MINIO_ENDPOINT:-}
      MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY:-}
      MINIO_SECRET_KEY: ${MINIO_SECRET_KEY:-}
      MINIO_BUCKET_NAME: ${MINIO_BUCKET_NAME:-}
      MINIO_SECURE: ${MINIO_SECURE:-false}
      TIMEZONE: ${TIMEZONE:-Asia/Shanghai}
      CACHE_PREFIX: ${CACHE_PREFIX:-ai-agent-admin:prod:}
      DINGTALK_REDIRECT_URI: ${DINGTALK_REDIRECT_URI:-}
      DINGTALK_H5_REDIRECT_URI: ${DINGTALK_H5_REDIRECT_URI:-}
    volumes:
      - backend_storage:/app/storage
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    ports:
      - "${BACKEND_PORT_MAPPING:-8000}"
    networks:
      - zq-network

  web:
    build:
      context: .
      dockerfile: docker/web/Dockerfile
      args:
        VITE_BASE: /ai-agent-admin/
        VITE_GLOB_API_URL: /ai-agent-admin/basic-api
        VITE_APP_TITLE: ${APP_NAME:-AI Agent Admin}
    image: ai-agent-admin-web:latest
    container_name: ${APP_NAME:-ai-agent-admin}-web
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - "${WEB_PORT:-80}:80"
    networks:
      - zq-network

volumes:
  postgres_data:
    name: ${APP_NAME:-ai-agent-admin}-postgres-data
  redis_data:
    name: ${APP_NAME:-ai-agent-admin}-redis-data
  backend_storage:
    name: ${APP_NAME:-ai-agent-admin}-backend-storage

networks:
  zq-network:
    name: ${APP_NAME:-ai-agent-admin}-network
    driver: bridge
