Skip to content

Commit 3f73a08

Browse files
committed
chore: update Dockerfile and dependencies for improved build process
1 parent 9c2cf95 commit 3f73a08

File tree

4 files changed

+382
-18
lines changed

4 files changed

+382
-18
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
.*
44

55
# Allow certain files and folders
6+
!uv.lock
7+
!pyproject.toml
68
!requirements.txt
79
!functions
810
!tests

Dockerfile

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,62 @@
1-
# Use an official Python runtime as a parent image
2-
FROM python:3.11-slim
1+
# --- Builder Stage ---
2+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
3+
34
# Keeps Python from generating .pyc files in the container
45
ENV PYTHONDONTWRITEBYTECODE=1
56

67
# Turns off buffering for easier container logging
78
ENV PYTHONUNBUFFERED=1
89

10+
# Enable bytecode compilation
11+
ENV UV_COMPILE_BYTECODE=1
12+
13+
# Copy from the cache instead of linking since it's a mounted volume
14+
ENV UV_LINK_MODE=copy
15+
16+
# Disable Python downloads, because we want to use the system interpreter
17+
# across both images. If using a managed Python version, it needs to be
18+
# copied from the build image into the final image; see `standalone.Dockerfile`
19+
# for an example.
20+
ENV UV_PYTHON_DOWNLOADS=0
21+
922
# Install system requirements
1023
# gcc for C compilation
1124
RUN apt-get -qq update && apt-get install -y gcc g++
12-
RUN apt-get -qq update && apt-get install -y git curl pipx
25+
# git for version control
26+
RUN apt-get -qq update && apt-get install -y git curl
27+
1328

1429
# Get Rust
1530
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
1631
ENV PATH="${PATH}:/root/.cargo/bin"
1732

18-
# # Set the working directory to /app
19-
WORKDIR /app
33+
# Install the project's dependencies using the lockfile and settings
34+
# TODO: Add comments on mount types and why we use them
35+
RUN --mount=type=cache,target=/root/.cache/uv \
36+
--mount=type=bind,source=uv.lock,target=uv.lock \
37+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
38+
uv sync --locked --no-install-project --no-editable
2039

21-
# Install any needed packages specified in requirements.txt
22-
RUN pip install -q -U pip setuptools setuptools_rust wheel
23-
COPY requirements.txt /app
24-
RUN pip install -q --no-cache-dir -U -r requirements.txt
2540

26-
# # Copy the current directory contents into the container at /app (except .dockerignore)
41+
# Copy the project into the intermediate image
2742
COPY . /app
2843

44+
# Sync the project
45+
RUN --mount=type=cache,target=/root/.cache/uv \
46+
--mount=type=bind,source=uv.lock,target=uv.lock \
47+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
48+
uv sync --locked --no-editable
49+
50+
# --- Final Stage ---
51+
# This stage builds the final, lean image
52+
FROM python:3.12-slim
53+
54+
# Copy the environment, but not the source code
55+
COPY --from=builder --chown=app:app /app /app
56+
57+
# Make sure the environment is in the PATH
58+
ENV PATH="/app/.venv/bin:$PATH"
59+
2960
WORKDIR /app/examples
3061

3162
# Run rpc_client.py when the container launches

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ dependencies = [
2626
river = { git = "https://github.com/MarekWadinger/river.git" }
2727

2828
[dependency-groups]
29+
build = [
30+
"setuptools>=80.9.0",
31+
"setuptools-rust>=1.12.0",
32+
"wheel>=0.45.1",
33+
]
2934
dev = [
3035
"flake8>=7.3.0",
3136
"flake8-html>=0.4.3",

0 commit comments

Comments
 (0)