guohanghui commited on
Commit
e52ebd4
·
verified ·
1 Parent(s): d23db5b

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +51 -0
Dockerfile ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ # 安装系统依赖(包括编译 ephem 所需的依赖)
4
+ RUN apt-get update && apt-get install -y \
5
+ git \
6
+ build-essential \
7
+ python3-dev \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ # 升级 pip
11
+ RUN python -m pip install --upgrade pip setuptools wheel
12
+
13
+ # 创建非 root 用户
14
+ RUN useradd -m -u 1000 user
15
+ USER user
16
+
17
+ # 设置环境变量
18
+ ENV PATH="/home/user/.local/bin:$PATH"
19
+ ENV PYTHONPATH=/app/PyPSA/source:$PYTHONPATH
20
+ ENV MCP_TRANSPORT=http
21
+ ENV MCP_PORT=7860
22
+
23
+ # 设置工作目录
24
+ WORKDIR /app
25
+
26
+ # 复制代码(必须先复制才能编译本地 ephem)
27
+ COPY --chown=user:user . /app
28
+
29
+ # 在非 root 用户前安装 ephem 的编译依赖(必须用 root)
30
+ USER root
31
+ RUN apt-get update && apt-get install -y \
32
+ python3-dev \
33
+ && rm -rf /var/lib/apt/lists/*
34
+ USER user
35
+
36
+ # 复制并安装依赖
37
+ COPY --chown=user:user ./requirements.txt requirements.txt
38
+ RUN pip install --no-cache-dir --user --upgrade -r requirements.txt
39
+
40
+ # 编译本地的 ephem 源码
41
+ RUN cd /app/pyephem/source && python setup.py build_ext --inplace 2>&1 || echo "Trying pip install in-place build..."
42
+ RUN pip install --no-cache-dir --user -e /app/PyPSA/source 2>&1 || true
43
+
44
+ # 复制代码(必须先复制才能编译本地 ephem)
45
+ COPY --chown=user:user . /app
46
+
47
+ # 端口暴露
48
+ EXPOSE 7860
49
+
50
+ # 启动命令
51
+ CMD ["python", "PyPSA/mcp_output/start_mcp.py"]