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

Try using uv for worker #896

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Build Docker container image with wheels
Instead of using `uv` virtualenv to build the image, we want to build the wheels
so that the docker app won't need to have dependency on build tools.
  • Loading branch information
michelletran-codecov committed Nov 19, 2024
commit 9c0bcc88ca709a3511c587f23acb4e7d4193b956
30 changes: 24 additions & 6 deletions docker/Dockerfile.requirements
Original file line number Diff line number Diff line change
@@ -25,14 +25,28 @@ ENV UV_LINK_MODE=copy \
UV_PYTHON=python \
UV_PROJECT_ENVIRONMENT=/worker

# Change the working directory to the `worker` directory
WORKDIR /worker
# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen

# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project
uv export --no-hashes --frozen --format requirements-txt > requirements.txt

RUN grep -v '^-e ' requirements.txt > requirements.remote.txt

# build all remote wheels
RUN pip wheel -w wheels --find-links wheels -r requirements.remote.txt

# build all local packages to wheels
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv build --all-packages --wheel -o wheels


# RUNTIME STAGE - Copy packages from build stage and install runtime dependencies
@@ -45,8 +59,12 @@ RUN apt-get install -y \
libxslt-dev \
make

WORKDIR /worker
COPY --from=build /worker /worker
COPY --from=build /wheels/ /wheels/

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv pip install --no-deps --no-index --find-links=wheels wheels/* --system

RUN addgroup --system application \
&& adduser --system codecov --ingroup application --home /home/codecov
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -34,6 +34,13 @@ dependencies = [
"zstandard>=0.23.0",
]

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
py-modules = []

[tool.uv]
dev-dependencies = [
"factory-boy>=3.3.1",