services:
  caddy:
    build:
      context: ..
      dockerfile: deploy/caddy/Dockerfile
      args:
        VITE_ADMIN_BASE_PATH: ${VITE_ADMIN_BASE_PATH:-/manage-7x9k2p}
    restart: unless-stopped
    environment:
      TZ: Asia/Shanghai
      CADDY_DOMAIN: ${CADDY_DOMAIN:?请先导出 CADDY_DOMAIN，或使用 scripts/deploy-prod.sh 部署}
      CADDY_EMAIL: ${CADDY_EMAIL:?请先导出 CADDY_EMAIL，或使用 scripts/deploy-prod.sh 部署}
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    deploy:
      resources:
        limits:
          memory: 256M
          cpus: '0.5'
        reservations:
          memory: 128M
          cpus: '0.25'
    depends_on:
      - backend

  mysql:
    image: mysql:8.4
    restart: unless-stopped
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    env_file:
      - ../backend/.env
    environment:
      TZ: Asia/Shanghai
    volumes:
      - mysql_data:/var/lib/mysql
      - ./mysql/my.cnf:/etc/mysql/conf.d/my.cnf:ro
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '1.0'
        reservations:
          memory: 256M
          cpus: '0.5'
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p\"$${MYSQL_ROOT_PASSWORD}\""]
      interval: 10s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7.4-alpine
    restart: unless-stopped
    volumes:
      - redis_data:/data
    deploy:
      resources:
        limits:
          memory: 256M
          cpus: '0.5'
        reservations:
          memory: 128M
          cpus: '0.25'
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 10

  minio:
    image: minio/minio:RELEASE.2025-09-07T16-13-09Z
    restart: unless-stopped
    command: server /data --console-address ":9001"
    env_file:
      - ../backend/.env
    environment:
      TZ: Asia/Shanghai
    volumes:
      - minio_data:/data
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '0.5'
        reservations:
          memory: 256M
          cpus: '0.25'
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 10s
      timeout: 5s
      retries: 10

  backend:
    build:
      context: ../backend
    restart: unless-stopped
    env_file:
      - ../backend/.env
    environment:
      TZ: Asia/Shanghai
    volumes:
      - ../backend/logs:/app/logs
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '1.0'
        reservations:
          memory: 256M
          cpus: '0.5'
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
      minio:
        condition: service_healthy
    expose:
      - "8080"

volumes:
  caddy_data:
  caddy_config:
  mysql_data:
  redis_data:
  minio_data:
