Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (43 loc) · 1.77 KB
/
Copy pathDockerfile
File metadata and controls
54 lines (43 loc) · 1.77 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
# syntax=docker/dockerfile:1
# ============================================================
# Stage 1: 构建前端 (Node 22)
# 产出 web/dist(Vite 默认配置:root=构建目录, outDir=dist)
# ============================================================
FROM node:22-slim AS frontend
WORKDIR /build
# 先装依赖以利用 Docker 层缓存
COPY web/package.json web/package-lock.json ./
RUN npm ci
# 再拷源码并构建(产物输出到 /build/dist)
COPY web/ ./
# 共享设计系统 input.css 由 app/ 提供,本地以 ../../app/static/src/input.css 引用;
# 构建阶段仅拷贝了 web/,须同步该目录到相对路径对应的 /app/static/src/ 下,否则 vite 解析失败。
COPY app/static/src/ /app/static/src/
RUN npm run build
# ============================================================
# Stage 2: 运行环境 (Python 3.13)
# ============================================================
FROM python:3.13-slim AS runtime
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
USE_SPA=1 \
PORT=5000
WORKDIR /app
# 基础工具:healthcheck 用 curl
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# Python 依赖(gunicorn 单独安装,保持仓库 requirements.txt 不变)
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt gunicorn
# 应用代码
COPY app/ ./app/
COPY run.py serve_spa.py init_db.py ./
# 前端构建产物(来自 Stage 1)
COPY --from=frontend /build/dist ./web/dist/
# SQLite 持久化(务必挂载卷,否则容器重建会清空书签!)
VOLUME ["/app/instance"]
EXPOSE 5000
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]