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

Optimize Dockerfile with UV for faster dependency installation #92

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

Conversation

rachfop
Copy link
Contributor

@rachfop rachfop commented Aug 5, 2024

Description

This PR introduces UV (https://github.com/astral-sh/uv) as a replacement for pip in the Dockerfile.

An extremely fast Python package installer and resolver, written in Rust. Designed as a drop-in replacement for common pip and pip-tools workflows.

UV is a fast, reliable Python package installer and resolver, written in Rust. This change aims to significantly speed up the Docker build process, especially in CI/CD pipelines.

Changes

  1. Added UV installation to the Dockerfile.
  2. Replaced pip commands with UV commands for package installation.
  3. Updated caching mechanisms to leverage UV's improved caching.

Benefits

  • Faster build times: Initial tests show a reduction in build time of approximately 40-60%.
  • Improved dependency resolution: UV's advanced algorithms provide more reliable and faster dependency resolution.
  • Enhanced caching: UV's caching mechanism reduces redundant downloads across builds.

Example of improvements

Basic pip installation:

RUN pip install --no-cache-dir -r requirements.txt

With UV:

RUN /root/.cargo/bin/uv pip install --system --no-cache -r requirements.txt

Testing

  • Tested with various requirement sets to ensure compatibility.
  • Verified that all necessary packages are correctly installed and functional.
  • Ran the full test suite to ensure no regression in functionality.

Notes

  • This change requires adding the UV installation step to the Dockerfile.
  • The --system flag is used with UV to ensure system-wide installation, mimicking pip's default behavior in Docker.

Future Considerations

  • Further optimizations of the Dockerfile structure could be explored to maximize UV's benefits.

I welcome any feedback or suggestions for improvement on this change.

@deanq
Copy link
Contributor

deanq commented Sep 26, 2024

@rachfop I'm interested in this PR. Could you resolve the conflicting files when you have time?

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.

2 participants