Skip to content

Commit c4f4df1

Browse files
authored
Migrate to using uv in Docker (#88)
* Commit uv lockfile * Update docker configuration to use Python uv Using uv is a bit more complicated for the commands, and this removes some layer caching, but it makes it much easier to work out how to run local commands that match production. * Remove unused requirements.txt file This is replaced by uv.lock * Try installing uv into CI image
1 parent da3ce6a commit c4f4df1

6 files changed

Lines changed: 1250 additions & 211 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/node_modules
2+
**/.venv
23
**/.tox
34
**/.coverage
45
**/*.egg-info

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414

15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v7
17+
1518
- name: Set up Python 3.12
1619
uses: actions/setup-python@v5
1720
with:
1821
python-version: "3.12"
1922

2023
- name: Install tox
21-
run: pip install tox
24+
run: uv tool install tox
2225

2326
- name: Run tests
24-
run: tox
27+
run: uv run --extra=dev tox
2528
env:
2629
TOXENV: py312
2730

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ server/logs/
1818
src/WebCompatManager.egg-info/
1919
build/
2020
dist/
21-
uv.lock
2221

2322
# Code coverage
2423
.coverage*

Dockerfile

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,29 @@ WORKDIR /src
88
RUN npm install
99
RUN npm run production
1010

11-
FROM python:3.12-alpine AS backend
11+
FROM ghcr.io/astral-sh/uv:python3.12-alpine AS backend
1212

13-
RUN apk add --no-cache build-base git mariadb-dev && pip install tomli
14-
15-
# Install dependencies before copying src, so pip is only run when needed
16-
# Also install build dependencies that are otherwise missed in wheel cache
17-
# (from pyproject.toml [build-system].requires)
18-
COPY ./requirements.txt ./pyproject.toml /src/
19-
RUN cd /src && \
20-
python -c "import tomli; from itertools import chain; pyp=tomli.load(open('pyproject.toml','rb')); deps=pyp['project']['dependencies']; extras=pyp['project']['optional-dependencies']; print('\0'.join(chain(deps, extras['docker'], extras['server'])))" | xargs -0 pip wheel -q -c requirements.txt --wheel-dir /var/cache/wheels && \
21-
pip wheel -q --wheel-dir /var/cache/wheels wheel setuptools_scm[toml]
22-
23-
FROM python:3.12-alpine
13+
RUN apk add --no-cache build-base git mariadb-dev
2414

2515
RUN adduser -D worker && \
2616
apk add --no-cache bash git mariadb-client mariadb-connector-c openssh-client-default && \
27-
pip install tomli && \
2817
rm -rf /var/log/*
2918

30-
COPY --from=backend /var/cache/wheels /var/cache/wheels
31-
32-
COPY ./requirements.txt ./pyproject.toml /src/
33-
USER worker
34-
RUN cd /src && \
35-
python -c "import tomli; from itertools import chain; pyp=tomli.load(open('pyproject.toml','rb')); deps=pyp['project']['dependencies']; extras=pyp['project']['optional-dependencies']; print('\0'.join(chain(deps, extras['docker'], extras['server'])))" | xargs -0 pip install --no-cache-dir --no-index --find-links /var/cache/wheels -q -c requirements.txt
36-
37-
# Embed full source code
38-
USER root
3919
COPY . /src/
20+
RUN cd /src && uv sync --locked --extra=server --extra=docker
4021

4122
# Retrieve previous Javascript build
4223
COPY --from=frontend /src/dist/ /src/server/frontend/dist/
43-
RUN mkdir -p /data/fuzzing-tc-config && chown -R worker:worker /src /data/fuzzing-tc-config
44-
45-
# Install FM
46-
# Note: the extras must be duplicated above in the Python
47-
# script to pre-install dependencies.
48-
USER worker
49-
ENV PATH="${PATH}:/home/worker/.local/bin"
50-
RUN pip install --no-cache-dir --no-index --find-links /var/cache/wheels --no-deps -q /src[docker,server]
5124

5225
# Use a custom settings file that can be overwritten
5326
ENV DJANGO_SETTINGS_MODULE="server.settings_docker"
5427

5528
WORKDIR /src/server
5629

5730
# Collect staticfiles, including Vue.js build
58-
RUN python manage.py collectstatic --no-input
31+
RUN uv run --extra=server --extra=docker manage.py collectstatic --no-input
5932

6033
# Run with gunicorn, using container's port 80
6134
ENV PORT=80
6235
EXPOSE 80
63-
CMD ["gunicorn", "--bind", "0.0.0.0:80", "--error-logfile", "-", "--access-logfile", "-", "--capture-output", "server.wsgi"]
36+
CMD ["uv", "run", "--extra", "server", "--extra", "docker", "gunicorn", "--bind", "0.0.0.0:80", "--error-logfile", "-", "--access-logfile", "-", "--capture-output", "server.wsgi"]

requirements.txt

Lines changed: 0 additions & 176 deletions
This file was deleted.

0 commit comments

Comments
 (0)