Skip to content

Enhancement: slim Docker image, add .dockerignore, fix Go binary shipping - #15880

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
6ba3i:chore/optimize_build
Jun 10, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
6ba3i:chore/optimize_build

Conversation

@6ba3i

@6ba3i 6ba3i commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

The RAGFlow Docker image was 9.06 GB with build-only compiler packages leaking into the runtime, duplicate frontend source shipped alongside compiled assets, and no .dockerignore causing ~6 GB of unnecessary context transfer per build.

Type of change

  • Performance Improvement

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5285d55c-37ea-433d-bc82-f0293099edca

📥 Commits

Reviewing files that changed from the base of the PR and between 74bb040 and 1a1fe15.

📒 Files selected for processing (1)
  • .dockerignore
💤 Files with no reviewable changes (1)
  • .dockerignore

📝 Walkthrough

Walkthrough

This PR reduces Docker build context with a new .dockerignore, splits runtime vs build dependencies between base and builder stages, adds apt cache cleanup in multiple install steps, stages frontend npm install for better layer caching, and removes copying the raw web directory in production.

Changes

Docker Image Optimization

Layer / File(s) Summary
Build context exclusion
.dockerignore
.dockerignore rules exclude Python/Node build artifacts, logs, runtime data, C/C++ build outputs, dependency caches, IDE settings, test coverage artifacts, and docker/.env.
Base stage: runtime-only dependencies and apt cleanup
Dockerfile (lines 46–47, 66–67, 96–97, 113–114)
Base stage removes build-tooling and compilation prerequisites, keeping only runtime/OS packages. Apt package lists are cleared after NGINX, Node.js, and ODBC driver installation to reduce layer size.
Builder stage: Python compilation dependencies
Dockerfile (lines 143–149)
Builder stage explicitly installs build-only dependencies for compiling Python C extensions, since they are removed from base. Apt lists are cleaned afterward.
Frontend build caching: staged npm install
Dockerfile (lines 166–176)
Frontend manifests (package.json, package-lock.json, .npmrc) are copied first to run npm install, then full sources are copied and the production build runs with Vite, improving cache reuse on source-only changes.
Production stage: remove raw web directory
Dockerfile (lines 197–198)
Production stage no longer copies the raw web directory from the build context, relying on compiled assets from the builder output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Docker crumbs swept from the tray,
Base grows lean to race the day,
Manifests first, then builds that sing,
Secrets kept, and layers spring,
A sprightly image — hop, deploy! 🎋

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: slimming the Docker image, adding .dockerignore, and fixing Go binary shipping.
Description check ✅ Passed The description addresses the required template sections, explaining the problem solved and identifying the change type as a Performance Improvement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@6ba3i 6ba3i added the ci Continue Integration label Jun 10, 2026
@6ba3i
6ba3i marked this pull request as draft June 10, 2026 02:27
@6ba3i
6ba3i marked this pull request as ready for review June 10, 2026 02:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
Dockerfile (2)

46-47: ⚡ Quick win

Runtime base still includes build/development packages.

Line 46 keeps pkg-config and libjemalloc-dev in base, which weakens the runtime-only split and adds image weight. Move build tooling to builder, and keep only runtime jemalloc libraries in base.

Proposed diff
-    apt install -y \
-    libglib2.0-0 libglx-mesa0 libgl1 pkg-config libgdiplus default-jdk libatk-bridge2.0-0 libgtk-4-1 libnss3 xdg-utils libjemalloc-dev gnupg unzip curl wget git vim less ghostscript pandoc texlive texlive-latex-extra texlive-xetex texlive-lang-chinese fonts-freefont-ttf fonts-noto-cjk postgresql-client && \
+    apt install -y \
+    libglib2.0-0 libglx-mesa0 libgl1 libgdiplus default-jdk libatk-bridge2.0-0 libgtk-4-1 libnss3 xdg-utils libjemalloc2 gnupg unzip curl wget git vim less ghostscript pandoc texlive texlive-latex-extra texlive-xetex texlive-lang-chinese fonts-freefont-ttf fonts-noto-cjk postgresql-client && \
@@
-    apt install -y build-essential libpython3-dev libicu-dev libgbm-dev && \
+    apt install -y build-essential pkg-config libpython3-dev libicu-dev libgbm-dev && \

Also applies to: 145-148

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Dockerfile` around lines 46 - 47, The runtime image still installs build-time
packages pkg-config and libjemalloc-dev; remove pkg-config and libjemalloc-dev
from the runtime/base stage and install them only in the builder stage instead,
while keeping the runtime jemalloc library (e.g., libjemalloc2 or the
distro-specific non-dev jemalloc package) in base; update the builder stage
package list to include pkg-config and libjemalloc-dev (and any other build
tools needed) and remove dev packages from the runtime install lines referenced;
ensure you also mirror this change for the later duplicate block (the other
runtime install group) so only runtime libraries remain in base and all build
tooling lives in builder.

169-170: ⚡ Quick win

Use npm ci for lockfile-based Docker builds.

Line 170 uses npm install even though package-lock.json is copied. npm ci is typically faster and more deterministic for this layer.

Proposed diff
 RUN --mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked \
-    cd web && NODE_OPTIONS="--max-old-space-size=8192" npm install
+    cd web && NODE_OPTIONS="--max-old-space-size=8192" npm ci
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Dockerfile` around lines 169 - 170, The Dockerfile layer currently runs "npm
install" in the web directory (the RUN line invoking cd web &&
NODE_OPTIONS="--max-old-space-size=8192" npm install) but should use
lockfile-based install for reproducible builds; change the command to use "npm
ci" instead while keeping the build cache mount
(--mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked) and the
NODE_OPTIONS env so the layer runs cd web &&
NODE_OPTIONS="--max-old-space-size=8192" npm ci.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Dockerfile`:
- Around line 46-47: The runtime image still installs build-time packages
pkg-config and libjemalloc-dev; remove pkg-config and libjemalloc-dev from the
runtime/base stage and install them only in the builder stage instead, while
keeping the runtime jemalloc library (e.g., libjemalloc2 or the distro-specific
non-dev jemalloc package) in base; update the builder stage package list to
include pkg-config and libjemalloc-dev (and any other build tools needed) and
remove dev packages from the runtime install lines referenced; ensure you also
mirror this change for the later duplicate block (the other runtime install
group) so only runtime libraries remain in base and all build tooling lives in
builder.
- Around line 169-170: The Dockerfile layer currently runs "npm install" in the
web directory (the RUN line invoking cd web &&
NODE_OPTIONS="--max-old-space-size=8192" npm install) but should use
lockfile-based install for reproducible builds; change the command to use "npm
ci" instead while keeping the build cache mount
(--mount=type=cache,id=ragflow_npm,target=/root/.npm,sharing=locked) and the
NODE_OPTIONS env so the layer runs cd web &&
NODE_OPTIONS="--max-old-space-size=8192" npm ci.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b841b961-2bc6-4dd5-b01b-a9ee2ddd1e1f

📥 Commits

Reviewing files that changed from the base of the PR and between 9d9c2dc and 74bb040.

📒 Files selected for processing (2)
  • .dockerignore
  • Dockerfile

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (d56aeb2) to head (1a1fe15).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15880   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 7f4bf69 into infiniflow:main Jun 10, 2026
1 check passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 14, 2026
@6ba3i
6ba3i deleted the chore/optimize_build branch September 22, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants