github-actions[bot] commited on
Commit
47f9aeb
·
1 Parent(s): 10fc7f0

deploy: 93de9eb — 更新 Dockerfile.huggingface

Browse files
Files changed (2) hide show
  1. Dockerfile +21 -26
  2. Dockerfile.huggingface +21 -26
Dockerfile CHANGED
@@ -11,27 +11,23 @@
11
  # [Bug2] build-essential for better-sqlite3 node-gyp fallback
12
  # [Bug3] npm install --omit=dev (--only=production deprecated in npm v10)
13
  # [Bug5] ARG LITELLM_VERSION for single-source versioning
14
- # [BugP] prisma generate — LiteLLM v1.61+ initialises its Prisma client at
15
- # lifespan startup whenever database_url is present in config. The
16
- # prisma-client-py package requires the Prisma query-engine binary to
17
- # exist before the process starts. Without this step the container
18
- # crashes immediately with:
19
  # ModuleNotFoundError: No module named 'prisma'
20
  # Exception: Unable to find Prisma binaries.
21
  # Please run 'prisma generate' first.
22
  #
23
- # IMPORTANT — cache-dir alignment:
24
- # prisma-client-py stores the downloaded query-engine binary in
25
- # PRISMA_BINARY_CACHE_DIR (default: ~/.cache/prisma-binaries/).
26
- # If we run `prisma generate` as root during the build, binaries land
27
- # in /root/.cache/. At runtime the container runs as uid=1000 (user),
28
- # which looks in /home/user/.cache/ — a completely different path, so
29
- # the binary is never found.
30
- #
31
- # Fix: set PRISMA_BINARY_CACHE_DIR=/app/.prisma (a path under /app
32
- # that gets chowned to user:user later in this file). Both the build
33
- # step and the runtime process use this same env-var, so the binary is
34
- # always found regardless of which uid is active.
35
 
36
  FROM node:20-alpine AS frontend-builder
37
  WORKDIR /build
@@ -47,9 +43,8 @@ FROM python:3.11-slim
47
 
48
  ARG LITELLM_VERSION=1.81.14
49
 
50
- # Point prisma-client-py at a stable, user-writable cache directory.
51
- # This env var must be set before `prisma generate` and must persist into the
52
- # final container so the runtime process finds the binary in the same place.
53
  ENV PRISMA_BINARY_CACHE_DIR=/app/.prisma
54
 
55
  RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -59,16 +54,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
59
  && apt-get purge -y gnupg && apt-get autoremove -y \
