services:
  # MySQL 数据库
  mysql:
    image: mysql:8.0
    container_name: martial-mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: martial_db
      TZ: Asia/Shanghai
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./database:/docker-entrypoint-initdb.d
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p123456"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - martial-network

  # Redis 缓存
  redis:
    image: redis:7-alpine
    container_name: martial-redis
    restart: always
    command: redis-server --requirepass 123456
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "123456", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - martial-network

  # MinIO 对象存储
  minio:
    image: minio/minio:RELEASE.2024-12-18T13-15-44Z
    container_name: minio
    environment:
      MINIO_ROOT_USER: "JohnSion"
      MINIO_ROOT_PASSWORD: "v!*BTket4oagDdw"
      TZ: "Asia/Shanghai"
    command: server /data --console-address ":9001"
    volumes:
      - ./minio_data:/data
    ports:
      - "9000:9000"
      - "9001:9001"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:9000/minio/health/live"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
    networks:
      - martial-network

  # MinIO 初始化 - 创建桶和设置策略
  minio-init:
    image: minio/mc:latest
    depends_on:
      minio:
        condition: service_healthy
    entrypoint: >
      sh -c "
      mc alias set local http://minio:9000 $${MINIO_ROOT_USER} $${MINIO_ROOT_PASSWORD} &&
      mc mb -p local/assets || true &&
      mc anonymous set download local/assets || true
      "
    environment:
      MINIO_ROOT_USER: "JohnSion"
      MINIO_ROOT_PASSWORD: "v!*BTket4oagDdw"
    restart: "no"
    networks:
      - martial-network

  # 后端应用（完整构建模式）
  martial-api:
    build:
      context: .
      dockerfile: Dockerfile.quick
    container_name: martial-api
    restart: always
    environment:
      SPRING_PROFILE: dev
      JAVA_OPTS: "-Xms512m -Xmx1024m -XX:+UseG1GC"
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/martial_db?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
      SPRING_DATASOURCE_USERNAME: root
      SPRING_DATASOURCE_PASSWORD: 123456
      SPRING_DATA_REDIS_HOST: redis
      SPRING_DATA_REDIS_PORT: 6379
      SPRING_DATA_REDIS_PASSWORD: 123456
    ports:
      - "8123:8123"
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - martial-network

networks:
  martial-network:
    driver: bridge

volumes:
  mysql_data:
  redis_data:
