Skip to content

Commit 77ee5e8

Browse files
committed
feat: slim docker image and uv toolchain
1 parent f92288b commit 77ee5e8

22 files changed

Lines changed: 451 additions & 3363 deletions

.dockerignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.venv/
2+
.pytest_cache/
3+
.mypy_cache/
4+
__pycache__/
5+
*.pyc
6+
*.pyo
7+
*.pyd
8+
9+
.git/
10+
.github/
11+
12+
tests/
13+
docs/
14+
redis/
15+
verifiers/
16+
17+
*.log
18+
attestation_sdk.log
19+
verifier.log
20+
poetry.lock
21+
pyproject.toml

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
tags-ignore: ["v*"]
7+
pull_request:
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.12"
20+
21+
- name: Set up uv
22+
uses: astral-sh/setup-uv@v4
23+
with:
24+
enable-cache: true
25+
26+
- name: Install dependencies
27+
run: |
28+
UV_NO_MANAGED_PYTHON=1 UV_PYTHON_DOWNLOADS=never uv venv -p python
29+
uv pip install --python .venv/bin/python -r requirements.txt -r test-requirements.txt
30+
31+
- name: Run tests
32+
run: ./run_tests.sh

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ A proxy for vLLM.
1010
## Run for development
1111

1212
```bash
13-
# Run production server
14-
uvicorn main:app --host 0.0.0.0 --reload
13+
# Run with Uvicorn
14+
PYTHONPATH=src uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
1515

16-
# Run development server
17-
fastapi dev main.py --host 0.0.0.0
16+
# Or run via the local runner (uses the project logging config)
17+
PYTHONPATH=src python src/run.py
18+
19+
# FastAPI dev server (optional)
20+
PYTHONPATH=src fastapi dev src/app/main.py --host 0.0.0.0 --port 8000
1821
```
1922

2023

@@ -23,7 +26,11 @@ fastapi dev main.py --host 0.0.0.0
2326
### Build for production
2427

2528
```bash
26-
bash docker/build.sh
29+
# Minimal image (recommended)
30+
bash docker/build.sh vllm-proxy:latest runtime
31+
32+
# Includes nv-ppcie-verifier in an isolated venv for GPU evidence collection
33+
bash docker/build.sh vllm-proxy:gpu runtime-gpu
2734
```
2835

