services:
  # ==================== 基础设施（可选，默认使用宿主机 MySQL/Redis）====================
  # 如需独立数据库，取消注释以下 mysql 和 redis 服务
  # mysql:
  #   image: mysql:5.7
  #   platform: linux/amd64
  #   container_name: smartclean-mysql
  #   ports:
  #     - "${MYSQL_PORT:-3307}:3306"
  #   environment:
  #     MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-kaixinjiuhao}
  #   volumes:
  #     - mysql_data:/var/lib/mysql
  #     - ./init-sql:/docker-entrypoint-initdb.d
  #     - ../../sql:/sql-source
  #   command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
  #   healthcheck:
  #     test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
  #     interval: 10s
  #     timeout: 5s
  #     retries: 10
  #     start_period: 30s
  #   networks:
  #     - smartclean

  # redis:
  #   image: redis:6-alpine
  #   container_name: smartclean-redis
  #   ports:
  #     - "${REDIS_PORT:-6380}:6379"
  #   command: redis-server --requirepass ${REDIS_PASSWORD:-kaixinjiuhao}
  #   volumes:
  #     - redis_data:/data
  #   healthcheck:
  #     test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD:-kaixinjiuhao}", "ping"]
  #     interval: 10s
  #     retries: 3
  #   networks:
  #     - smartclean

  # ==================== 应用服务 ====================
  web:
    image: smartclean-web:${VERSION:-latest}
    container_name: smartclean-web
    build:
      context: ../..
      dockerfile: deploy/docker/Dockerfile.web
    ports:
      - "${WEB_PORT:-18095}:8080"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./conf/application-docker.yml:/app/config/application-docker.yml
      - web_logs:/app/logs
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/"]
      interval: 15s
      timeout: 5s
      retries: 5
      start_period: 90s
    restart: on-failure:3
    networks:
      - smartclean

  task:
    image: smartclean-task:${VERSION:-latest}
    container_name: smartclean-task
    build:
      context: ../..
      dockerfile: deploy/docker/Dockerfile.task
    ports:
      - "${TASK_PORT:-18097}:8097"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      SPRING_PROFILES_ACTIVE: docker
    volumes:
      - ./conf/application-task-docker.yml:/app/config/application-task-docker.yml
      - task_logs:/app/logs
    restart: on-failure:3
    networks:
      - smartclean

  frontend:
    image: smartclean-front:${VERSION:-latest}
    container_name: smartclean-front
    build:
      context: ../..
      dockerfile: deploy/docker/Dockerfile.front
    ports:
      - "${FRONT_PORT:-8180}:80"
    depends_on:
      - web
    volumes:
      - ./conf/nginx.conf:/etc/nginx/conf.d/default.conf
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost/"]
      interval: 10s
      retries: 3
    restart: on-failure:3
    networks:
      - smartclean

volumes:
  web_logs:
  task_logs:

networks:
  smartclean:
    driver: bridge
