This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathDockerfile.requirements
More file actions
57 lines (45 loc) · 1.79 KB
/
Dockerfile.requirements
File metadata and controls
57 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# syntax=docker/dockerfile:1.4
ARG PYTHON_IMAGE=ghcr.io/astral-sh/uv:python3.12-bookworm-slim
# BUILD STAGE - Download dependencies from GitHub that require SSH access
FROM $PYTHON_IMAGE as build
RUN apt-get update
RUN apt-get install -y \
curl \
git \
build-essential \
libffi-dev \
libpq-dev
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python \
UV_PROJECT_ENVIRONMENT=/api
# 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 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
FROM $PYTHON_IMAGE
# Our postgres driver psycopg2 requires libpq-dev as a runtime dependency
RUN apt-get update
RUN apt-get install -y \
git \
libpq-dev \
make \
curl \
libexpat1
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