Commit 8765dfb7 by sunqi02

feat: add Dockerfile.prod with multi-stage build and non-root user

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 8a67bdac
# ============ Stage 1: Builder ============
FROM python:3.12-slim AS builder
WORKDIR /build
# 安装编译依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# 安装 Python 依赖到指定目录(便于后续拷贝)
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# ============ Stage 2: Runtime ============
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
# 从 builder 拷贝已安装的 Python 包
COPY --from=builder /install /usr/local
# 拷贝项目文件
COPY app/ ./app/
COPY config/ ./config/
COPY skills/ ./skills/
COPY sitecustomize.py ./
# 创建非 root 用户并切换
RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser \
&& chown -R appuser:appuser /app
USER appuser
EXPOSE 8000
# 生产模式:多进程,无热重载
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!