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

Experiment: Use uv+pip to install packages during build #659

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dleviminzi
Copy link
Collaborator

@dleviminzi dleviminzi commented Oct 25, 2024

When building the image for the app below on the main branch (using pip) it currently takes 31 seconds. Building the same image using uv takes 14s. This might be controversial because we are adding a dependency instead of just using the base python tooling. However, the speed up is pretty impressive in my opinion and given the tweak -> build -> tweak -> build nature of users' applications I think the improvement will be felt.

There is also an additional optimization bundled in that could be separated out. I changed the build step command processing so that it resolves all dependencies at once instead of doing a bunch of individual pip installs. However, if somebody had two different add_python_packages, my current implementation of this optimization would break. If we like it, I'll make a more robust version that allows for multiple groups of packages.

from beta9 import endpoint, Image

@endpoint( image=Image()
    .add_commands(
        ["echo 4"] # trigger new builds
    )
    .add_python_packages(
        ["numpy", "pandas", "seaborn", "transformers", "matplotlib", "scipy", "scikit-learn", "opencv-python"]
    ),
    name="slow-build"
)
def handler():
    return "hello"

One other change you might notice is the addition of imageArchitectures in the config. The primary reason I added this was so that we could use arm runner images when developing locally (they are much faster). I added an optional flag to the makefile so that you can decide which architecture to build the runner with.

pkg/abstractions/image/build.go Outdated Show resolved Hide resolved
pkg/abstractions/image/build.go Show resolved Hide resolved
docker/Dockerfile.worker Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
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