# Product Service 独立部署配置
version: '3.8'

services:
  product-service:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: erp-product-service
    ports:
      - "8083:8083"
    environment:
      - SPRING_PROFILES_ACTIVE=prod
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/erp_java?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
      - SPRING_DATASOURCE_USERNAME=erp_user
      - SPRING_DATASOURCE_PASSWORD=erp123456
      - SPRING_REDIS_HOST=redis
      - SPRING_REDIS_PORT=6379
      - SPRING_REDIS_PASSWORD=redis123456
      - SPRING_CLOUD_NACOS_DISCOVERY_SERVER-ADDR=nacos:8848
      - SPRING_CLOUD_NACOS_CONFIG_SERVER-ADDR=nacos:8848
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
      nacos:
        condition: service_started
    networks:
      - erp-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8083/product/actuator/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  # MySQL (仅用于独立部署演示，生产环境应使用外部数据库)
  mysql:
    image: mysql:8.0
    container_name: erp-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root123456
      - MYSQL_DATABASE=erp_java
      - MYSQL_USER=erp_user
      - MYSQL_PASSWORD=erp123456
    ports:
      - "3307:3306"
    volumes:
      - mysql-data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    networks:
      - erp-network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot123456"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  # Redis
  redis:
    image: redis:7-alpine
    container_name: erp-redis
    command: redis-server --requirepass redis123456
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - erp-network
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "redis123456", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  # Nacos
  nacos:
    image: nacos/nacos-server:v2.2.3
    container_name: erp-nacos
    environment:
      - MODE=standalone
      - SPRING_DATASOURCE_PLATFORM=embedded
    ports:
      - "8848:8848"
      - "9848:9848"
    networks:
      - erp-network
    restart: unless-stopped

networks:
  erp-network:
    driver: bridge

volumes:
  mysql-data:
  redis-data:
