version: '3.8'

services:
  # MySQL
  mysql:
    image: mysql:8.0
    container_name: hzhub-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-hzhub123}
      MYSQL_DATABASE: hzhub
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - hzhub-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-hzhub123}"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Redis
  redis:
    image: redis:7-alpine
    container_name: hzhub-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - hzhub-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Weaviate (向量数据库)
  weaviate:
    image: semitechnologies/weaviate:1.25.0
    container_name: hzhub-weaviate
    ports:
      - "28080:8080"
    environment:
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'none'
      ENABLE_MODULES: ''
      CLUSTER_HOSTNAME: 'node1'
    volumes:
      - weaviate_data:/var/lib/weaviate
    networks:
      - hzhub-network

  # hzhub-ai (AI服务)
  hzhub-ai:
    build:
      context: ../hzhub-ai
      dockerfile: Dockerfile
    container_name: hzhub-ai
    ports:
      - "6039:6039"
    environment:
      SPRING_PROFILES_ACTIVE: dev
      SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_URL: jdbc:mysql://hzhub-mysql:3306/ruoyi_ai?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
      SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_USERNAME: root
      SPRING_DATASOURCE_DYNAMIC_DATASOURCE_MASTER_PASSWORD: hzhub123
      SPRING_DATA_REDIS_HOST: hzhub-redis
      SPRING_DATA_REDIS_PORT: 6379
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - hzhub-network

  # n8n (工作流)
  n8n:
    image: n8nio/n8n:latest
    container_name: hzhub-n8n
    environment:
      N8N_BASIC_AUTH_ACTIVE: "true"
      N8N_BASIC_AUTH_USER: ${N8N_USER:-admin}
      N8N_BASIC_AUTH_PASSWORD: ${N8N_PASSWORD:-hzhub123}
    ports:
      - "5678:5678"
    volumes:
      - n8n_data:/home/node/.n8n
    networks:
      - hzhub-network

  # hzhub-admin (前端管理后台)
  hzhub-admin:
    build:
      context: ../hzhub-admin
      dockerfile: Dockerfile
    container_name: hzhub-admin
    ports:
      - "5666:5666"
    environment:
      - NGINX_PORT=5666
    depends_on:
      - hzhub-ai
    networks:
      - hzhub-network

volumes:
  mysql_data:
  redis_data:
  weaviate_data:
  n8n_data:

networks:
  hzhub-network:
    driver: bridge
