# deer-flow-backend Dockerfile 离线版本
# 修改点: 使用本地 deer-flow 源码替代 git clone

FROM ghcr.nju.edu.cn/astral-sh/uv:python3.12-bookworm

# Install uv.
COPY --from=ghcr.nju.edu.cn/astral-sh/uv:latest /uv /bin/uv

# 配置 apt 阿里云镜像源并安装系统依赖
RUN if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
        sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources; \
    elif [ -f /etc/apt/sources.list ]; then \
        sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list; \
    fi && \
    apt-get update && apt-get install -y \
    libpq-dev git \
    && rm -rf /var/lib/apt/lists/*

# 配置 uv 使用阿里云 PyPI 镜像
ENV UV_INDEX_URL="https://mirrors.aliyun.com/pypi/simple/"

WORKDIR /app

# 离线模式: 本地 deer-flow 路径
ARG RESOURCES_DIR=./build-cache/resources
ARG DEERFLOW_DIR=${RESOURCES_DIR}/deer-flow

# 复制本地 deer-flow 源码（离线环境预先下载）
COPY ${DEERFLOW_DIR} /app
COPY runtime/deer-flow/.env /app/.env
COPY runtime/deer-flow/conf.yaml /app/conf.yaml

# Pre-cache the application dependencies.
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked --no-install-project

# Install the application dependencies.
RUN --mount=type=cache,target=/root/.cache/uv \
    uv sync --locked

EXPOSE 8000

# Run the application.
CMD ["uv", "run", "--no-sync", "python", "server.py", "--host", "0.0.0.0", "--port", "8000"]
