version: '3.8'

services:
  # MySQL 数据库
  mysql:
    image: mysql:8.0
    container_name: jeecgboot-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root@JeecgBoot123
      MYSQL_DATABASE: jeecg-boot
      MYSQL_USER: jeecg
      MYSQL_PASSWORD: jeecg@123
      TZ: Asia/Shanghai
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
      - ./db/jeecgboot-mysql-5.7.sql:/docker-entrypoint-initdb.d/init.sql
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --default-time-zone='+08:00'
    networks:
      - jeecg-network
    restart: always

  # Redis
  redis:
    image: redis:7.0
    container_name: jeecgboot-redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    command: redis-server --appendonly yes
    networks:
      - jeecg-network
    restart: always

  # 后端服务
  backend:
    image: jeecgboot-backend:3.9.2
    container_name: jeecgboot-backend
    ports:
      - "8080:8080"
    environment:
      - SPRING_PROFILES_ACTIVE=prod
      - TZ=Asia/Shanghai
      - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/jeecg-boot?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
      - SPRING_DATASOURCE_USERNAME=jeecg
      - SPRING_DATASOURCE_PASSWORD=jeecg@123
      - SPRING_REDIS_HOST=redis
      - SPRING_REDIS_PORT=6379
    depends_on:
      - mysql
      - redis
    volumes:
      - ./logs:/app/logs
    networks:
      - jeecg-network
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  mysql-data:
  redis-data:

networks:
  jeecg-network:
    driver: bridge
