Spaces:
Sleeping
Sleeping
| # 使用官方Python镜像作为基础镜像 | |
| FROM python:3.10-slim | |
| # 设置工作目录 | |
| WORKDIR /app | |
| # 复制当前目录内容到容器中 | |
| COPY . /app | |
| # 安装Playwright系统依赖和Python包 | |
| RUN apt-get update && \ | |
| apt-get install -y \ | |
| wget \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 安装Python依赖 | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| RUN pip install requests | |
| # 设置Playwright缓存目录的环境变量 | |
| ENV PLAYWRIGHT_BROWSERS_PATH=/app/playwright-browsers | |
| # 安装Playwright和浏览器(使用普通用户权限) | |
| RUN pip install playwright && \ | |
| playwright install --with-deps | |
| # 创建非root用户并切换 | |
| RUN useradd -m myuser && chown -R myuser:myuser /app | |
| USER myuser | |
| # 暴露端口 | |
| EXPOSE 8000 | |
| # 运行应用 | |
| CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"] |