vm / Dockerfile
bitterapricot's picture
fix error.
40afb77
Raw
History Blame Contribute Delete
3.7 kB
# 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"]