LifeVta commited on
Commit
8d715cc
·
verified ·
1 Parent(s): 58943a6

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -13
Dockerfile CHANGED
@@ -22,7 +22,6 @@ RUN apk add --no-cache \
22
  WORKDIR /app
23
 
24
  # Pin uv to a minor version for reproducible builds.
25
- # Bump manually when you want to pick up a newer uv release.
26
  COPY --from=ghcr.io/astral-sh/uv:0.6 /uv /uvx /bin/
27
 
28
  COPY pyproject.toml uv.lock ./
@@ -38,21 +37,13 @@ RUN uv sync --frozen --no-dev --no-install-project \
38
  # ── Runtime ───────────────────────────────────────────────────────────────────
39
  FROM python:3.13-alpine
40
 
41
- # 固化网页默认开关(非敏感数据,公开可见安全无虞)
42
  ENV PYTHONDONTWRITEBYTECODE=1 \
43
  PYTHONUNBUFFERED=1 \
44
  TZ=Asia/Shanghai \
45
  VIRTUAL_ENV=/opt/venv \
46
  SERVER_HOST=0.0.0.0 \
47
  SERVER_PORT=7860 \
48
- SERVER_WORKERS=1 \
49
- APP_BASE_URL="https://lifevta-grok2api.hf.space/" \
50
- ENABLE_WEBUI="true" \
51
- TEMPORARY_SESSIONS="false" \
52
- CONVERSATION_MEMORY="true" \
53
- CONDENSED_REASONING="true" \
54
- DYNAMIC_STATSIG="true" \
55
- ALLOW_NSFW_GENERATION="true"
56
 
57
  ENV PATH="$VIRTUAL_ENV/bin:$PATH"
58
 
@@ -69,13 +60,12 @@ WORKDIR /app
69
 
70
  COPY --from=builder /opt/venv /opt/venv
71
 
72
- # 🌟 关键修复点:加了通配符后,编译时如果有加密包就会打包进去,如果没有也会安全跳过不报错
73
  COPY pyproject.toml config.defaults.toml ./
74
  COPY accounts.db.enc* ./
75
  COPY app ./app
76
  COPY scripts ./scripts
77
 
78
- # 恢复真实的本地物理目录,让你的启动脚本能够顺利 mkdir 顺利通过
79
  RUN mkdir -p /app/data /app/logs \
80
  && chmod +x /app/scripts/entrypoint.sh /app/scripts/init_storage.sh
81
 
@@ -85,4 +75,19 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
85
  CMD ["sh", "-c", "wget -qO /dev/null http://127.0.0.1:${SERVER_PORT}/health || exit 1"]
86
 
87
  ENTRYPOINT ["/app/scripts/entrypoint.sh"]
88
- CMD ["sh", "-c", "exec granian --interface asgi --host ${SERVER_HOST} --port ${SERVER_PORT} --workers ${SERVER_WORKERS} app.main:app"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  WORKDIR /app
23
 
24
  # Pin uv to a minor version for reproducible builds.
 
25
  COPY --from=ghcr.io/astral-sh/uv:0.6 /uv /uvx /bin/
26
 
27
  COPY pyproject.toml uv.lock ./
 
37
  # ── Runtime ───────────────────────────────────────────────────────────────────
38
  FROM python:3.13-alpine
39
 
 
40
  ENV PYTHONDONTWRITEBYTECODE=1 \
41
  PYTHONUNBUFFERED=1 \
42
  TZ=Asia/Shanghai \
43
  VIRTUAL_ENV=/opt/venv \
44
  SERVER_HOST=0.0.0.0 \
45
  SERVER_PORT=7860 \
46
+ SERVER_WORKERS=1
 
 
 
 
 
 
 
47
 
48
  ENV PATH="$VIRTUAL_ENV/bin:$PATH"
49
 
 
60
 
61
  COPY --from=builder /opt/venv /opt/venv
62
 
 
63
  COPY pyproject.toml config.defaults.toml ./
64
  COPY accounts.db.enc* ./
65
  COPY app ./app
66
  COPY scripts ./scripts
67
 
68
+ # 建立标准的物理运行目录
69
  RUN mkdir -p /app/data /app/logs \
70
  && chmod +x /app/scripts/entrypoint.sh /app/scripts/init_storage.sh
71
 
 
75
  CMD ["sh", "-c", "wget -qO /dev/null http://127.0.0.1:${SERVER_PORT}/health || exit 1"]
76
 
77
  ENTRYPOINT ["/app/scripts/entrypoint.sh"]
78
+
79
+ # 🌟 核心改进:抛弃不稳定的 sed,改用纯 Python 拦截器,在服务拉起的最后一刻同时强刷默认模板与抢跑生成的运行时配置
80
+ CMD ["sh", "-c", "python3 -c \"import os; \
81
+ def patch(f): \
82
+ if not os.path.exists(f): return; \
83
+ t=open(f,'r',encoding='utf-8').read(); pw=os.getenv('APP_ACCESS_PASSWORD','grok2api'); \
84
+ t=t.replace('app_key = \\\"grok2api\\\"', f'app_key = \\\"{pw}\\\"').replace('app_key = \\\"\\\"', f'app_key = \\\"{pw}\\\"'); \
85
+ t=t.replace('app_url = \\\"\\\"', 'app_url = \\\"https://lifevta-grok2api.hf.space/\\\"'); \
86
+ t=t.replace('api_key = \\\"\\\"', f'api_key = \\\"{pw}\\\"'); \
87
+ t=t.replace('webui_enabled = false', 'webui_enabled = true'); \
88
+ t=t.replace('webui_key = \\\"\\\"', f'webui_key = \\\"{pw}\\\"'); \
89
+ t=t.replace('temporary = true', 'temporary = false'); \
90
+ t=t.replace('memory = false', 'memory = true'); \
91
+ t=t.replace('thinking_summary = false', 'thinking_summary = true'); \
92
+ open(f,'w',encoding='utf-8').write(t); \
93
+ for p in ['config.defaults.toml', 'data/config.toml', '/app/data/config.toml']: patch(p)\"; exec granian --interface asgi --host ${SERVER_HOST} --port ${SERVER_PORT} --workers ${SERVER_WORKERS} app.main:app"]