Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 2.5x faster docker build with uv #2532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

banteg
Copy link
Contributor

@banteg banteg commented Feb 26, 2025

Summary

  • Add a new Dockerfile.uv using the faster uv package manager
  • Improve .dockerignore to significantly reduce build context size
  • Optimize the Docker build process for improved performance

Performance Analysis

This PR introduces a Docker build optimization using the uv package manager and an improved .dockerignore file. The changes are presented for the consideration of Ape maintainers and are not yet integrated into any CI or build pipelines.

Build Times Comparison

  • Standard Docker build (slim): 111.74 seconds
  • UV Docker build: 44.86 seconds
  • Speed Improvement: 2.49x faster with UV

Detailed Step Analysis

  1. Build Context Transfer:

    • Standard: transferring context: 2.34GB 11.8s
    • UV: transferring context: 2.85MB 0.0s
    • Key Finding: The .dockerignore file reduced the build context from 2.34GB to just 2.85MB (822x smaller!)
  2. File Copying Times:

    • Standard: COPY . . - DONE 13.3s
    • UV: COPY . . - DONE 0.1s
    • Key Finding: Copying files is 133x faster with the optimized .dockerignore
  3. Package Build/Install:

    • Standard: RUN pip wheel . - DONE 50.1s
    • UV: RUN uv build --wheel . - DONE 4.5s
    • Key Finding: UV's package building is ~11x faster than pip
  4. Image Size:

    • Standard: 525MB
    • UV: 698MB
    • Note: The UV image is slightly larger due to additional development dependencies

Key Performance Factors

  1. Build Context Optimization:

    • The .dockerignore file provides enormous benefits by excluding the .git directory (1.5GB) and other unnecessary files.
    • This dramatically reduces the time spent transferring files to the Docker daemon.
  2. UV Performance:

    • UV's package building is significantly faster than pip, reducing the wheel creation time by ~45 seconds.
    • UV's dependency resolution and installation is more efficient.
  3. Build Process Structure:

    • The simplified build process in the UV Dockerfile has fewer steps and more efficient resource usage.

Test plan

  • The Docker build completes successfully
  • The resulting image functions correctly
  • Build performance is significantly improved

🤖 Generated with Claude Code

- Add new Dockerfile.uv using the faster uv package manager
- Improve .dockerignore to reduce build context size
- Build is 2.5x faster and has better caching properties
- Final image size is slightly larger (698MB vs 525MB)

🤖 Generated with Claude Code
Co-Authored-By: Claude <[email protected]>
COPY --from=builder /build/dist/*.whl /wheels/

# Install the wheels with uv (using --system since we're in a Docker container)
RUN uv pip install --system /wheels/*.whl
Copy link
Member

Choose a reason for hiding this comment

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

Can it not do --system? I am not sure of the security implications of this, if it overrides any system installations that could expose an attack surface inside the container

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think that's how you are supposed to install things in docker

@banteg
Copy link
Contributor Author

banteg commented Feb 26, 2025

noticed this inside the container, caused by setuptools-scm

- slim: eth-ape 0.8.29.dev0+g4d2d1fd54.d20250226
- uv: eth-ape 0.8.999

Copy link
Member

@antazoey antazoey left a comment

Choose a reason for hiding this comment

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

USER harambe

# Set entrypoint
ENTRYPOINT ["ape"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ENTRYPOINT ["ape"]
ENTRYPOINT ["ape"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants