Spaces:
Paused
Paused
| # 使用官方Python 3.9 Alpine作为基础镜像(轻量级) | |
| FROM python:3.9-alpine | |
| # 设置工作目录 | |
| WORKDIR /app | |
| # 安装系统依赖 | |
| # 添加 py3-yaml 直接通过 apk 安装 PyYAML | |
| RUN apk add --no-cache \ | |
| curl \ | |
| ca-certificates \ | |
| tzdata \ | |
| tar \ | |
| gzip \ | |
| python3-dev \ | |
| musl-dev \ | |
| libffi-dev \ | |
| yaml-dev \ | |
| py3-yaml | |
| # 不再需要 build-base,因为不再编译 PyYAML | |
| # 设置时区为亚洲/上海 | |
| ENV TZ=Asia/Shanghai | |
| # 创建必要的目录并设置权限 | |
| RUN mkdir -p ./clash_core ./subconverter ./data && \ | |
| chmod -R 777 ./data | |
| # 下载并安装Clash Meta,保留原始文件名 | |
| RUN echo "Downloading Clash Meta..." && \ | |
| curl -L -f -o /tmp/clash-meta.gz "https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/clash.meta-linux-amd64-v1.16.0.gz" && \ | |
| echo "Extracting Clash Meta..." && \ | |
| gunzip -c /tmp/clash-meta.gz > ./clash_core/clash.meta-linux-amd64 && \ | |
| echo "Setting Clash Meta permissions..." && \ | |
| chmod +x ./clash_core/clash.meta-linux-amd64 && \ | |
| echo "Verifying Clash Meta exists..." && \ | |
| test -f ./clash_core/clash.meta-linux-amd64 && \ | |
| echo "Cleaning up Clash Meta download..." && \ | |
| rm /tmp/clash-meta.gz | |
| # 下载并完整解压subconverter | |
| RUN echo "Downloading subconverter..." && \ | |
| curl -L -f -o /tmp/subconverter.tar.gz "https://github.com/tindy2013/subconverter/releases/download/v0.7.2/subconverter_linux64.tar.gz" && \ | |
| echo "Extracting subconverter archive..." && \ | |
| tar -xzf /tmp/subconverter.tar.gz -C ./subconverter --strip-components=1 && \ | |
| echo "Setting subconverter permissions..." && \ | |
| chmod +x ./subconverter/subconverter && \ | |
| echo "Verifying subconverter exists..." && \ | |
| test -f ./subconverter/subconverter && \ | |
| echo "Cleaning up subconverter download..." && \ | |
| rm /tmp/subconverter.tar.gz | |
| # 复制Python依赖列表 | |
| COPY requirements.txt ./ | |
| # 升级 pip | |
| RUN pip install --upgrade pip | |
| # 不再需要预安装 Cython 和 setuptools | |
| # RUN pip install --no-cache-dir Cython setuptools | |
| # 不再需要设置 PyYAML 环境变量 | |
| # ENV YAML_INCLUDE_DIR=/usr/include \ | |
| # YAML_LIB_DIR=/usr/lib | |
| # 不再需要单独安装 PyYAML | |
| # RUN echo "Installing PyYAML..." && \ | |
| # pip install --no-cache-dir --no-build-isolation PyYAML==6.0 | |
| # 安装剩余的Python依赖 (PyYAML 已通过 apk 安装) | |
| RUN echo "Installing Python dependencies..." && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # 可选:删除构建依赖以减小镜像体积 | |
| # RUN apk del python3-dev musl-dev libffi-dev yaml-dev | |
| # 设置环境变量 | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| FLASK_APP=app.main \ | |
| FLASK_ENV=production | |
| # 复制应用代码 | |
| COPY app/ ./app/ | |
| # 复制启动脚本并赋予执行权限 | |
| COPY entrypoint.sh ./ | |
| RUN chmod +x ./entrypoint.sh | |
| # 暴露单一端口 (Hugging Face Spaces要求) | |
| EXPOSE 8000 | |
| # 使用entrypoint脚本启动应用 | |
| ENTRYPOINT ["/app/entrypoint.sh"] |