guohanghui commited on
Commit
a8ac1e4
·
verified ·
1 Parent(s): 0acb792

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +53 -17
Dockerfile CHANGED
@@ -1,43 +1,79 @@
1
  FROM python:3.10
2
 
3
- # 安装构建工具、git 和必要的库
4
  RUN apt-get update && apt-get install -y \
5
  git \
6
  build-essential \
7
  cmake \
 
 
 
8
  libboost-all-dev \
9
- && rm -rf /var/lib/apt/lists/* && \
10
- python -m pip install --upgrade pip
 
11
 
12
- # 创建非 root 用户
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  RUN useradd -m -u 1000 user
 
 
 
 
14
  USER user
15
  ENV PATH="/home/user/.local/bin:$PATH"
16
 
17
  WORKDIR /app
18
 
19
- # 复制并安装依赖
20
  COPY --chown=user ./requirements.txt requirements.txt
21
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
22
 
23
  # 复制代码
24
  COPY --chown=user . /app
25
 
26
- # 编译 medpy 扩展模块
27
- WORKDIR /app/medpy/source
28
- RUN python setup.py build_ext --inplace || echo "Warning: Failed to build extensions"
29
- RUN pip install --no-cache-dir -e . || echo "Warning: Failed to install medpy"
30
-
31
- # 返回工作目录
32
- WORKDIR /app
33
-
34
- # 设置 Python 路径
35
- ENV PYTHONPATH=/app/medpy/source:$PYTHONPATH
36
 
37
  # 端口与环境变量
38
  EXPOSE 7860
39
  ENV MCP_TRANSPORT=http
40
  ENV MCP_PORT=7860
41
 
42
- # 启动命令
43
- CMD ["python", "medpy/mcp_output/start_mcp.py"]
 
 
1
  FROM python:3.10
2
 
3
+ # 安装所有可能需要的构建工具
4
  RUN apt-get update && apt-get install -y \
5
  git \
6
  build-essential \
7
  cmake \
8
+ g++ \
9
+ gcc \
10
+ gfortran \
11
  libboost-all-dev \
12
+ python3-dev \
13
+ swig \
14
+ && rm -rf /var/lib/apt/lists/*
15
 
16
+ # 升级 pip 和构建工具
17
+ RUN python -m pip install --upgrade pip setuptools wheel
18
+
19
+ # 先安装编译依赖
20
+ RUN pip install --no-cache-dir \
21
+ Cython>=0.29.0 \
22
+ numpy>=1.21.0 \
23
+ scipy>=1.7.0
24
+
25
+ WORKDIR /tmp
26
+
27
+ # 复制 medpy source
28
+ COPY ./medpy/source /tmp/medpy_source
29
+
30
+ WORKDIR /tmp/medpy_source
31
+
32
+ # 清理之前的编译产物
33
+ RUN rm -rf build/ dist/ *.egg-info
34
+
35
+ # 详细编译日志
36
+ RUN echo "=== Starting medpy compilation ===" && \
37
+ python setup.py build_ext --inplace --force --verbose 2>&1 | tee /tmp/compile.log && \
38
+ echo "=== Compilation log ===" && \
39
+ cat /tmp/compile.log
40
+
41
+ # 安装编译后的 medpy
42
+ RUN pip install -e . --verbose
43
+
44
+ # 关键:验证 maxflow 是否真的编译成功
45
+ RUN echo "=== Verifying maxflow ===" && \
46
+ python -c "import sys; print('Python path:', sys.path)" && \
47
+ python -c "import medpy; print('medpy location:', medpy.__file__)" && \
48
+ python -c "from medpy.graphcut import maxflow; print('✓✓✓ maxflow loaded successfully'); print('GraphDouble:', maxflow.GraphDouble)" && \
49
+ echo "=== maxflow verification passed ==="
50
+
51
+ # 创建用户
52
  RUN useradd -m -u 1000 user
53
+
54
+ # 复制编译好的 maxflow 到用户可访问位置(如果需要)
55
+ RUN find /tmp/medpy_source -name "*.so" -o -name "*.pyd" | xargs -I {} echo "Found compiled extension: {}"
56
+
57
  USER user
58
  ENV PATH="/home/user/.local/bin:$PATH"
59
 
60
  WORKDIR /app
61
 
62
+ # 安装其他依赖
63
  COPY --chown=user ./requirements.txt requirements.txt
64
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
65
 
66
  # 复制代码
67
  COPY --chown=user . /app
68
 
69
+ # Python 路径
70
+ ENV PYTHONPATH=/app:$PYTHONPATH
 
 
 
 
 
 
 
 
71
 
72
  # 端口与环境变量
73
  EXPOSE 7860
74
  ENV MCP_TRANSPORT=http
75
  ENV MCP_PORT=7860
76
 
77
+ # 启动前再次验证
78
+ CMD python -c "from medpy.graphcut.maxflow import GraphDouble; print('✓ maxflow available')" && \
79
+ python medpy/mcp_output/start_mcp.py