version: '3.8'

services:
  # MySQL 服务(可选，如果需要可以取消注释）
  # mysql:
  #   image: mysql:8.0
  #   container_name: mysql-container
  #   restart: on-failure
  #   environment:
  #     MYSQL_ROOT_PASSWORD: 12345678
  #     MYSQL_DATABASE: inventory_v2
  #   ports:
  #     - "23306:3306"
  #   volumes:
  #     - ./mysql/data:/var/lib/mysql
  #   networks:
  #     - app-network

  # API 服务
  api:
    image: node:22-alpine
    container_name: api-container
    restart: on-failure
    environment:
      - NODE_ENV=prod
      # 数据库连接信息(连接到外部 MySQL 容器）
      - MYSQL_HOST=host.docker.internal
      - MYSQL_PORT=23306
      - MYSQL_USERNAME=root
      - MYSQL_PASSWORD=root
      - MYSQL_DATABASE=inventory
    volumes:
      - ../../API:/app
    working_dir: /app
    command: sh -c "npm run dev"
    ports:
      - "7001:7001"
    networks:
      - app-network

  # Cube 服务
  cube:
    image: cubejs/cube:latest
    ports:
      - 4000:4000
    environment:
      - CUBEJS_DEV_MODE=true
      - CUBEJS_DB_TYPE=mysql
      - CUBEJS_DB_HOST=host.docker.internal
      - CUBEJS_DB_PORT=23306
      - CUBEJS_DB_USER=cubejs
      - CUBEJS_DB_PASS=12345678
      - CUBEJS_DB_NAME=inventory_v2
      - CUBEJS_DB_SSL=false
      - CUBEJS_API_SECRET=your-secret-here
      - CUBEJS_WEB_SOCKETS=true
      # - CUBEJS_REFRESH_SCHEMA=true
    volumes:
      - ./cube/conf:/cube/conf
    
    # networks:
    #   - app-network
    # network_mode: host

  # WEB 服务
  web:
    image: nginx:alpine
    container_name: web-container
    restart: on-failure
    volumes:
      - ../../WEB/dist:/usr/share/nginx/html
      - ../../WEB/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "8080:80"
    depends_on:
      - api
    networks:
      - app-network

  # DataX 服务
  datax:
    image: beginor/datax
    container_name: datax-container
    restart: on-failure
    volumes:
      - ./datax/job:/datax/job
      - ./datax/log:/datax/log
    networks:
      - app-network

# volumes:
#   mysql-data:
#     driver: local

networks:
  app-network:
    driver: bridge
