name: multi-rider

# 离线/内网部署：镜像通过 `docker load -i multi-rider-*.tar` 提前导入，
# compose 不再尝试 build；如需在联网构建机上重建，请使用
#   docker build -f ops/Dockerfile -t ${MULTI_RIDER_IMAGE:-multi-rider:latest} .
# 然后 `docker save` 出 tar 拷到内网。
x-app-common: &app-common
  image: ${MULTI_RIDER_IMAGE:-multi-rider:latest}
  pull_policy: never
  env_file:
    - ${APP_ENV_FILE:-./app.env}
  volumes:
    - ${MULTI_RIDER_ROOT:-./runtime}/data:/data
    - ${MULTI_RIDER_ROOT:-./runtime}/data:/app/data
    - ${MULTI_RIDER_ROOT:-./runtime}/output:/app/output
    - ${MULTI_RIDER_ROOT:-./runtime}/datasets:/app/datasets
    - ${MULTI_RIDER_ROOT:-./runtime}/face_data:/app/face_data
    - ${MULTI_RIDER_ROOT:-./runtime}/train_runs:/app/train_runs
    - ${MULTI_RIDER_ROOT:-./runtime}/upload_tmp:/app/upload_tmp
    - ${MULTI_RIDER_MODEL_ROOT:-./model}:/app/model
  restart: unless-stopped

services:
  web:
    <<: *app-common
    container_name: multi-rider-web
    command: sh -c "if [ -f scripts/run_migrations.py ]; then python scripts/run_migrations.py || echo '[warn] migrations failed, continuing'; else echo '[warn] scripts/run_migrations.py not in image, skipping migrations'; fi; exec python app.py"
    ports:
      - "${APP_PORT:-5001}:5001"
    healthcheck:
      test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:5001/api/health', timeout=5).read()\""]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  worker:
    <<: *app-common
    container_name: multi-rider-worker
    command: python worker.py
    depends_on:
      - web