60
  && rm -rf /var/lib/apt/lists/*
61
 
62
- # Install LiteLLM and run prisma generate in a single layer (as root, so
63
- # pip can write to system site-packages). The query-engine binary is written
64
- # to $PRISMA_BINARY_CACHE_DIR (/app/.prisma) which is later chowned to
65
- # user:user, making it readable at runtime.
66
- RUN pip install --no-cache-dir "litellm[proxy]==${LITELLM_VERSION}" \
67
  && mkdir -p "${PRISMA_BINARY_CACHE_DIR}" \
68
  && SCHEMA_PATH=$(python3 -c \
69
  "import litellm, os; \
70
  print(os.path.join(os.path.dirname(litellm.__file__), 'proxy', 'schema.prisma'))") \
71
- && echo "Running prisma generate --schema ${SCHEMA_PATH}" \
72
  && prisma generate --schema "${SCHEMA_PATH}"
73
 
74
  RUN useradd -m -u 1000 -s /bin/bash user
 
11
  # [Bug2] build-essential for better-sqlite3 node-gyp fallback
12
  # [Bug3] npm install --omit=dev (--only=production deprecated in npm v10)
13
  # [Bug5] ARG LITELLM_VERSION for single-source versioning
14
+ # [BugP] prisma generate — LiteLLM v1.61+ database_url 存在时会在 FastAPI
15
+ # lifespan 启动阶段初始化 Prisma 客户端,需要 query-engine 二进制文件
16
+ # 预先存在。否则容器立即崩溃:
 
 
17
  # ModuleNotFoundError: No module named 'prisma'
18
  # Exception: Unable to find Prisma binaries.
19
  # Please run 'prisma generate' first.
20
  #
21
+ # 根因分析(三层):
22
+ # 1. litellm[proxy]==1.81.14 的依赖树里 **没有** prisma 包,
23
+ # 必须显式 pip install prisma
24
+ # 2. prisma generate 产生的 query-engine 二进制默认写入
25
+ # ~/.cache/prisma-binaries/(即 root /root/.cache/),
26
+ # 但容器运行时是 uid=1000(user),查找路径是
27
+ # /home/user/.cache/ 完全不同的目录 找不到。
28
+ # 3. 修复:设 PRISMA_BINARY_CACHE_DIR=/app/.prisma(在 /app 下,
29
+ # 后续 chown -R user:user /app 会覆盖到这里),build 阶段和
30
+ # 运行时都读同一个环境变量,路径始终一致。
 
 
31
 
32
  FROM node:20-alpine AS frontend-builder
33
  WORKDIR /build
 
43
 
44
  ARG LITELLM_VERSION=1.81.14
45
 
46
+ # prisma 二进制缓存目录固定到 /app/.prisma,
47
+ # 使 build 阶段(root)和运行时(uid=1000)使用同一路径。
 
48
  ENV PRISMA_BINARY_CACHE_DIR=/app/.prisma
49
 
50
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
54
  && apt-get purge -y gnupg && apt-get autoremove -y \
55
  && rm -rf /var/lib/apt/lists/*
56
 
57
+ # [BugP 修复]
58
+ # litellm[proxy]==1.81.14 的依赖里不含 prisma,需要单独安装。
59
+ # 安装后立即执行 prisma generate,将 query-engine 写入
60
+ # $PRISMA_BINARY_CACHE_DIR(/app/.prisma),后续 chown 会一并处理权限。
61
+ RUN pip install --no-cache-dir "litellm[proxy]==${LITELLM_VERSION}" prisma \
62
  && mkdir -p "${PRISMA_BINARY_CACHE_DIR}" \
63
  && SCHEMA_PATH=$(python3 -c \
64
  "import litellm, os; \
65
  print(os.path.join(os.path.dirname(litellm.__file__), 'proxy', 'schema.prisma'))") \
66
+ && echo "Running: prisma generate --schema ${SCHEMA_PATH}" \
67
  && prisma generate --schema "${SCHEMA_PATH}"
68
 
69
  RUN useradd -m -u 1000 -s /bin/bash user
Dockerfile.huggingface CHANGED
@@ -11,27 +11,23 @@
11
  # [Bug2] build-essential for better-sqlite3 node-gyp fallback
12
  # [Bug3] npm install --omit=dev (--only=production deprecated in npm v10)
13
  # [Bug5] ARG LITELLM_VERSION for single-source versioning
14
- # [BugP] prisma generate — LiteLLM v1.61+ initialises its Prisma client at
15
- # lifespan startup whenever database_url is present in config. The
16
- # prisma-client-py package requires the Prisma query-engine binary to
17
- # exist before the process starts. Without this step the container
18
- # crashes immediately with:
19
  # ModuleNotFoundError: No module named 'prisma'
20
  # Exception: Unable to find Prisma binaries.
21
  # Please run 'prisma generate' first.
22
  #
23
- # IMPORTANT — cache-dir alignment:
24
- # prisma-client-py stores the downloaded query-engine binary in
25
- # PRISMA_BINARY_CACHE_DIR (default: ~/.cache/prisma-binaries/).
26
- # If we run `prisma generate` as root during the build, binaries land
27
- # in /root/.cache/. At runtime the container runs as uid=1000 (user),
28
- # which looks in /home/user/.cache/ — a completely different path, so
29
- # the binary is never found.
30
- #
31
- # Fix: set PRISMA_BINARY_CACHE_DIR=/app/.prisma (a path under /app
32
- # that gets chowned to user:user later in this file). Both the build
33
- # step and the runtime process use this same env-var, so the binary is
34
- # always found regardless of which uid is active.
35
 
36
  FROM node:20-alpine AS frontend-builder
37
  WORKDIR /build
@@ -47,9 +43,8 @@ FROM python:3.11-slim
47
 
48
  ARG LITELLM_VERSION=1.81.14
49
 
50
- # Point prisma-client-py at a stable, user-writable cache directory.
51
- # This env var must be set before `prisma generate` and must persist into the
52
- # final container so the runtime process finds the binary in the same place.
53
  ENV PRISMA_BINARY_CACHE_DIR=/app/.prisma
54
 
55
  RUN apt-get update && apt-get install -y --no-install-recommends \
@@ -59,16 +54,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
59
  && apt-get purge -y gnupg && apt-get autoremove -y \
60
  && rm -rf /var/lib/apt/lists/*
61
 
62
- # Install LiteLLM and run prisma generate in a single layer (as root, so
63
- # pip can write to system site-packages). The query-engine binary is written
64
- # to $PRISMA_BINARY_CACHE_DIR (/app/.prisma) which is later chowned to
65
- # user:user, making it readable at runtime.
66
- RUN pip install --no-cache-dir "litellm[proxy]==${LITELLM_VERSION}" \
67
  && mkdir -p "${PRISMA_BINARY_CACHE_DIR}" \
68
  && SCHEMA_PATH=$(python3 -c \
69
  "import litellm, os; \
70
  print(os.path.join(os.path.dirname(litellm.__file__), 'proxy', 'schema.prisma'))") \
71
- && echo "Running prisma generate --schema ${SCHEMA_PATH}" \
72
  && prisma generate --schema "${SCHEMA_PATH}"
73
 
74
  RUN useradd -m -u 1000 -s /bin/bash user
 
11
  # [Bug2] build-essential for better-sqlite3 node-gyp fallback
12
  # [Bug3] npm install --omit=dev (--only=production deprecated in npm v10)
13
  # [Bug5] ARG LITELLM_VERSION for single-source versioning
14
+ # [BugP] prisma generate — LiteLLM v1.61+ database_url 存在时会在 FastAPI
15
+ # lifespan 启动阶段初始化 Prisma 客户端,需要 query-engine 二进制文件
16
+ # 预先存在。否则容器立即崩溃:
 
 
17
  # ModuleNotFoundError: No module named 'prisma'
18
  # Exception: Unable to find Prisma binaries.
19
  # Please run 'prisma generate' first.
20
  #
21
+ # 根因分析(三层):
22
+ # 1. litellm[proxy]==1.81.14 的依赖树里 **没有** prisma 包,
23
+ # 必须显式 pip install prisma
24
+ # 2. prisma generate 产生的 query-engine 二进制默认写入
25
+ # ~/.cache/prisma-binaries/(即 root /root/.cache/),
26
+ # 但容器运行时是 uid=1000(user),查找路径是
27
+ # /home/user/.cache/ 完全不同的目录 找不到。
28
+ # 3. 修复:设 PRISMA_BINARY_CACHE_DIR=/app/.prisma(在 /app 下,
29
+ # 后续 chown -R user:user /app 会覆盖到这里),build 阶段和
30
+ # 运行时都读同一个环境变量,路径始终一致。
 
 
31
 
32
  FROM node:20-alpine AS frontend-builder
33
  WORKDIR /build
 
43
 
44
  ARG LITELLM_VERSION=1.81.14
45
 
46
+ # prisma 二进制缓存目录固定到 /app/.prisma,
47
+ # 使 build 阶段(root)和运行时(uid=1000)使用同一路径。
 
48
  ENV PRISMA_BINARY_CACHE_DIR=/app/.prisma
49
 
50
  RUN apt-get update && apt-get install -y --no-install-recommends \
 
54
  && apt-get purge -y gnupg && apt-get autoremove -y \
55
  && rm -rf /var/lib/apt/lists/*
56
 
57
+ # [BugP 修复]
58
+ # litellm[proxy]==1.81.14 的依赖里不含 prisma,需要单独安装。
59
+ # 安装后立即执行 prisma generate,将 query-engine 写入
60
+ # $PRISMA_BINARY_CACHE_DIR(/app/.prisma),后续 chown 会一并处理权限。
61
+ RUN pip install --no-cache-dir "litellm[proxy]==${LITELLM_VERSION}" prisma \
62
  && mkdir -p "${PRISMA_BINARY_CACHE_DIR}" \
63
  && SCHEMA_PATH=$(python3 -c \
64
  "import litellm, os; \
65
  print(os.path.join(os.path.dirname(litellm.__file__), 'proxy', 'schema.prisma'))") \
66
+ && echo "Running: prisma generate --schema ${SCHEMA_PATH}" \
67
  && prisma generate --schema "${SCHEMA_PATH}"
68
 
69
  RUN useradd -m -u 1000 -s /bin/bash user