From e5cbc593f44ccc790940f072a74fd91c5c83debc Mon Sep 17 00:00:00 2001 From: yangdx Date: Tue, 14 Oct 2025 15:02:58 +0800 Subject: [PATCH] Optimize Docker build with multi-stage frontend compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Add frontend build stage to Dockerfile • Remove --production flag from bun install • Fix frontend asset integration --- .github/workflows/pypi-publish.yml | 2 +- Dockerfile | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 6ea4ec07..14c2bcc5 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -26,7 +26,7 @@ jobs: - name: Build Frontend WebUI run: | cd lightrag_webui - bun install --frozen-lockfile --production + bun install --frozen-lockfile bun run build cd .. diff --git a/Dockerfile b/Dockerfile index e25b4f99..89b09d81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,17 @@ -# Build stage +# Frontend build stage +FROM oven/bun:1 AS frontend-builder + +WORKDIR /app + +# Copy frontend source code +COPY lightrag_webui/ ./lightrag_webui/ + +# Build frontend +RUN cd lightrag_webui && \ + bun install --frozen-lockfile && \ + bun run build + +# Python build stage FROM python:3.12-slim AS builder WORKDIR /app @@ -20,6 +33,9 @@ COPY pyproject.toml . COPY setup.py . COPY lightrag/ ./lightrag/ +# Copy frontend build output from frontend-builder stage +COPY --from=frontend-builder /app/lightrag/api/webui ./lightrag/api/webui + # Install dependencies ENV PATH="/root/.cargo/bin:${PATH}" RUN pip install --user --no-cache-dir --use-pep517 . @@ -42,7 +58,7 @@ RUN pip install --upgrade pip setuptools wheel # Copy only necessary files from builder COPY --from=builder /root/.local /root/.local -COPY ./lightrag ./lightrag +COPY --from=builder /app/lightrag ./lightrag COPY setup.py . RUN pip install --use-pep517 ".[api]"