FROM python:3.10 RUN apt-get update && apt-get install -y \ gfortran \ libopenmpi-dev \ openmpi-bin \ libopenblas-dev \ liblapack-dev \ pkg-config \ git \ && rm -rf /var/lib/apt/lists/* RUN useradd -m -u 1000 user && \ python -m pip install --upgrade pip USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # 克隆 pyPDAF(包含 submodule) RUN git clone --recursive https://github.com/yumengch/pyPDAF.git pyPDAF_source WORKDIR /app/pyPDAF_source # 设置 MPI 编译器环境变量 ENV MPIFC=mpifort ENV FC=mpifort ENV F90=mpifort # 安装构建依赖 RUN pip install --no-cache-dir meson-python meson ninja cython numpy mpi4py # 尝试编译安装(如果失败就跳过) RUN pip install --no-cache-dir -v . || echo "Build failed, will try alternative" # 如果上面失败,尝试直接使用预编译的 wheel RUN if ! python -c "import pyPDAF" 2>/dev/null; then \ pip install --no-cache-dir pypdaf || \ echo "Both build and install failed"; \ fi WORKDIR /app # 复制 MCP 代码 COPY --chown=user ./pyPDAF/mcp_output /app/pyPDAF/mcp_output COPY --chown=user ./requirements.txt /app/requirements.txt # 修复导入语句 RUN if [ -f /app/pyPDAF/mcp_output/mcp_plugin/mcp_service.py ]; then \ sed -i 's/from src\.pyPDAF import/from pyPDAF import/g' /app/pyPDAF/mcp_output/mcp_plugin/mcp_service.py; \ fi # 安装其他依赖 RUN pip install --no-cache-dir --upgrade -r requirements.txt ENV PYTHONPATH=/app:$PYTHONPATH ENV MCP_TRANSPORT=http ENV MCP_PORT=7860 EXPOSE 7860 CMD ["python", "pyPDAF/mcp_output/start_mcp.py"]