Skip to content

Commit eb09732

Browse files
committed
chore: Use uv to install python packages in containers in Docker Compose setup
1 parent edf20b3 commit eb09732

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
FROM postgres
22

3-
# Install git
3+
# Install python
44
RUN apt-get update && \
5-
apt-get install -y python3 python3-venv && \
5+
apt-get install -y python3 && \
66
apt-get clean && \
77
rm -rf /var/lib/apt/lists/*
88

9+
# Install uv
10+
COPY --from=ghcr.io/astral-sh/uv:0.9.3 /uv /uvx /bin/
11+
912
WORKDIR /app
1013

11-
# Copy necessary files and folders
14+
# Install python dependencies, only copying necessary files
1215
COPY ./pyproject.toml MANIFEST.in ./
13-
COPY ./grader_service ./grader_service
14-
# Create a virtual environment
15-
RUN python3 -m venv /venv
16+
RUN --mount=type=cache,target=/root/.cache/uv \
17+
uv sync --no-dev
1618

17-
# Activate venv and install the package
18-
RUN /venv/bin/pip install .
19+
# Copy the project files and install the package itself
20+
COPY ./grader_service ./grader_service
21+
RUN --mount=type=cache,target=/root/.cache/uv \
22+
uv pip install .
1923

2024
CMD ["sh", "-c", "/app/init-db-postgres.sh"]

examples/docker_compose/Dockerfile-Hub

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ WORKDIR /app
1010

1111
ENV JUPYTERHUB_CRYPT_KEY=e3f92a0d5e37446c7e894a2ef6c6ec3bcb4aa3c38d2a442eb567adf780597aa0
1212

13-
RUN pip install grader_labextension
14-
13+
RUN python3 -m pip install grader_labextension
1514
RUN python3 -m pip install dockerspawner oauthenticator
1615

1716
CMD ["jupyterhub", "-f", "/app/jupyterhub_config.py"]

examples/docker_compose/Dockerfile-Service

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
FROM python:3.13-slim
22

3-
# Install git
3+
# Install git and sqlite
44
RUN apt-get update && \
55
apt-get install -y git sqlite3 && \
66
apt-get clean && \
77
rm -rf /var/lib/apt/lists/*
88

9+
# Install uv
10+
COPY --from=ghcr.io/astral-sh/uv:0.9.3 /uv /uvx /bin/
11+
ENV UV_SYSTEM_PYTHON=true
12+
913
WORKDIR /app
1014

11-
# Copy necessary files and folders
15+
# Install python dependencies, only copying necessary files
1216
COPY ./pyproject.toml MANIFEST.in ./
13-
COPY ./grader_service ./grader_service
17+
RUN uv pip compile pyproject.toml -o requirements.txt
18+
RUN --mount=type=cache,target=/root/.cache/uv \
19+
uv pip install -r requirements.txt && \
20+
uv pip install numpy ipykernel
1421

15-
RUN pip install .
16-
RUN pip install numpy ipykernel
22+
# Copy the project files and install the package itself
23+
COPY ./grader_service ./grader_service
24+
RUN --mount=type=cache,target=/root/.cache/uv \
25+
uv pip install .
1726

1827
# Set default branch to main and default user
1928
RUN git config --global init.defaultBranch main && \

0 commit comments

Comments
 (0)