-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (43 loc) · 1.51 KB
/
Dockerfile
File metadata and controls
61 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ==================== 后端服务 Dockerfile ====================
# 多阶段构建优化镜像大小
# ==================== 构建阶段 ====================
FROM python:3.13-slim AS builder
WORKDIR /build
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never
COPY pyproject.toml .
RUN uv venv /opt/venv && \
. /opt/venv/bin/activate && \
uv pip install --no-cache -e .
# ==================== 运行阶段 ====================
FROM python:3.13-slim AS runner
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender1 \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
RUN groupadd --gid 1000 appgroup && \
useradd --uid 1000 --gid appgroup --shell /bin/bash --create-home appuser
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
APP_DEBUG=false \
APP_LOG_LEVEL=INFO \
APP_LOG_DIR=logs
COPY --chown=appuser:appgroup src ./src
COPY --chown=appuser:appgroup pyproject.toml .
RUN mkdir -p logs data/chroma && \
chown -R appuser:appgroup logs data
USER appuser
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
CMD ["uv", "run", "uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]