li / Dockerfile
xiaolongmr
Improve frontend loading performance
dbfb96e
Raw
History Blame Contribute Delete
1.66 kB
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 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 services ./services
COPY utils ./utils
COPY scripts ./scripts
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
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--access-log"]