vomebook commited on
Commit
1177c28
·
verified ·
1 Parent(s): 71394cc

Upload Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -4
Dockerfile CHANGED
@@ -1,8 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
5
- # 安装系统依赖(gzip 用于压缩 JSON 响应)
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
  gzip \
8
  && rm -rf /var/lib/apt/lists/*
@@ -11,14 +27,14 @@ COPY requirements.txt .
11
  RUN pip install --no-cache-dir -r requirements.txt
12
 
13
  COPY app.py .
14
- COPY static/ static/
15
  COPY data/ data/
 
16
 
17
- # 可选:预压缩 search_data.json 加速首次加载
18
  RUN if [ -f data/search_data.json ]; then \
19
  gzip -k -9 data/search_data.json; \
20
  fi
21
 
22
  EXPOSE 7860
23
 
24
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--log-level", "info"]
 
1
+ FROM node:22-bookworm-slim AS static-assets
2
+
3
+ ARG ESBUILD_VERSION=0.25.8
4
+
5
+ WORKDIR /build
6
+
7
+ RUN npm install --global "esbuild@${ESBUILD_VERSION}" \
8
+ && test "$(esbuild --version)" = "${ESBUILD_VERSION}"
9
+
10
+ COPY static/ /build/static/
11
+
12
+ RUN mkdir -p /out \
13
+ && cp -a static/. /out/ \
14
+ && esbuild static/app.js --minify --target=es2019 --charset=utf8 --legal-comments=none --outfile=/out/app.js \
15
+ && esbuild static/style.css --minify --outfile=/out/style.css \
16
+ && esbuild static/sw.js --minify --target=es2019 --charset=utf8 --legal-comments=none --outfile=/out/sw.js
17
+
18
  FROM python:3.11-slim
19
 
20
  WORKDIR /app
21
 
 
22
  RUN apt-get update && apt-get install -y --no-install-recommends \
23
  gzip \
24
  && rm -rf /var/lib/apt/lists/*
 
27
  RUN pip install --no-cache-dir -r requirements.txt
28
 
29
  COPY app.py .
30
+ COPY --from=static-assets /out/ static/
31
  COPY data/ data/
32
+ COPY txt/ txt/
33
 
 
34
  RUN if [ -f data/search_data.json ]; then \
35
  gzip -k -9 data/search_data.json; \
36
  fi
37
 
38
  EXPOSE 7860
39
 
40
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--log-level", "info"]