2936
### Run for production
@@ -33,15 +40,24 @@ cd docker
3340
docker compose up -d
3441
```
3542

43+
### GPU evidence collection
44+
45+
The minimal image does not include `nv-ppcie-verifier` (it conflicts with the main app dependencies). Use the `runtime-gpu` image, or provide a separate Python environment and set `GPU_EVIDENCE_PYTHON` to its interpreter:
46+
47+
```bash
48+
UV_NO_MANAGED_PYTHON=1 UV_PYTHON_DOWNLOADS=never uv venv .venv-ppcie -p python3
49+
uv pip install --python .venv-ppcie/bin/python -r requirements-gpu.txt
50+
export GPU_EVIDENCE_PYTHON="$PWD/.venv-ppcie/bin/python"
51+
```
52+
3653
## Tests
3754

3855
### Quick Start
3956

4057
```bash
41-
python3 -m venv .venv
42-
. .venv/bin/activate
43-
pip install -r requirements.txt
44-
pip install -r test-requirements.txt
58+
# Preferred: uv
59+
UV_NO_MANAGED_PYTHON=1 UV_PYTHON_DOWNLOADS=never uv venv -p python3
60+
uv pip install --python .venv/bin/python -r requirements.txt -r test-requirements.txt
4561
./run_tests.sh
4662
```
4763

docker/Dockerfile

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,65 @@
1-
# GPU quote requires pynvml, which requires cuda, so use vllm image instead of python3
2-
FROM vllm/vllm-openai:v0.9.1
1+
# syntax=docker/dockerfile:1.7
32

4-
# Install dependencies
5-
WORKDIR /tmp
3+
# The proxy talks to a separate vLLM server; it doesn't need the multi-GB vLLM runtime image.
4+
# Keep the image small by using a slim Python base + venv, and rely on the NVIDIA runtime to
5+
# mount driver libraries (e.g., NVML) when GPU features are enabled.
6+
FROM python:3.12-slim-bookworm AS builder
7+
8+
ARG UV_VERSION=0.9.17
9+
10+
ENV DEBIAN_FRONTEND=noninteractive \
11+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
12+
PYTHONDONTWRITEBYTECODE=1 \
13+
UV_NO_MANAGED_PYTHON=1 \
14+
UV_PYTHON_DOWNLOADS=never \
15+
UV_LINK_MODE=copy
16+
17+
RUN apt-get update && apt-get install -y --no-install-recommends \
18+
build-essential \
19+
&& rm -rf /var/lib/apt/lists/*
20+
21+
RUN python -m pip install --no-cache-dir --upgrade pip \
22+
&& python -m pip install --no-cache-dir "uv==${UV_VERSION}"
623

7-
# Install packages via requirements.txt instead of poetry
8-
# because of nv-ppcie-verifier requires some old version packages,
9-
# which is not compatible with lots of current dependencies.
24+
ENV VIRTUAL_ENV=/opt/venv
25+
RUN python -m venv "$VIRTUAL_ENV"
26+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
27+
28+
WORKDIR /tmp
1029
COPY requirements.txt ./
11-
RUN pip install --no-cache-dir --upgrade -r requirements.txt \
12-
&& rm -rf requirements.txt
30+
RUN --mount=type=cache,target=/root/.cache/uv \
31+
uv pip install --strict -r requirements.txt
32+
33+
FROM builder AS gpu-builder
34+
35+
ENV VIRTUAL_ENV=/opt/ppcie-venv
36+
RUN python -m venv "$VIRTUAL_ENV"
37+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
38+
39+
WORKDIR /tmp
40+
COPY requirements-gpu.txt ./
41+
RUN --mount=type=cache,target=/root/.cache/uv \
42+
uv pip install --strict -r requirements-gpu.txt
43+
44+
FROM python:3.12-slim-bookworm AS runtime
45+
46+
ENV VIRTUAL_ENV=/opt/venv \
47+
PATH="/opt/venv/bin:$PATH" \
48+
PYTHONUNBUFFERED=1
49+
50+
RUN apt-get update && apt-get install -y --no-install-recommends \
51+
ca-certificates \
52+
&& rm -rf /var/lib/apt/lists/*
1353

14-
# Copy source code
1554
WORKDIR /app
55+
COPY --from=builder /opt/venv /opt/venv
1656
COPY src ./
17-
EXPOSE 8000
1857

58+
EXPOSE 8000
1959
ENTRYPOINT ["./entrypoint.sh"]
60+
61+
FROM runtime AS runtime-gpu
62+
COPY --from=gpu-builder /opt/ppcie-venv /opt/ppcie-venv
63+
ENV GPU_EVIDENCE_PYTHON=/opt/ppcie-venv/bin/python
64+
ENV NVIDIA_VISIBLE_DEVICES=all
65+
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility

docker/build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
35
# Default image name
46
IMAGE=${1:-vllm-proxy:latest}
7+
TARGET=${2:-runtime}
58

69
echo "Image: $IMAGE"
10+
echo "Target: $TARGET"
711

812
# Build the Docker image with the specified version
913
docker build \
1014
--no-cache \
1115
-f docker/Dockerfile \
12-
-t $IMAGE \
16+
--target "$TARGET" \
17+
-t "$IMAGE" \
1318
.

docs/TESTING.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
1. Create and activate a Python virtual environment:
66
```bash
7-
python3 -m venv .venv
8-
. .venv/bin/activate
7+
UV_NO_MANAGED_PYTHON=1 UV_PYTHON_DOWNLOADS=never uv venv -p python3
98
```
109

1110
2. Install dependencies:
1211
```bash
13-
pip install -r requirements.txt
14-
pip install -r test-requirements.txt
12+
uv pip install --python .venv/bin/python -r requirements.txt -r test-requirements.txt
1513
```
1614

1715
## Running Tests
@@ -25,8 +23,7 @@ Use the provided test runner script:
2523

2624
Or run manually:
2725
```bash
28-
. .venv/bin/activate
29-
PYTHONPATH=src python -m pytest tests/ -v
26+
PYTHONPATH=src .venv/bin/python -m pytest tests/ -v
3027
```
3128

3229
Environment variables are automatically set by `tests/conftest.py`.
@@ -37,7 +34,7 @@ Environment variables are automatically set by `tests/conftest.py`.
3734
**Run a specific test file:**
3835
```bash
3936
./run_tests.sh tests/app/test_openai.py
40-
# Expands to: PYTHONPATH=src python -m pytest tests/ -v tests/app/test_openai.py
37+
# Expands to: PYTHONPATH=src .venv/bin/python -m pytest tests/ -v tests/app/test_openai.py
4138
```
4239

4340
**Run a specific test function:**
@@ -108,9 +105,7 @@ The test suite is designed to run in CI environments without special hardware:
108105
# Example GitHub Actions workflow
109106
- name: Run tests
110107
run: |
111-
python3 -m venv .venv
112-
. .venv/bin/activate
113-
pip install -r requirements.txt
114-
pip install -r test-requirements.txt
108+
UV_NO_MANAGED_PYTHON=1 UV_PYTHON_DOWNLOADS=never uv venv -p python3
109+
uv pip install --python .venv/bin/python -r requirements.txt -r test-requirements.txt
115110
./run_tests.sh
116-
```
111+
```

0 commit comments

Comments
 (0)