File size: 2,272 Bytes
bd4057b
 
 
 
 
 
 
 
 
 
 
 
d76c588
bd4057b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6563b83
bd4057b
 
 
34f333f
bd4057b
dbfb96e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd4057b
 
 
d12cef2
 
 
d188720
 
d12cef2
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETARCH

FROM --platform=$BUILDPLATFORM node:22-alpine AS web-build

WORKDIR /app/web

COPY web/package.json web/bun.lock ./
RUN npm install

COPY VERSION /app/VERSION
COPY CHANGELOG.md /app/CHANGELOG.md
COPY web ./
RUN NEXT_PUBLIC_APP_VERSION="$(cat /app/VERSION)" npm run build


FROM --platform=$TARGETPLATFORM python:3.13-slim AS app

ARG TARGETPLATFORM
ARG TARGETARCH

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    UV_LINK_MODE=copy

WORKDIR /app

# 安装系统依赖
# - git: Git 存储后端需要
# - libpq-dev: PostgreSQL 客户端库
# - gcc: 编译 psycopg2-binary 需要
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    libpq-dev \
    gcc \
    openssl \
    && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir uv

COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project

COPY main.py ./
COPY VERSION ./
COPY api ./api
COPY assets ./assets
COPY services ./services
COPY utils ./utils
COPY scripts ./scripts
COPY bundled_skills ./bundled_skills
COPY --from=web-build /app/web/out ./web_dist
RUN python - <<'PY'
from __future__ import annotations

import gzip
from pathlib import Path

root = Path("web_dist")
suffixes = {".css", ".html", ".js", ".json", ".map", ".svg", ".txt", ".xml"}
for path in root.rglob("*"):
    if not path.is_file() or path.suffix.lower() not in suffixes or path.stat().st_size < 1024:
        continue
    gz_path = path.with_name(f"{path.name}.gz")
    with path.open("rb") as source, gzip.open(gz_path, "wb", compresslevel=9) as target:
        target.writelines(source)
PY

EXPOSE 7860

# ⚠️ 必须显式写 --no-access-log:uvicorn 的 access log **默认就是开的**,
# `--access-log` 只是把默认值写出来,删掉它等于没改(实测线上照旧 285 KB/s、1800 行/秒)。
# 容器只有 2 个共享 vCPU,每条请求都多一次格式化 + write 系统调用,且日志会被 HF 全量流出去。
# 注意 main.py 末尾的 uvicorn.run(access_log=False) 在线上**不会执行**(这里是 CLI 启动),
# 所以只改 main.py 无效,必须在这里保持一致。
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--no-access-log"]