File size: 3,700 Bytes
24ee200 bc08ced 5800188 24ee200 4af5292 40afb77 4af5292 24ee200 d8be5ba 24ee200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile
FROM python:3.12
# 安装运行时依赖
RUN apt-get update && apt-get install -y \
build-essential gcc g++ cmake make gnupg \
pybind11-dev libpython3-dev python3-dev \
default-jdk \
net-tools \
nginx \
supervisor \
curl wget git \
libgomp1 \
libwebsockets-dev \
libjson-c-dev \
libssl-dev \
libuv1-dev \
&& rm -rf /var/lib/apt/lists/*
# 安装 ttyd(从源码编译)
RUN cd /tmp && \
git clone https://github.com/tsl0922/ttyd.git && \
cd ttyd && \
mkdir build && cd build && \
cmake .. && \
make && \
make install && \
cd / && \
rm -rf /tmp/ttyd
# 安装 mineru(从源码编译)
#pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple
#pip install uv -i https://mirrors.aliyun.com/pypi/simple
#uv pip install -U "mineru[all]" -i https://mirrors.aliyun.com/pypi/simple
RUN pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple && \
pip install uv -i https://mirrors.aliyun.com/pypi/simple && \
uv pip install --system -U "mineru[all]" -i https://mirrors.aliyun.com/pypi/simple
# cd /tmp && \
# git clone https://github.com/opendatalab/MinerU.git && \
# cd MinerU && \
# uv pip install --system -e .[all] -i https://mirrors.aliyun.com/pypi/simple && \
# cd /
# 验证安装
RUN ttyd --version
# 安装 Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm@latest
RUN useradd -m -u 1000 user
RUN chown -R user:user /var/lib/nginx/ \
&& chmod -R 755 /var/lib/nginx \
&& chown -R user:user /var/log/ \
&& chmod -R 755 /var/log \
&& chown -R user:user /run/ \
&& chmod -R 755 /run
USER user
WORKDIR /app
# 复制 Nginx 配置
#COPY nginx/nginx.conf /etc/nginx/nginx.conf
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY --chown=user . /app
# 编译C++
#RUN cd app_cmake && \
# cmake . && \
# make
# 编译nodejs addon napi C++扩展
#RUN cd app_napi && \
# npm install
# 编译Python C++扩展
RUN cd app_cpppy && \
mkdir -p build && \
cd build && \
cmake .. -DCMAKE_BUILD_TYPE=Release && \
make -j$(nproc)
# 将编译好的扩展复制到Python可导入位置
RUN cp ./app_cpppy/build/*.so ./bin/ 2>/dev/null || true
#RUN cp ./app_cmake/bin/* ./bin/ 2>/dev/null || true
#RUN cp ./app_napi/build/Release/napitools.node ./bin/ 2>/dev/null || true
#RUN cp ./app_napi/build/Release/xcpe ./bin/ 2>/dev/null || true
# 设置环境变量
ENV PATH="/home/user/.local/bin:/app/bin:$PATH"
ENV PYTHONPATH=/usr/local/lib/python3.12/site-packages:/app/bin:$PYTHONPATH
# 设置可执行权限
RUN chmod +x /app/scripts/
RUN chmod +x /app/bin/
# 暴露端口
EXPOSE 7860
# 启动服务
#CMD ["/app/scripts/start.sh"]
#CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
# --port 7860: Hugging Face Spaces 强制要求应用运行在 7860 端口
# --ip 0.0.0.0: 监听所有网络接口
# --allow-root: Docker 容器通常以 root 用户运行,必须开启此权限
# --ServerApp.token: 设置访问密码,默认为 'huggingface'
# --ServerApp.cookie_options: 解决 Spaces 嵌入 iframe 时的 Cookie 跨域问题
#CMD ["jupyter", "lab", "--port=7860", "--ip=0.0.0.0", "--allow-root", \
# "--ServerApp.token='huggingface'", \
# "--ServerApp.cookie_options='{\"SameSite\": \"None\", \"Secure\": true}'"]
# 启动 Supervisor
CMD ["/usr/bin/supervisord", "-n", "-c", "/app/supervisor/supervisor.conf"]
|