version: '3.8'

services:
  # MySQL 数据库
  mysql:
    image: mysql:5.7
    container_name: ruoyi-mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: ruoyi
      TZ: Asia/Shanghai
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
      - ./sql:/docker-entrypoint-initdb.d
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      - ruoyi-network
    restart: unless-stopped

  # Redis 缓存
  redis:
    image: redis:6-alpine
    container_name: ruoyi-redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - ruoyi-network
    restart: unless-stopped

  # 后端服务
  backend:
    build:
      context: .
      dockerfile: Dockerfile.backend
    container_name: ruoyi-backend
    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
      SPRING_DATASOURCE_USERNAME: root
      SPRING_DATASOURCE_PASSWORD: password
      SPRING_REDIS_HOST: redis
      SPRING_REDIS_PORT: 6379
      SERVER_SERVLET_CONTEXT_PATH: /
    ports:
      - "8080:8080"
    volumes:
      - upload-data:/home/ruoyi/uploadPath
    depends_on:
      - mysql
      - redis
    networks:
      - ruoyi-network
    restart: unless-stopped

  # 前端 Nginx
  frontend:
    build:
      context: ./ruoyi-ui
      dockerfile: Dockerfile
    container_name: ruoyi-frontend
    ports:
      - "8081:80"
    depends_on:
      - backend
    networks:
      - ruoyi-network
    restart: unless-stopped

networks:
  ruoyi-network:
    driver: bridge

volumes:
  mysql-data:
  redis-data:
  upload-data:
