# HuggingFace Spaces 自动部署 - 包含 airs_protocol 下载 FROM ubuntu:22.04 # 避免交互式提示 ENV DEBIAN_FRONTEND=noninteractive ENV TZ=Asia/Shanghai # 设置工作目录 WORKDIR /app # 更新包管理器并安装基础依赖 RUN apt-get update && apt-get install -y \ curl \ wget \ git \ ca-certificates \ gnupg \ lsb-release \ software-properties-common \ build-essential \ python3-dev \ python3-pip \ python3-venv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # 安装 Node.js 22.04 RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \ && apt-get install -y nodejs # 安装 Python 3.12.11 RUN add-apt-repository ppa:deadsnakes/ppa \ && apt-get update \ && apt-get install -y python3.12 python3.12-dev python3.12-venv python3.12-distutils \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # 设置 Python 3.12 为默认 RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 # 安装最新 pip RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12 # 升级 pip RUN python3 -m pip install --upgrade pip setuptools wheel # 创建启动脚本 RUN echo '#!/bin/bash\n\ set -e\n\ \n\ echo "正在下载 airs_protocol 代码..."\n\ \n\ # 克隆 airs_protocol 仓库到主目录\n\ if [ -d "airs_protocol" ]; then\n\ echo "清理旧代码..."\n\ rm -rf "airs_protocol"\n\ fi\n\ \n\ git clone -b master https://gitee.com/tanbushi/airs-protocol.git temp_airs\n\ \n\ # 只复制 airs_protocol 子目录的内容到主目录\n\ if [ -d "temp_airs/airs_protocol" ]; then\n\ mkdir -p airs_protocol\n\ cp -r temp_airs/airs_protocol/* airs_protocol/\n\ cp -r temp_airs/airs_protocol/.[^.]* airs_protocol/ 2>/dev/null || true\n\ fi\n\ \n\ # 清理临时文件\n\ rm -rf temp_airs\n\ \n\ echo "airs_protocol 代码下载完成"\n\ ls -la airs_protocol/\n\ \n\ # 安装当前项目依赖\n\ if [ -f "package.json" ]; then\n\ echo "安装 Node.js 依赖..."\n\ npm install\n\ fi\n\ \n\ if [ -f "requirements.txt" ]; then\n\ echo "安装 Python 依赖..."\n\ python3 -m pip install -r requirements.txt\n\ fi\n\ \n\ # 安装 airs_protocol 依赖\n\ if [ -f "airs_protocol/requirements.txt" ]; then\n\ echo "安装 airs_protocol Python 依赖..."\n\ python3 -m pip install -r airs_protocol/requirements.txt\n\ fi\n\ \n\ if [ -f "airs_protocol/package.json" ]; then\n\ echo "安装 airs_protocol Node.js 依赖..."\n\ cd airs_protocol && npm install && cd ..\n\ fi\n\ \n\ echo "环境准备完成,启动应用..."\n\ \n\ # HuggingFace Spaces 启动逻辑\n\ if [ $# -gt 0 ]; then\n\ exec "$@"\n\ else\n\ # 优先级启动顺序\n\ if [ -f "package.json" ]; then\n\ if grep -q "start" package.json; then\n\ echo "使用 npm start 启动..."\n\ exec npm start\n\ fi\n\ fi\n\ \n\ if [ -f "app.py" ]; then\n\ echo "使用 python app.py 启动..."\n\ exec python3 app.py\n\ fi\n\ \n\ if [ -f "main.py" ]; then\n\ echo "使用 python main.py 启动..."\n\ exec python3 main.py\n\ fi\n\ \n\ if [ -f "server.py" ]; then\n\ echo "使用 python server.py 启动..."\n\ exec python3 server.py\n\ fi\n\ \n\ # 默认保持运行,避免容器重启\n\ echo "未找到标准启动文件,保持容器运行..."\n\ sleep infinity\n\ fi' > /app/entrypoint.sh \ && chmod +x /app/entrypoint.sh # 复制项目文件 COPY . . # 暴露 HuggingFace Spaces 默认端口 EXPOSE 7860 # HuggingFace Spaces 会使用此 entrypoint ENTRYPOINT ["/app/entrypoint.sh"]