version: '3.8'

services:
  # 应用服务
  cms-app:
    build: .
    container_name: cms-java-app
    ports:
      - "9200:9200"
    environment:
      - SPRING_PROFILES_ACTIVE=prod
      - JAVA_OPTS=-Xms512m -Xmx1024m
    volumes:
      # 证书挂载卷 - 将宿主机证书目录挂载到容器
      - ./certs:/app/certs:ro
      # 日志挂载卷
      - ./logs:/app/logs
      # 上传文件挂载卷
      - ./uploads:/app/uploads
    networks:
      - cms-network
    depends_on:
      - mysql
      - redis
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9200/actuator/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  # MySQL数据库
  mysql:
    image: mysql:8.0
    container_name: cms-mysql
    environment:
      MYSQL_ROOT_PASSWORD: root123456
      MYSQL_DATABASE: modules
      MYSQL_USER: modules
      MYSQL_PASSWORD: 8YdLnk7KsPAyDXGA
    ports:
      - "3308:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/init:/docker-entrypoint-initdb.d
    networks:
      - cms-network
    restart: unless-stopped
    command: --default-authentication-plugin=mysql_native_password

  # Redis缓存
  redis:
    image: redis:6.2-alpine
    container_name: cms-redis
    ports:
      - "16379:6379"
    volumes:
      - redis_data:/data
      - ./redis/redis.conf:/usr/local/etc/redis/redis.conf
    networks:
      - cms-network
    restart: unless-stopped
    command: redis-server /usr/local/etc/redis/redis.conf

  # Nginx反向代理（可选）
  nginx:
    image: nginx:alpine
    container_name: cms-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/ssl:/etc/nginx/ssl
      - ./uploads:/var/www/uploads
    networks:
      - cms-network
    depends_on:
      - cms-app
    restart: unless-stopped

networks:
  cms-network:
    driver: bridge

volumes:
  mysql_data:
    driver: local
  redis_data:
    driver: local
