# Multi-stage Dockerfile for TraceStudio server (production) FROM python:3.10-slim as builder WORKDIR /build # Install build deps RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ gcc \ && rm -rf /var/lib/apt/lists/* # Copy requirements and install into a wheel/cache location COPY server/requirements.txt ./requirements.txt RUN pip install --no-cache-dir --upgrade pip setuptools wheel # 使用 --user 安装,这样可以保留 bin 目录结构,方便后续复制 RUN pip install --no-cache-dir --user -r requirements.txt FROM python:3.10-slim WORKDIR /app # Copy installed dependencies from builder (including bin scripts like uvicorn) COPY --from=builder /root/.local /root/.local # Copy server code COPY server/ /app/ # Copy custom nodes into expected location COPY cloud/custom_nodes /app/custom_nodes # Ensure local bin is in PATH so we can run uvicorn directly ENV PATH=/root/.local/bin:$PATH ENV PYTHONUNBUFFERED=1 ENV CLOUD_ROOT=/opt/tracestudio/cloud EXPOSE 8000 # 关键修改:启动时强制检查并更新 pytrace # 注意:容器运行环境需要能够访问 pytrace 的发布源 (PyPI 或 私有源) CMD ["sh", "-c", "pip install --upgrade --no-cache-dir pytrace && uvicorn main:app --host 0.0.0.0 --port 8000"]