22# Shared build ARGs among stages
33ARG WORKDIR=/app
44ARG VENV="$WORKDIR/.venv"
5+ ARG UV_VERSION=0.5.16
6+
7+ # ## Distroless uv version layer to be copied from (because COPY --from does not interpolate variables)
8+ FROM ghcr.io/astral-sh/uv:$UV_VERSION AS uv
59
610# ## --- Build Depdendencies ---
711FROM python:3.12 AS builder
@@ -23,36 +27,33 @@ RUN set -eux ;\
2327 apt-get install -y --no-install-recommends build-essential libpcre3 libpcre3-dev git ;\
2428 rm -rf /var/lib/apt/lists/*
2529
26- # Create virtual env to store dependencies, "activate" it
27- RUN python -m venv --upgrade-deps "$VENV"
28- ENV VIRTUAL_ENV="$VENV" PATH="$VENV/bin:$PATH"
30+ # Install uv to replace pip & friends
31+ COPY --from=uv /uv /uvx /bin/
2932
30- # Set a couple pip -related settings
33+ # Set a couple uv -related settings
3134# Wait a bit longer for slow connections
32- ENV PIP_TIMEOUT=100
33- # Don't nag about newer pip
34- ENV PIP_DISABLE_PIP_VERSION_CHECK=1
35- # Don't cache pip packages
36- ENV PIP_NO_CACHE_DIR=1
37- # Require activated virtual environment
38- ENV PIP_REQUIRE_VIRTUALENV=1
39- # Eventual python cache files go here (not to be copied)
40- ENV PYTHONPYCACHEPREFIX=/tmp/__pycache__
35+ ENV UV_HTTP_TIMEOUT=100
36+ # Don't cache packages
37+ ENV UV_NO_CACHE=1
38+
39+ # Create virtual env to store dependencies, "activate" it
40+ RUN uv venv "$VENV"
41+ ENV VIRTUAL_ENV="$VENV" PATH="$VENV/bin:$PATH"
4142
4243# Install runtime dependencies
4344RUN --mount=target=/build-ctx \
44- pip install -r /build-ctx/requirements/main.txt
45- RUN pip install uwsgi==$UWSGI_VERSION
45+ uv pip install -r /build-ctx/requirements/main.txt
46+ RUN uv pip install uwsgi==$UWSGI_VERSION
4647# Install extra packages into the virtual env
47- RUN pip install ${EXTRA_PACKAGES}
48+ RUN uv pip install ${EXTRA_PACKAGES}
4849
4950# Copy project contents necessary for an editable install
5051COPY .git .git/
5152COPY giftless giftless/
5253COPY pyproject.toml .
5354# Editable-install the giftless package (add a kind of a project path reference in site-packages)
5455# To detect the package version dynamically, setuptools-scm needs the git binary
55- RUN pip install -e .
56+ RUN uv pip install -e .
5657
5758# ## --- Build Final Image ---
5859FROM python:3.12-slim AS final
0 commit comments