# 检澜（DockScope）— Docker 堆栈（本文件不含 build，避免中文路径下 compose --build 触发 Bake/gRPC 错误）
# 一键启动（项目根目录，需已安装 Node）：npm install && npm run up
# 纯命令（PowerShell 一行）：$env:DOCKER_BUILDKIT='0'; docker build -f docker/backend/Dockerfile -t bridge-disease-backend:local .; docker build -f docker/frontend/Dockerfile --build-arg VITE_API_BASE_URL=http://127.0.0.1:5000 -t bridge-disease-frontend:local .; docker compose -p bridge-disease up -d
# 检澜 Web http://localhost:8080  检澜 API http://localhost:5000

name: bridge-disease

services:
  db:
    image: mysql:8.0
    container_name: bridge-disease-mysql
    restart: unless-stopped
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-bridgedisease_root}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-bridge_disease}
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "${MYSQL_HOST_PORT:-3307}:3306"
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uroot -p$$MYSQL_ROOT_PASSWORD || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 30
      start_period: 30s

  backend:
    image: bridge-disease-backend:local
    container_name: bridge-disease-backend
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      FLASK_RUN_HOST: "0.0.0.0"
      FLASK_RUN_PORT: "5000"
      MYSQL_HOST: db
      MYSQL_PORT: "3306"
      MYSQL_USER: root
      MYSQL_PASSWORD: ${MYSQL_ROOT_PASSWORD:-bridgedisease_root}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-bridge_disease}
      SQLALCHEMY_DATABASE_URI: mysql+pymysql://root:${MYSQL_ROOT_PASSWORD:-bridgedisease_root}@db:3306/${MYSQL_DATABASE:-bridge_disease}?charset=utf8mb4
    ports:
      - "5000:5000"

  frontend:
    image: bridge-disease-frontend:local
    container_name: bridge-disease-frontend
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - "8080:80"

volumes:
  mysql_data:
