fix(docker): use multi-stage build to remove build-essential from runtime image#1846
Open
yangzheli wants to merge 3 commits intobytedance:mainfrom
Open
fix(docker): use multi-stage build to remove build-essential from runtime image#1846yangzheli wants to merge 3 commits intobytedance:mainfrom
yangzheli wants to merge 3 commits intobytedance:mainfrom
Conversation
…time image The build-essential toolchain (~200 MB) was only needed for compiling native Python extensions during `uv sync` but remained in the final image, increasing size and attack surface. Split the Dockerfile into a builder stage (with build-essential) and a clean runtime stage that copies only the compiled artifacts, Node.js, Docker CLI, and uv. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the backend Docker image into a multi-stage build so native Python extensions can be compiled in a builder stage while keeping the final runtime image smaller and with fewer build-time tools installed.
Changes:
- Split
backend/Dockerfileintobuilderandruntimestages, compiling Python deps in the builder stage. - Copy only the built backend artifacts/venv plus required tooling (uv, Node.js runtime, Docker CLI) into the runtime stage.
Address Copilot review comments: - Add a `dev` build stage (FROM builder) that retains build-essential so startup-time `uv sync` in dev containers can compile from source - Update docker-compose-dev.yaml to use `target: dev` for gateway and langgraph services - Keep the clean runtime stage (no build-essential) as the default final stage for production builds Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Copilot's suggestion has been adopted in 32e5bde. Please take another look when you have time.@WillemJiang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
part of #1086
Summary
The build-essential toolchain was only needed for compiling native Python extensions during
uv syncbut remained in the final image, increasing size and attack surface. Split the Dockerfile into a builder stage (with build-essential) and a clean runtime stage that copies only the compiled artifacts, Node.js, Docker CLI, and uv.Screenshots