Skip to content

Commit

Permalink
Use uv to install packages in Docker
Browse files Browse the repository at this point in the history
In order to do this we need to install uv inside the Docker container.
We don't want it being installed in the venv that we use for production.
So we need to do this as a separate step.

Part of the reason uv is faster is because it uses a cache of packages.
By default it uses `$HOME/.cache/uv` as the location for this cache
(even if you use --no-cache, it makes a temp folder in there)[^1].

Our docker image doesn't have permission to write there, so we override
the default and set the cache to be in /tmp/ instead

[^1] https://docs.astral.sh/uv/concepts/cache/#cache-directory
  • Loading branch information
quis committed Dec 11, 2024
1 parent 165c8d3 commit bd9430a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM python:3.11-slim-bookworm as base
ENV CLAMAV_MIRROR_URL https://s3.eu-west-1.amazonaws.com/notifications.service.gov.uk-clamav-database-mirror/clam
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
ENV UV_CACHE_DIR='/tmp/uv-cache/'


# Use clamav database from private mirror. Disable with: --build-arg CLAMAV_USE_MIRROR=false for local builds
ARG CLAMAV_USE_MIRROR=true
Expand Down Expand Up @@ -52,9 +54,11 @@ RUN echo "Install OS dependencies for python app requirements" && \

COPY requirements.txt .

RUN pip install uv

RUN echo "Installing python requirements" && \
python3 -m venv /opt/venv && \
/opt/venv/bin/pip install -r requirements.txt
uv pip sync --python /opt/venv/bin/python requirements.txt

COPY . .
RUN make generate-version-file # This file gets copied across
Expand Down Expand Up @@ -100,6 +104,7 @@ USER notify
RUN mkdir -p app

# Install dev/test requirements
RUN pip install uv
COPY --chown=notify:notify requirements_for_test.txt ./
RUN make bootstrap

Expand Down

0 comments on commit bd9430a

Please sign in to comment.