-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (36 loc) · 1.04 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (36 loc) · 1.04 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
# 阶段 1: 构建前端
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
# 安装 pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# 复制前端代码
COPY frontend/package.json frontend/pnpm-lock.yaml* ./
RUN --mount=type=cache,target=/root/.cache/pnpm pnpm install --frozen-lockfile
COPY frontend/ ./
RUN pnpm build
# 阶段 2: Python 后端
FROM python:3.12-slim AS backend
WORKDIR /app
# 安装 uv
RUN pip install uv
# 复制依赖文件
COPY pyproject.toml ./
# 安装 Python 依赖
RUN uv sync --no-dev --frozen --no-install-project
# 复制应用代码
COPY main.py ./
COPY config.py ./
COPY database.py ./
COPY crypto.py ./
COPY routers/ ./routers/
COPY services/ ./services/
# 复制前端构建产物
COPY --from=frontend-builder /app/frontend/dist ./static
# 创建非 root 用户
RUN useradd -m -u 1000 appuser && \
chown -R appuser:appuser /app
USER appuser
# 暴露端口
EXPOSE 8000
# 启动命令
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--loop", "uvloop"]